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

Source Code for Module pycalcar

  1  #!/usr/bin/env python 
  2  #-*- coding:utf-8 -* 
  3   
  4  """ 
  5          Manage all the Pycalcar Software 
  6           
  7          G{importgraph} 
  8  """ 
  9   
 10  #       Pycalcar 
 11  #       Copyright (C) 2013 GALODE A. 
 12  # 
 13  #       This file is part of Pycalcar. 
 14  #  
 15  #       Pycalcar is free software: you can redistribute it and/or modify 
 16  #       it under the terms of the GNU General Public License as published by 
 17  #       the Free Software Foundation, either version 3 of the License, or 
 18  #       (at your option) any later version. 
 19  #  
 20  #       Pycalcar is distributed in the hope that it will be useful, 
 21  #       but WITHOUT ANY WARRANTY; without even the implied warranty of 
 22  #       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 23  #       GNU General Public License for more details. 
 24  # 
 25  #       You should have received a copy of the GNU General Public License 
 26  #       along with Pycalcar.  If not, see <http://www.gnu.org/licenses/> 
 27   
 28  import sys 
 29   
 30  import ihm_pycalcar 
 31  import sqlite_pycalcar 
 32  import money_op_pycalcar 
 33  import path_mkr 
 34   
 35   
36 -class PycalcarSoftware:
37 """ 38 Class which manage the entire Pycalcar software 39 40 G{classtree} 41 """ 42 43 #===================================================# 44 # Init # 45 #===================================================#
46 - def __init__(self) :
47 self.path_base = path_mkr.cxf_get_path() 48 self.operand = self.p_init_operand() 49 self.bdd, list_toolbar, list_calc, list_conv, list_param, list_about, list_money, list_lang, list_rate, list_message, language = self.f_init_bdd() 50 51 interface = self.f_init_ihm(list_toolbar, list_calc, list_conv, list_param, list_money, list_lang, list_rate, list_about, list_message, language) 52 53 self.p_start_software(interface)
54 55 56 57 58 #===================================================# 59 # Init des calculs # 60 #===================================================#
61 - def p_init_operand(self):
62 63 operand = money_op_pycalcar.MoneyOp() 64 65 return operand
66 67 68 69 70 #===================================================# 71 # Init de la BDD # 72 #===================================================#
73 - def f_init_bdd(self):
74 75 bdd = sqlite_pycalcar.SqlitePycalcar(self.path_base) 76 language = bdd.f_config_get_language() 77 list_toolbar, list_calc, list_conv, list_param, list_about = bdd.f_read_menu_text(language) 78 list_money = bdd.f_read_money_name() 79 list_lang = bdd.f_read_lang() 80 list_rate = bdd.f_read_money_rate(list_money[0][0],list_money[0][1],list_money[0][2]) 81 list_message = bdd.f_read_message(language) 82 83 84 return bdd, list_toolbar, list_calc, list_conv, list_param, list_about, list_money, list_lang, list_rate, list_message, language
85 86 87 88 89 #===================================================# 90 # Init de l'IHM # 91 #===================================================#
92 - def f_init_ihm(self, list_toolbar, list_calc, list_conv, list_param, list_money, list_lang, list_rate, list_about, list_message, language):
93 94 interface = ihm_pycalcar.IhmPycalcar(self.f_operation_add,self.f_operation_sub,self.f_operation_mult,self.f_operation_div,\ 95 list_toolbar, list_calc, list_conv, list_param, list_money,\ 96 list_lang,list_rate,self.f_money_read_rates, self.f_cbox_conv, list_about, self.p_money_create,\ 97 self.p_money_update, self.p_money_delete, self.p_rate_crupds, self.p_rate_delete, \ 98 self.p_lang_change, self.f_conv_go, self.f_moneys_read_rate, self.f_rate_read, \ 99 self.f_money_reloaded, list_message, self.path_base, language) 100 101 return interface
102 103 104 105 106 #===================================================# 107 # Lancement de l'application # 108 #===================================================#
109 - def p_start_software(self, interface):
110 111 interface.p_gtk_win_main() 112 interface.p_start_ihm()
113 114 115 116 117 #===================================================# 118 # Permet d'effectuer une addition # 119 #===================================================#
120 - def f_operation_add(self,unit10,unit11,unit12,unit13,unit14,unit15,unit16,unit17,unit18,unit19,\ 121 unit20,unit21,unit22,unit23,unit24,unit25,unit26,unit27,unit28,unit29, 122 rate0,rate1,rate2,rate3,rate4,rate5,rate6,rate7,rate8):
123 124 result = self.operand.f_money_add(unit10,unit11,unit12,unit13,unit14,unit15,unit16,unit17,unit18,unit19,\ 125 unit20,unit21,unit22,unit23,unit24,unit25,unit26,unit27,unit28,unit29, 126 rate0,rate1,rate2,rate3,rate4,rate5,rate6,rate7,rate8) 127 return result
128 129 130 131 132 #===================================================# 133 # Permet d'effectuer une soustraction # 134 #===================================================#
135 - def f_operation_sub(self,unit10,unit11,unit12,unit13,unit14,unit15,unit16,unit17,unit18,unit19,\ 136 unit20,unit21,unit22,unit23,unit24,unit25,unit26,unit27,unit28,unit29, 137 rate0,rate1,rate2,rate3,rate4,rate5,rate6,rate7,rate8):
138 139 result = self.operand.f_money_sub(unit10,unit11,unit12,unit13,unit14,unit15,unit16,unit17,unit18,unit19,\ 140 unit20,unit21,unit22,unit23,unit24,unit25,unit26,unit27,unit28,unit29, 141 rate0,rate1,rate2,rate3,rate4,rate5,rate6,rate7,rate8) 142 return result
143 144 145 146 147 #===================================================# 148 # Permet d'effectuer une multiplication # 149 #===================================================#
150 - def f_operation_mult(self,unit20,unit10,unit11,unit12,unit13,unit14,unit15,unit16,unit17,unit18,unit19, 151 rate0,rate1,rate2,rate3,rate4,rate5,rate6,rate7,rate8):
152 153 result = self.operand.f_money_mult(unit20,unit10,unit11,unit12,unit13,unit14,unit15,unit16,unit17,unit18,unit19, 154 rate0,rate1,rate2,rate3,rate4,rate5,rate6,rate7,rate8) 155 return result
156 157 158 159 160 #===================================================# 161 # Permet d'effectuer une division # 162 #===================================================#
163 - def f_operation_div(self,unit20,unit10,unit11,unit12,unit13,unit14,unit15,unit16,unit17,unit18,unit19, 164 rate0,rate1,rate2,rate3,rate4,rate5,rate6,rate7,rate8):
165 166 result, reste = self.operand.f_money_div(unit20,unit10,unit11,unit12,unit13,unit14,unit15,unit16,unit17,unit18,unit19, 167 rate0,rate1,rate2,rate3,rate4,rate5,rate6,rate7,rate8) 168 return result, reste
169 170 171 172 173 #===================================================# 174 # Lire les differents taux des unites de la devise # 175 #===================================================#
176 - def f_money_read_rates(self,name,year,nation):
177 178 result = self.bdd.f_read_money_rate(name,year,nation) 179 return result
180 181 182 183 184 #===================================================# 185 # Lire le taux de convertion entre 2 monnaies # 186 #===================================================#
187 - def f_moneys_read_rate(self,name1,year1,nation1,name2,year2,nation2):
188 189 value = self.bdd.f_read_rate(name1,year1,nation1,name2,year2,nation2) 190 return value
191 192 193 194 195 #===================================================# 196 # Creer une monnaie en BDD # 197 #===================================================#
198 - def p_money_create(self,name,year,nation,nb_unit,u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,\ 199 tx0,tx1,tx2,tx3,tx4,tx5,tx6,tx7,tx8):
200 201 self.bdd.p_ins_money(name,year,nation,nb_unit,u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,\ 202 tx0,tx1,tx2,tx3,tx4,tx5,tx6,tx7,tx8)
203 204 205 206 207 #===================================================# 208 # Mettre a jour une monnaie # 209 #===================================================#
210 - def p_money_update(self,old_name,old_year,old_nation,name,year,nation, \ 211 nb_unit,u0,u1,u2,u3,u4,u5,u6,u7,u8,u9, \ 212 tx0,tx1,tx2,tx3,tx4,tx5,tx6,tx7,tx8):
213 214 self.bdd.p_upd_money(old_name,old_year,old_nation,name,year,nation, \ 215 nb_unit,u0,u1,u2,u3,u4,u5,u6,u7,u8,u9, \ 216 tx0,tx1,tx2,tx3,tx4,tx5,tx6,tx7,tx8)
217 218 219 220 221 #===================================================# 222 # Permet d'effacer une monnaie # 223 #===================================================#
224 - def p_money_delete(self,name,year,nation):
225 226 self.bdd.p_del_money(name,year,nation)
227 228 229 230 231 #===================================================# 232 # Permet de regenerer les donnees d'une monnaie # 233 #===================================================#
234 - def f_money_reloaded(self):
235 236 list_money = self.bdd.f_read_money_name() 237 list_rate = self.bdd.f_read_money_rate(list_money[0][0],list_money[0][1],list_money[0][2]) 238 239 return list_money, list_rate
240 241 242 243 244 #===================================================# 245 # Permet de lire un taux de conversion # 246 #===================================================#
247 - def f_rate_read(self,name1,year1,nation1,name2,year2,nation2):
248 249 rate = self.bdd.f_read_rate(name1,year1,nation1,name2,year2,nation2) 250 251 return rate
252 253 254 255 256 #===================================================# 257 # Permet de créer/MAJ un taux de convertion # 258 #===================================================#
259 - def p_rate_crupds(self,name1,year1,nation1,name2,year2,nation2,rate):
260 261 test = self.f_rate_read(name1,year1,nation1,name2,year2,nation2) 262 #Test d'existence dds le sens fourni 263 if (test == 0): 264 self.bdd.p_ins_rate(name1,year1,nation1,name2,year2,nation2,rate) 265 else: 266 self.bdd.p_upd_rate(name1,year1,nation1,name2,year2,nation2,rate) 267 268 269 test = self.f_rate_read(name2,year2,nation2,name1,year1,nation1) 270 #Test d'existence ds le sens inverse 271 if (test == 0): 272 self.bdd.p_ins_rate(name2,year2,nation2,name1,year1,nation1,1/rate) 273 else: 274 self.bdd.p_upd_rate(name2,year2,nation2,name1,year1,nation1,1/rate)
275 276 277 278 279 #===================================================# 280 # Permet d'effacer un taux de conversion # 281 #===================================================#
282 - def p_rate_delete(self,name1,year1,nation1,name2,year2,nation2):
283 284 285 self.bdd.p_del_rate(name1,year1,nation1,name2,year2,nation2)
286 287 288 289 290 #===================================================# 291 # Permet de changer la langue du logiciel # 292 #===================================================#
293 - def p_lang_change(self,language):
294 295 self.bdd.p_config_set_language(language)
296 297 298 299 300 #===================================================# 301 # Permet de recuperer des donnes # 302 #===================================================#
303 - def f_cbox_conv(self,name,year,nation):
304 305 result = self.bdd.f_read_conv_combox(name,year,nation) 306 return result
307 308 309 310 311 #===================================================# 312 # Permet d'effectuer une convertion entre monnaies# 313 #===================================================#
314 - def f_conv_go(self,unit10,unit11,unit12,unit13,unit14,unit15,unit16,unit17,unit18,unit19,\ 315 rate10,rate11,rate12,rate13,rate14,rate15,rate16,rate17,rate18, \ 316 rate20,rate21,rate22,rate23,rate24,rate25,rate26,rate27,rate28, \ 317 rate_conv):
318 319 base1 = self.operand.f_convert_base(unit10,unit11,unit12,unit13,unit14,unit15,unit16,unit17,unit18,unit19,\ 320 rate10,rate11,rate12,rate13,rate14,rate15,rate16,rate17,rate18) 321 base2 = base1 * rate_conv 322 base2 = int(base2 + 0.5) 323 324 return self.operand.f_convert_total(base2,rate20,rate21,rate22,rate23,rate24,rate25,rate26,rate27,rate28)
325 326 327 328 329 #===================================================# 330 # Main de la classe # 331 #===================================================# 332 if __name__ == '__main__': 333 try: 334 software = PycalcarSoftware() 335 except: 336 print "error: ", sys.exc_info() 337 a = raw_input("Error") 338