comparison Gtk/gui.py @ 5:6502bfdaa84d

update import durus database
author Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
date Sat, 06 Nov 2010 21:30:33 +0100
parents 4e976a99efb9
children 2fc6b47dbe70
comparison
equal deleted inserted replaced
4:4e976a99efb9 5:6502bfdaa84d
68 else: 68 else:
69 print utils.mapping(_("The icon file does not exist. '$1'"), 69 print utils.mapping(_("The icon file does not exist. '$1'"),
70 (globals.getAppPath("ICON"),)) 70 (globals.getAppPath("ICON"),))
71 71
72 # Autodetect desktop 72 # Autodetect desktop
73 if globals.desktop["autodetect"] is True: 73 if globals.desktop["autodetect"]:
74 openwith.autodetect_desktop() 74 openwith.autodetect_desktop()
75 print utils.mapping(_("pyArq-Presupuestos running on $1"), 75 print utils.mapping(_("pyArq-Presupuestos running on $1"),
76 (globals.desktop["desktop"],)) 76 (globals.desktop["desktop"],))
77 77
78 class MainWindow(object): 78 class MainWindow(object):
203 203
204 budget: "base.Budget" object 204 budget: "base.Budget" object
205 205
206 Appends a budget in the "__budget_list" 206 Appends a budget in the "__budget_list"
207 """ 207 """
208 if budget != None: 208 if not budget is None:
209 _budget = budget 209 _budget = budget
210 if _budget in self.__budget_temp_list: 210 if _budget in self.__budget_temp_list:
211 self.__budget_temp_list.remove(_budget) 211 self.__budget_temp_list.remove(_budget)
212 self.__budget_list.append(_budget) 212 self.__budget_list.append(_budget)
213 213
227 def _menuitemImportFiebdc(self, widget): 227 def _menuitemImportFiebdc(self, widget):
228 """def _menuitemImportFiebdc(self, widget) 228 """def _menuitemImportFiebdc(self, widget)
229 229
230 widget: the widget where the event is emitted from 230 widget: the widget where the event is emitted from
231 Callback to open a budget file. 231 Callback to open a budget file.
232 Inits a timeout to test if a budgets is appended to "__budget_list"
233 calling _testBudgetList method if it is true.
234 232
235 Creates and shows a window to open a budget file. 233 Creates and shows a window to open a budget file.
236 """ 234 """
237 _budget = base.Budget() 235 _budget = base.Budget()
238 self.__budget_temp_list.append(_budget) 236 self.__budget_temp_list.append(_budget)
247 def _menuitemImportPriceDatabase(self, widget): 245 def _menuitemImportPriceDatabase(self, widget):
248 """def _menuitemImportPriceDatabase(self, widget) 246 """def _menuitemImportPriceDatabase(self, widget)
249 247
250 widget: the widget where the event is emitted from 248 widget: the widget where the event is emitted from
251 Callback to open a budget file. 249 Callback to open a budget file.
252 Inits a timeout to test if a budgets is appended to "__budget_list" 250
253 calling _testBudgetList method if it is true. 251 Creates and shows a window to open a price database file.
254
255 Creates and shows a window to open a budget file.
256 """ 252 """
257 _budget = base.Budget() 253 _budget = base.Budget()
258 self.__budget_temp_list.append(_budget) 254 self.__budget_temp_list.append(_budget)
259 _budget_file = fiebdc.Read() 255 _budget_file = fiebdc.Read()
260 _read_method = _budget_file.readFile 256 _read_method = _budget_file.readFile
261 _filename = "file" 257 _filename = "file"
262 _filetype = "basedate" 258 _filetype = "database"
263 _exit_method = _budget_file.cancel 259 _exit_method = _budget_file.cancel
264 _file_window = importFiebdc.FileSelectionWindow(self, 260 _file_window = importFiebdc.FileSelectionWindow(self,
265 _read_method, _budget, _filename, _exit_method, _filetype) 261 _read_method, _budget, _filename, _exit_method, _filetype)
266 262
267 def _menuitemOpenPriceDatabase(self, widget): 263 def _menuitemOpenPriceDatabase(self, widget):
268 """def _menuitemOpenPriceDatabase(self, widget) 264 """def _menuitemOpenPriceDatabase(self, widget)
269 265
270 widget: the widget where the event is emitted from 266 widget: the widget where the event is emitted from
271 Callback to open a budget file. 267 Callback to open a price database from a durus file.
272 268
273 Creates and shows a window to open a budget file. 269 Creates and shows a window to open a durus database
274 """ 270 """
275 _openDialog = OpenDurusDatabase(self._OpenDurusDatabase) 271 _budget = None
276 _openDialog.main() 272 self.__budget_temp_list.append(_budget)
277 273 _budget_file = durusdatabase.Read()
278 def _OpenDurusDatabase(self, file): 274 _read_method = _budget_file.readFile
279 """def _menuitemImportFiebdc(self, widget) 275 _filename = "file"
280 276 _filetype = "durus"
281 widget: the widget where the event is emitted from 277 _exit_method = _budget_file.cancel
282 278 _file_window = importFiebdc.FileSelectionWindow(self,
283 Callback to open a budget file from a durus file. 279 _read_method, _budget, _filename, _exit_method, _filetype)
284 """
285 _file = file
286 print utils.mapping(_("Loading file: $1:"), (_file,))
287 _time = time.time()
288 _durus_file = durusdatabase.DurusFile(_file,False)
289 _budget = _durus_file.getBudget()
290 _durus_file.close()
291 print utils.mapping(("Loadig time: $1 seconds"),
292 (("%.2f" %(time.time()-_time)),))
293 self.__budget_list.append(_budget)
294 _page = Page(_budget)
295 self.__notebook.append_page(_page.widget, _page.title)
296 self.__page_list.append(_page)
297 280
298 def _menuitemClose(self, widget): 281 def _menuitemClose(self, widget):
299 """def _menuitemClose(self, widget) 282 """def _menuitemClose(self, widget)
300 283
301 widget: the widget where the event is emitted from 284 widget: the widget where the event is emitted from
303 Callback to close a budget file. 286 Callback to close a budget file.
304 """ 287 """
305 _page_num = self.__notebook.get_current_page() 288 _page_num = self.__notebook.get_current_page()
306 if _page_num == -1: 289 if _page_num == -1:
307 return 290 return
308 _page = self.__page_list.pop(_page_num) 291 #_page = self.__page_list.pop(_page_num)
292 _page = self.__page_list[_page_num]
309 if isinstance(_page, Page): 293 if isinstance(_page, Page):
310 #not loading budget 294 #not loading budget
311 self.__budget_list.pop(_page_num) 295 self.__budget_list.pop(_page_num)
312 _page.clear() 296 if isinstance(_page, EmptyPage) and _page.filetype == "durus":
313 self.__notebook.remove_page(_page_num) 297 print _("Cancel reading Durus database has not been implemented.")
298 else:
299 self.__page_list.pop(_page_num)
300 _page.clear()
301 self.__notebook.remove_page(_page_num)
314 302
315 def _delete_event(self, widget, event): 303 def _delete_event(self, widget, event):
316 """_delete_event(self, widget, event) 304 """_delete_event(self, widget, event)
317 305
318 widget: the widget where the event is emitted from 306 widget: the widget where the event is emitted from
403 self.__widget.pack_start(_align, True, True, 0) 391 self.__widget.pack_start(_align, True, True, 0)
404 _progressframe = gtk.Frame() 392 _progressframe = gtk.Frame()
405 _progressframe.set_shadow_type(gtk.SHADOW_IN) 393 _progressframe.set_shadow_type(gtk.SHADOW_IN)
406 _progressframe.show() 394 _progressframe.show()
407 self.__progress_bar = gtk.ProgressBar() 395 self.__progress_bar = gtk.ProgressBar()
408 self.__progress_bar.show() 396 if self.__filetype != "durus":
397 self.__progress_bar.show()
409 _progressframe.add(self.__progress_bar) 398 _progressframe.add(self.__progress_bar)
410 self.__statusbar.pack_start(_progressframe, False, False, 0) 399 self.__statusbar.pack_start(_progressframe, False, False, 0)
411 self.__widget.pack_end(self.__statusbar, False, True, 0) 400 self.__widget.pack_end(self.__statusbar, False, True, 0)
412 self.__main_item = None 401 self.__main_item = None
413 402
443 Launch the timeouts: 432 Launch the timeouts:
444 1- update progress bar 433 1- update progress bar
445 2- update time label 434 2- update time label
446 3- If the other timetouts are stoped the window is closed 435 3- If the other timetouts are stoped the window is closed
447 """ 436 """
448 gobject.timeout_add(500, self._updateProgressBar)
449 gobject.timeout_add(1000, self._updateLabel, time.time()) 437 gobject.timeout_add(1000, self._updateLabel, time.time())
450 self.__cancel = [False, False] 438 if self.__filetype != "durus":
439 gobject.timeout_add(500, self._updateProgressBar)
440 self.__cancel = [False, False]
441 else:
442 self.__cancel = [True, False]
451 gobject.timeout_add(1000, self._autoClose) 443 gobject.timeout_add(1000, self._autoClose)
452 444
453 def _updateProgressBar(self): 445 def _updateProgressBar(self):
454 """def _updateProgressBar(self) 446 """def _updateProgressBar(self)
455 447
490 if self.__cancel == [ True, True ]: 482 if self.__cancel == [ True, True ]:
491 return False 483 return False
492 else: 484 else:
493 return True 485 return True
494 486
495 def closeWindow(self): 487 def threadFinishedSignal(self, budget):
496 """def closeWindow(self) 488 """def closeWindow(self)
497 489
498 Sets the __children atribute to None 490 Sets the __children atribute to None
499 This causes that the timeouts is ended. 491 This causes that the timeouts is ended.
500 This method is called from thread when it is finished 492 This method is called from thread when it is finished
501 TODO: it must called threadFinished or somethig 493 """
502 """ 494 self.__budget = budget
503 self.__children = None 495 self.__children = None
504 self.stopLoading() 496 self.stopLoading()
505 _page = Page(self.__budget) 497 _page = Page(self.__budget)
506 _children = self.__widget.get_children() 498 _children = self.__widget.get_children()
507 for _child in _children: 499 for _child in _children:
534 Return de main widget to show in the page 526 Return de main widget to show in the page
535 """ 527 """
536 return self.__widget 528 return self.__widget
537 529
538 def getTitle(self): 530 def getTitle(self):
539 """def getTtle(self) 531 """def getTitle(self)
540 532
541 Return the title of the page, a gtk.Label objetc 533 Return the title of the page, a gtk.Label objetc
542 """ 534 """
543 return self.__title 535 return self.__title
536 def getFiletype(self):
537 """def getFiletipe(self)
538
539 Return the title of the page, a gtk.Label objetc
540 """
541 return self.__filetype
544 542
545 widget = property(getWidget, None, None, 543 widget = property(getWidget, None, None,
546 "Main widget showed in the pane") 544 "Main widget showed in the pane")
547 title = property(getTitle, None, None, 545 title = property(getTitle, None, None,
548 "Page Title") 546 "Page Title")
547 filetype = property(getFiletype, None, None,
548 "Filetype: budget, basedata or durus")
549 549
550 class Page(object): 550 class Page(object):
551 """gui.Page: 551 """gui.Page:
552 552
553 Description: 553 Description:
4398 """def getWidget(self) 4398 """def getWidget(self)
4399 4399
4400 return the main widget (gtk.ScrolledWindow) 4400 return the main widget (gtk.ScrolledWindow)
4401 """ 4401 """
4402 return self.__widget 4402 return self.__widget
4403 widget = property(getWidget, None, None,
4404 "The main widget (gtk.ScrolledWindow)")
4405
4406
4407 class OpenDurusDatabase(object):
4408 """gui.OpenFiebdc
4409
4410 Description:
4411 Class to show a dialog to open a durus price database
4412 Constructor:
4413 OpenDurusDatabase()
4414 Ancestry:
4415 +-- object
4416 +-- OpenDurusDatabase
4417 Atributes:
4418 "_openMethod": The method to open the file
4419 "__file": the filename to open
4420 "__window": the File Selection window
4421 Methods:
4422 __init__(self)
4423 setActiveCode(self, code)
4424 """
4425 def __init__(self, openMethod):
4426 self.__openMethod = openMethod
4427 self.__file = None
4428 self.__window = gtk.FileSelection("Abrir Archivo")
4429 self.__window.connect("destroy", self.destroy)
4430 self.__window.ok_button.connect("clicked", self._openFile)
4431 self.__window.cancel_button.connect("clicked",
4432 lambda w: self.__window.destroy())
4433 self.__window.set_filename(globals.getHomePath("DURUS-DATABASE"))
4434 self.__window.show()
4435
4436 def destroy(self, widget):
4437 gtk.main_quit()
4438
4439 def main(self):
4440 gtk.main()
4441
4442 def _openFile(self, w):
4443 self.__file = self.__window.get_filename()
4444 _filename = os.path.basename(self.__file)
4445 _filename_list = _filename.split(".")
4446 _filename_ext = _filename_list[-1]
4447 if _filename == "":
4448 print _("No file selected")
4449 elif len(_filename_list) < 2 or _filename_ext != "durus":
4450 print _("The filename must have durus extension")
4451 else:
4452 try:
4453 self.__openMethod(self.__window.get_filename())
4454 self.__window.destroy()
4455 except IOError:
4456 print utils.mapping("IOError, $1", (self.__file,))