Module pycalcar
[hide private]
[frames] | no frames]

Source Code for Module pycalcar

  1  #!/usr/bin/env python
 
  2  #-*- coding:utf-8 -*
 
  3  
 
  4  #       Pycalcar
 
  5  #       Copyright (C) 2013 GALODE A.
 
  6  #
 
  7  #       This file is part of Pycalcar.
 
  8  # 
 
  9  #       Pycalcar is free software: you can redistribute it and/or modify
 
 10  #       it under the terms of the GNU General Public License as published by
 
 11  #       the Free Software Foundation, either version 3 of the License, or
 
 12  #       (at your option) any later version.
 
 13  # 
 
 14  #       Pycalcar is distributed in the hope that it will be useful,
 
 15  #       but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 16  #       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 17  #       GNU General Public License for more details.
 
 18  #
 
 19  #       You should have received a copy of the GNU General Public License
 
 20  #       along with Pycalcar.  If not, see <http://www.gnu.org/licenses/>
 
 21  
 
 22  import ihm_pycalcar 
 23  import sqlite_pycalcar 
 24  import money_op_pycalcar 
 25  
 
 26  """
 
 27          :
 
 28          
 
 29          G{importgraph Demo}
 
 30  """ 
 31  
 
32 -class PycalcarSoftware:
33 """ 34 : 35 36 G{classtree} 37 38 DESCRIPTION 39 =========== 40 Main module of PYCALCAR Software 41 42 FUNCTIONS 43 ========= 44 p_init_operand 45 -------------- 46 Initialize the operand object 47 f_init_bdd 48 ---------- 49 Initialize the BDD object 50 f_init_ihm 51 ---------- 52 Create an interface object for the pycalcar software 53 p_start_software 54 ---------------- 55 Launch the pycalcar software 56 f_operation_add 57 --------------- 58 Allow to do add operation 59 f_operation_sub 60 --------------- 61 Allow to do sub operation 62 f_operation_mult 63 ---------------- 64 Allow to do multiplication operation 65 f_operation_div 66 --------------- 67 Allow to do division operation 68 f_money_read_rates 69 ------------------ 70 Allow to read the different internal rate for a money 71 f_money_read_rate 72 ----------------- 73 Allow to know the rate to convert the start to the aim money 74 p_money_create 75 -------------- 76 Allow to create a new money into database 77 p_money_update 78 -------------- 79 Allow to update money's data 80 p_money_delete 81 -------------- 82 Allow to delete a money 83 f_money_reloaded 84 ---------------- 85 Allow to reload money's DATA afetr update/delete/insert 86 f_rate_read 87 ----------- 88 Allow to read rate for conversion 89 p_rate_crupds 90 ------------- 91 Allow to make creation & update for a rate 92 p_rate_delete 93 ------------- 94 Allow to delete a rate 95 p_lang_change 96 ------------- 97 Allow to change the software language 98 f_cbox_conv 99 ----------- 100 Allow to read data to supply a combobox 101 f_conv_go 102 --------- 103 Make the conversion between two money 104 105 """ 106 107 #===================================================# 108 # Init # 109 #===================================================#
110 - def __init__(self) :
111 self.operand = self.p_init_operand() 112 self.bdd, list_toolbar, list_calc, list_conv, list_param, list_about, list_money, list_lang, list_rate, list_message = self.f_init_bdd() 113 114 interface = self.f_init_ihm(list_toolbar, list_calc, list_conv, list_param, list_money, list_lang, list_rate, list_about, list_message) 115 116 self.p_start_software(interface)
117 118 119 120 121 #===================================================# 122 # Init des calculs # 123 #===================================================#
124 - def p_init_operand(self):
125 """ 126 : 127 128 DESCRIPTION 129 =========== 130 Initialize the operand object 131 132 PARAMETERS 133 ========== 134 None 135 136 RETURNS 137 ======= 138 An operand object 139 """ 140 operand = money_op_pycalcar.MoneyOp() 141 142 return operand
143 144 145 146 147 #===================================================# 148 # Init de la BDD # 149 #===================================================#
150 - def f_init_bdd(self):
151 """ 152 : 153 154 DESCRIPTION 155 =========== 156 Initialize the BDD object 157 158 PARAMETERS 159 ========== 160 None 161 162 RETURNS 163 ======= 164 bdd 165 --- 166 A BDD object 167 168 list_toolbar 169 ------------ 170 A list that conatins the text for the tooltips of toolbar 171 172 list_calc 173 --------- 174 A list that contains the text for the calc screen interface 175 176 list_conv 177 --------- 178 A list that contains the text for the conv screen interface 179 180 list_param 181 ---------- 182 A list that contains the text for the param screen interface 183 184 list_about 185 ---------- 186 A list that contains the text for the about window 187 188 list_money 189 ---------- 190 A list that contains the different available money 191 192 list_lang 193 --------- 194 A list that contains the different available language 195 196 list_rate 197 --------- 198 A list that contains the different rate of a money 199 200 list_message 201 ------------ 202 A list that contains the different message for the information windows 203 """ 204 bdd = sqlite_pycalcar.SqlitePycalcar() 205 language = bdd.f_config_get_language() 206 list_toolbar, list_calc, list_conv, list_param, list_about = bdd.f_read_menu_text(language) 207 list_money = bdd.f_read_money_name() 208 list_lang = bdd.f_read_lang() 209 list_rate = bdd.f_read_money_rate(list_money[0][0],list_money[0][1],list_money[0][2]) 210 list_message = bdd.f_read_message(language) 211 212 return bdd, list_toolbar, list_calc, list_conv, list_param, list_about, list_money, list_lang, list_rate, list_message
213 214 215 216 217 #===================================================# 218 # Init de l'IHM # 219 #===================================================#
220 - def f_init_ihm(self, list_toolbar, list_calc, list_conv, list_param, list_money, list_lang, list_rate, list_about, list_message):
221 """ 222 : 223 224 DESCRIPTION 225 =========== 226 Create an interface object for the pycalcar software 227 228 PARAMETERS 229 ========== 230 list_toolbar 231 ------------ 232 A list that conatins the text for the tooltips of toolbar 233 234 list_calc 235 --------- 236 A list that contains the text for the calc screen interface 237 238 list_conv 239 --------- 240 A list that contains the text for the conv screen interface 241 242 list_param 243 ---------- 244 A list that contains the text for the param screen interface 245 246 list_money 247 ---------- 248 A list that contains the different available money 249 250 list_lang 251 --------- 252 A list that contains the different available language 253 254 list_rate 255 --------- 256 A list that contains the different rate between two money 257 list_about 258 ---------- 259 A list that contains the different information for about window 260 list_message 261 ------------ 262 A list that contains the different message for the information windows 263 264 RETURNS 265 ======= 266 An interface Object 267 """ 268 interface = ihm_pycalcar.IhmPycalcar(self.f_operation_add,self.f_operation_sub,self.f_operation_mult,self.f_operation_div,\ 269 list_toolbar, list_calc, list_conv, list_param, list_money,\ 270 list_lang,list_rate,self.f_money_read_rates, self.f_cbox_conv, list_about, self.p_money_create,\ 271 self.p_money_update, self.p_money_delete, self.p_rate_crupds, self.p_rate_delete, \ 272 self.p_lang_change, self.f_conv_go, self.f_moneys_read_rate, self.f_rate_read, self.f_money_reloaded, list_message) 273 274 return interface
275 276 277 278 279 #===================================================# 280 # Lancement de l'application # 281 #===================================================#
282 - def p_start_software(self, interface):
283 """ 284 : 285 286 DESCRIPTION 287 =========== 288 Launch the pycalcar software 289 290 PARAMETERS 291 ========== 292 interface 293 --------- 294 the interface object that allow to launch the software 295 296 RETURNS 297 ======= 298 None 299 """ 300 interface.p_gtk_win_main() 301 interface.p_start_ihm()
302 303 304 305 306 #===================================================# 307 # Permet d'effectuer une addition # 308 #===================================================#
309 - def f_operation_add(self,unit10,unit11,unit12,unit13,unit14,unit15,unit16,unit17,unit18,unit19,\ 310 unit20,unit21,unit22,unit23,unit24,unit25,unit26,unit27,unit28,unit29, 311 rate0,rate1,rate2,rate3,rate4,rate5,rate6,rate7,rate8):
312 """ 313 : 314 315 DESCRIPTION 316 =========== 317 Allow to do add operation 318 319 PARAMETERS 320 ========== 321 u10 => u19 322 ---------- 323 First line of operation, in the different units of the money 324 u20 => u29 325 ---------- 326 Second line of operation, in the different units of the money 327 rate0 => rate8 328 -------------- 329 Rate between the different units of the money 330 331 RETURNS 332 ======= 333 The result of add operation 334 """ 335 result = self.operand.f_money_add(unit10,unit11,unit12,unit13,unit14,unit15,unit16,unit17,unit18,unit19,\ 336 unit20,unit21,unit22,unit23,unit24,unit25,unit26,unit27,unit28,unit29, 337 rate0,rate1,rate2,rate3,rate4,rate5,rate6,rate7,rate8) 338 return result
339 340 341 342 343 #===================================================# 344 # Permet d'effectuer une soustraction # 345 #===================================================#
346 - def f_operation_sub(self,unit10,unit11,unit12,unit13,unit14,unit15,unit16,unit17,unit18,unit19,\ 347 unit20,unit21,unit22,unit23,unit24,unit25,unit26,unit27,unit28,unit29, 348 rate0,rate1,rate2,rate3,rate4,rate5,rate6,rate7,rate8):
349 """ 350 : 351 352 DESCRIPTION 353 =========== 354 Allow to do sub operation 355 356 PARAMETERS 357 ========== 358 u10 => u19 359 ---------- 360 First line of operation, in the different units of the money 361 u20 => u29 362 ---------- 363 Second line of operation, in the different units of the money 364 rate0 => rate8 365 -------------- 366 Rate between the different units of the money 367 368 RETURNS 369 ======= 370 The result of sub operation 371 """ 372 result = self.operand.f_money_sub(unit10,unit11,unit12,unit13,unit14,unit15,unit16,unit17,unit18,unit19,\ 373 unit20,unit21,unit22,unit23,unit24,unit25,unit26,unit27,unit28,unit29, 374 rate0,rate1,rate2,rate3,rate4,rate5,rate6,rate7,rate8) 375 return result
376 377 378 379 380 #===================================================# 381 # Permet d'effectuer une multiplication # 382 #===================================================#
383 - def f_operation_mult(self,unit20,unit10,unit11,unit12,unit13,unit14,unit15,unit16,unit17,unit18,unit19, 384 rate0,rate1,rate2,rate3,rate4,rate5,rate6,rate7,rate8):
385 """ 386 : 387 388 DESCRIPTION 389 =========== 390 Allow to do multiplication operation 391 392 PARAMETERS 393 ========== 394 u10 => u19 395 ---------- 396 First line of operation, in the different units of the money 397 u20 398 --- 399 The mult value 400 rate0 => rate8 401 -------------- 402 Rate between the different units of the money 403 404 RETURNS 405 ======= 406 The result of multiplication operation 407 """ 408 result = self.operand.f_money_mult(unit20,unit10,unit11,unit12,unit13,unit14,unit15,unit16,unit17,unit18,unit19, 409 rate0,rate1,rate2,rate3,rate4,rate5,rate6,rate7,rate8) 410 return result
411 412 413 414 415 #===================================================# 416 # Permet d'effectuer une division # 417 #===================================================#
418 - def f_operation_div(self,unit20,unit10,unit11,unit12,unit13,unit14,unit15,unit16,unit17,unit18,unit19, 419 rate0,rate1,rate2,rate3,rate4,rate5,rate6,rate7,rate8):
420 """ 421 : 422 423 DESCRIPTION 424 =========== 425 Allow to do division operation 426 427 PARAMETERS 428 ========== 429 u10 => u19 430 ---------- 431 First line of operation, in the different units of the money 432 u20 433 --- 434 The div value 435 rate0 => rate8 436 -------------- 437 Rate between the different units of the money 438 439 RETURNS 440 ======= 441 The result of division operation 442 """ 443 result, reste = self.operand.f_money_div(unit20,unit10,unit11,unit12,unit13,unit14,unit15,unit16,unit17,unit18,unit19, 444 rate0,rate1,rate2,rate3,rate4,rate5,rate6,rate7,rate8) 445 return result, reste
446 447 448 449 450 #===================================================# 451 # Lire les differents taux des unites de la devise # 452 #===================================================#
453 - def f_money_read_rates(self,name,year,nation):
454 """ 455 : 456 457 DESCRIPTION 458 =========== 459 Allow to read the different internal rate for a money 460 461 PARAMETERS 462 ========== 463 name 464 ---- 465 New name for the money 466 year 467 ---- 468 New year of creation for the money 469 nation 470 ------ 471 New nation for the money 472 473 RETURNS 474 ======= 475 A list that contains the different money and their informations 476 """ 477 result = self.bdd.f_read_money_rate(name,year,nation) 478 return result
479 480 481 482 483 #===================================================# 484 # Lire le taux de convertion entre 2 monnaies # 485 #===================================================#
486 - def f_moneys_read_rate(self,name1,year1,nation1,name2,year2,nation2):
487 """ 488 : 489 490 DESCRIPTION 491 =========== 492 Allow to know the rate to convert the start to the aim money 493 494 PARAMETERS 495 ========== 496 name1 497 ----- 498 The name of the start money 499 500 year1 501 ----- 502 The year of the start money 503 504 nation1 505 ------- 506 The nation of the start money 507 508 name2 509 ----- 510 The name of the end money 511 512 year2 513 ----- 514 The year of the end money 515 516 nation2 517 ------- 518 The nation of the end money 519 520 RETURNS 521 ======= 522 The rate to make the convertion 523 """ 524 value = self.bdd.f_read_rate(name1,year1,nation1,name2,year2,nation2) 525 return value
526 527 528 529 530 #===================================================# 531 # Creer une monnaie en BDD # 532 #===================================================#
533 - def p_money_create(self,name,year,nation,nb_unit,u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,\ 534 tx0,tx1,tx2,tx3,tx4,tx5,tx6,tx7,tx8):
535 """ 536 : 537 538 DESCRIPTION 539 =========== 540 Allow to create a new money into database 541 542 PARAMETERS 543 ========== 544 name 545 ---- 546 New name for the money 547 year 548 ---- 549 New year of creation for the money 550 nation 551 ------ 552 New nation for the money 553 nb_unit 554 ------- 555 Number of units in the money 556 u0 => u9 557 -------- 558 Name of the different units of the money 559 tx0 => tx8 560 ---------- 561 Rate between the different units of the money 562 563 RETURNS 564 ======= 565 none 566 """ 567 self.bdd.p_ins_money(name,year,nation,nb_unit,u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,\ 568 tx0,tx1,tx2,tx3,tx4,tx5,tx6,tx7,tx8)
569 570 571 572 573 #===================================================# 574 # Mettre a jour une monnaie # 575 #===================================================#
576 - def p_money_update(self,old_name,old_year,old_nation,name,year,nation, \ 577 nb_unit,u0,u1,u2,u3,u4,u5,u6,u7,u8,u9, \ 578 tx0,tx1,tx2,tx3,tx4,tx5,tx6,tx7,tx8):
579 """ 580 : 581 582 DESCRIPTION 583 =========== 584 Allow to update money's data 585 586 PARAMETERS 587 ========== 588 old_name 589 -------- 590 Old name of the money 591 old_year 592 -------- 593 Old year of creation of the money 594 old_nation 595 ---------- 596 Old nation of the money 597 name 598 ---- 599 New name for the money 600 year 601 ---- 602 New year of creation for the money 603 nation 604 ------ 605 New nation for the money 606 nb_unit 607 ------- 608 Number of units in the money 609 u0 => u9 610 -------- 611 Name of the different units of the money 612 tx0 => tx8 613 ---------- 614 Rate between the different units of the money 615 616 RETURNS 617 ======= 618 none 619 """ 620 self.bdd.p_upd_money(old_name,old_year,old_nation,name,year,nation, \ 621 nb_unit,u0,u1,u2,u3,u4,u5,u6,u7,u8,u9, \ 622 tx0,tx1,tx2,tx3,tx4,tx5,tx6,tx7,tx8)
623 624 625 626 627 #===================================================# 628 # Permet d'effacer une monnaie # 629 #===================================================#
630 - def p_money_delete(self,name,year,nation):
631 """ 632 : 633 634 DESCRIPTION 635 =========== 636 Allow to delete a money 637 638 PARAMETERS 639 ========== 640 name 641 ---- 642 New name for the money 643 year 644 ---- 645 New year of creation for the money 646 nation 647 ------ 648 New nation for the money 649 650 RETURNS 651 ======= 652 None 653 """ 654 self.bdd.p_del_money(name,year,nation)
655 656 657 658 659 #===================================================# 660 # Permet de regenerer les donnees d'une monnaie # 661 #===================================================#
662 - def f_money_reloaded(self):
663 """ 664 : 665 666 DESCRIPTION 667 =========== 668 Allow to reload money's DATA afetr update/delete/insert 669 670 PARAMETERS 671 ========== 672 None 673 674 RETURNS 675 ======= 676 Two list (money & rate) that contains updated data 677 """ 678 list_money = self.bdd.f_read_money_name() 679 list_rate = self.bdd.f_read_money_rate(list_money[0][0],list_money[0][1],list_money[0][2]) 680 681 return list_money, list_rate
682 683 684 685 686 #===================================================# 687 # Permet de lire un taux de conversion # 688 #===================================================#
689 - def f_rate_read(self,name1,year1,nation1,name2,year2,nation2):
690 """ 691 : 692 693 DESCRIPTION 694 =========== 695 Allow to read rate for conversion 696 697 PARAMETERS 698 ========== 699 name1 700 ----- 701 The name of the start money 702 703 year1 704 ----- 705 The year of the start money 706 707 nation1 708 ------- 709 The nation of the start money 710 711 name2 712 ----- 713 The name of the end money 714 715 year2 716 ----- 717 The year of the end money 718 719 nation2 720 ------- 721 The nation of the end money 722 723 RETURNS 724 ======= 725 A rate for conversion between 2 moneys 726 """ 727 rate = self.bdd.f_read_rate(name1,year1,nation1,name2,year2,nation2) 728 729 return rate
730 731 732 733 734 #===================================================# 735 # Permet de créer/MAJ un taux de convertion # 736 #===================================================#
737 - def p_rate_crupds(self,name1,year1,nation1,name2,year2,nation2,rate):
738 """ 739 : 740 741 DESCRIPTION 742 =========== 743 Allow to make creation & update for a rate 744 745 PARAMETERS 746 ========== 747 name1 748 ----- 749 The name of the start money 750 751 year1 752 ----- 753 The year of the start money 754 755 nation1 756 ------- 757 The nation of the start money 758 759 name2 760 ----- 761 The name of the end money 762 763 year2 764 ----- 765 The year of the end money 766 767 nation2 768 ------- 769 The nation of the end money 770 rate 771 ---- 772 The rate for conversion 773 774 RETURNS 775 ======= 776 None 777 """ 778 test = self.f_rate_read(name1,year1,nation1,name2,year2,nation2) 779 #Test d'existence dds le sens fourni 780 if (test == 0): 781 self.bdd.p_ins_rate(name1,year1,nation1,name2,year2,nation2,rate) 782 else: 783 self.bdd.p_upd_rate(name1,year1,nation1,name2,year2,nation2,rate) 784 785 786 test = self.f_rate_read(name2,year2,nation2,name1,year1,nation1) 787 #Test d'existence ds le sens inverse 788 if (test == 0): 789 self.bdd.p_ins_rate(name2,year2,nation2,name1,year1,nation1,1/rate) 790 else: 791 self.bdd.p_upd_rate(name2,year2,nation2,name1,year1,nation1,1/rate)
792 793 794 795 796 #===================================================# 797 # Permet d'effacer un taux de conversion # 798 #===================================================#
799 - def p_rate_delete(self,name1,year1,nation1,name2,year2,nation2):
800 """ 801 : 802 803 DESCRIPTION 804 =========== 805 Allow to delete a rate 806 807 PARAMETERS 808 ========== 809 name1 810 ----- 811 The name of the start money 812 813 year1 814 ----- 815 The year of the start money 816 817 nation1 818 ------- 819 The nation of the start money 820 821 name2 822 ----- 823 The name of the end money 824 825 year2 826 ----- 827 The year of the end money 828 829 nation2 830 ------- 831 The nation of the end money 832 rate 833 ---- 834 The rate for conversion 835 836 RETURNS 837 ======= 838 None 839 """ 840 841 self.bdd.p_del_rate(name1,year1,nation1,name2,year2,nation2)
842 843 844 845 846 #===================================================# 847 # Permet de changer la langue du logiciel # 848 #===================================================#
849 - def p_lang_change(self,language):
850 """ 851 : 852 853 DESCRIPTION 854 =========== 855 Allow to change the software language 856 857 PARAMETERS 858 ========== 859 language 860 -------- 861 The selected language 862 863 RETURNS 864 ======= 865 none 866 """ 867 self.bdd.p_config_set_language(language)
868 869 870 871 872 #===================================================# 873 # Permet de recuperer des donnes # 874 #===================================================#
875 - def f_cbox_conv(self,name,year,nation):
876 """ 877 : 878 879 DESCRIPTION 880 =========== 881 Allow to read data to supply a combobox 882 883 PARAMETERS 884 ========== 885 name 886 ---- 887 New name for the money 888 year 889 ---- 890 New year of creation for the money 891 nation 892 ------ 893 New nation for the money 894 895 RETURNS 896 ======= 897 A list that contains data to supply combobox 898 """ 899 result = self.bdd.f_read_conv_combox(name,year,nation) 900 return result
901 902 903 904 905 #===================================================# 906 # Permet d'effectuer une convertion entre monnaies# 907 #===================================================#
908 - def f_conv_go(self,unit10,unit11,unit12,unit13,unit14,unit15,unit16,unit17,unit18,unit19,\ 909 rate10,rate11,rate12,rate13,rate14,rate15,rate16,rate17,rate18, \ 910 rate20,rate21,rate22,rate23,rate24,rate25,rate26,rate27,rate28, \ 911 rate_conv):
912 """ 913 : 914 915 DESCRIPTION 916 =========== 917 Make the conversion between two money 918 919 PARAMETERS 920 ========== 921 unit10 => unit19 922 ---------------- 923 The values of the first money 924 rate0 => rate8 925 -------------- 926 The rate betwwen different units of the start money 927 rate_conv 928 --------- 929 The rate of conversion between money 930 931 RETURNS 932 ======= 933 the different values of the converted money 934 935 """ 936 base1 = self.operand.f_convert_base(unit10,unit11,unit12,unit13,unit14,unit15,unit16,unit17,unit18,unit19,\ 937 rate10,rate11,rate12,rate13,rate14,rate15,rate16,rate17,rate18) 938 base2 = base1 * rate_conv 939 base2 = int(base2 + 0.5) 940 941 return self.operand.f_convert_total(base2,rate20,rate21,rate22,rate23,rate24,rate25,rate26,rate27,rate28)
942 943 944 945 946 #===================================================# 947 # Main de la classe # 948 #===================================================# 949 if __name__ == '__main__': 950 software = PycalcarSoftware() 951