comparison Gtk/importFiebdc.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
50 Atributes: 50 Atributes:
51 "__mainWindow": gui.MainWindow object 51 "__mainWindow": gui.MainWindow object
52 "__readFileMethod": Method to read the selected file 52 "__readFileMethod": Method to read the selected file
53 "__budget": Budget object 53 "__budget": Budget object
54 "__filename": "file" 54 "__filename": "file"
55 "__filetype": "budget" or "database" 55 "__filetype": "budget" ,"database" or "durus"
56 "__cancelMethod": Method to cancel the read method 56 "__cancelMethod": Method to cancel the read method
57 "__file": The selected file 57 "__file": The selected file
58 "__window": The selection file window 58 "__window": The selection file window
59 Methods: 59 Methods:
60 __init__(self, mainWindow, readFileMethod, budget 60 __init__(self, mainWindow, readFileMethod, budget
61 arg_List, cancelMethod) 61 arg_List, cancelMethod)
62 destroy(self, widget)
63 main(self)
64 _launchProgressWindow(self, _file) 62 _launchProgressWindow(self, _file)
65 _openFile(self, w) 63 _openFile(self, filename)
66 _openFile2(Self, filename)
67 """ 64 """
68 65
69 def __init__(self, mainWindow, readFileMethod, budget, filename, 66 def __init__(self, mainWindow, readFileMethod, budget, filename,
70 cancelMethod, filetype): 67 cancelMethod, filetype):
71 """def __init__(self, mainWindow, readFileMethod, budget, 68 """def __init__(self, mainWindow, readFileMethod, budget,
74 mainWindow: gui.MainWindow object 71 mainWindow: gui.MainWindow object
75 readFileMethod: Method to read the selected file 72 readFileMethod: Method to read the selected file
76 budget: base.Budget object 73 budget: base.Budget object
77 filename: "file" 74 filename: "file"
78 cancelMethod: Method to cancel the read method 75 cancelMethod: Method to cancel the read method
79 fileytpe: "budget" or "database" 76 fileytpe: "budget", "database" or "durus".
80 Sets the init atributes, creates the file selection window 77 Sets the init atributes, creates the file selection window
81 Connects the events: 78 Connects the events:
82 * clicked ok button: _openFile 79 * clicked ok button: _openFile
83 * clicked cancel button: destroy window 80 * clicked cancel button: destroy window
84 * destroy event: _destroy 81 * destroy event: _destroy
94 self.__window = gtk.FileChooserDialog(title=_("Open File"), 91 self.__window = gtk.FileChooserDialog(title=_("Open File"),
95 action=gtk.FILE_CHOOSER_ACTION_OPEN, 92 action=gtk.FILE_CHOOSER_ACTION_OPEN,
96 buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL, 93 buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,
97 gtk.STOCK_OPEN,gtk.RESPONSE_OK)) 94 gtk.STOCK_OPEN,gtk.RESPONSE_OK))
98 self.__window.set_default_response(gtk.RESPONSE_OK) 95 self.__window.set_default_response(gtk.RESPONSE_OK)
99 self.__window.set_filename(globals.getHomePath("BUDGET")) 96 if self.__filetype == "budget" or self.__filetype == "database":
97 self.__window.set_current_folder(globals.getHomePath("BUDGET"))
98 else: # "durus"
99 self.__window.set_current_folder(
100 globals.getHomePath("DURUS-DATABASE"))
100 if self.__window.run() == gtk.RESPONSE_OK: 101 if self.__window.run() == gtk.RESPONSE_OK:
101 self._openFile(self.__window.get_filename()) 102 self._openFile(self.__window.get_filename())
102 self.__window.destroy() 103 self.__window.destroy()
103 104
104 def _launchProgressWindow(self, file): 105 def _launchProgressWindow(self, file):
105 """def _launchProgressWindow(self, file) 106 """def _launchProgressWindow(self, file)
106 107
107 Launch the progress window 108 Launch the progress window
108 """ 109 """
109 self.__filename = file 110 self.__filename = file
110
111 _emptyPage = gui.EmptyPage(self.__mainWindow, self.__readFileMethod, 111 _emptyPage = gui.EmptyPage(self.__mainWindow, self.__readFileMethod,
112 self.__budget, self.__filename, 112 self.__budget, self.__filename,
113 self.__cancelMethod, self.__filetype) 113 self.__cancelMethod, self.__filetype)
114 self.__mainWindow.getNotebook().append_page(_emptyPage.widget, 114 self.__mainWindow.getNotebook().append_page(_emptyPage.widget,
115 _emptyPage.title) 115 _emptyPage.title)
116 self.__mainWindow.getPageList().append(_emptyPage) 116 self.__mainWindow.getPageList().append(_emptyPage)
117 _emptyPage.run() 117 _emptyPage.run()
118 118
119 def _launchProgressTab(self, file):
120 """def _launchProgressTab(self, file)
121
122 Launch the progress window
123 """
124 self.__filename = file
125 print "abriendo fichero", self.__filename
126
127 def _openFile(self, filename): 119 def _openFile(self, filename):
128 """def _openFile(self, filename) 120 """def _openFile(self, filename)
129 121
130 filename: the filename to open 122 filename: the filename to open
131 If the selected file has a bc3 extension 123 If the selected file has a bc3 extension
138 _file = _file.encode("utf-8") 130 _file = _file.encode("utf-8")
139 #-# 131 #-#
140 self.__file = _file 132 self.__file = _file
141 _filename = os.path.basename(self.__file) 133 _filename = os.path.basename(self.__file)
142 _filename_ext = _filename.split(".")[-1] 134 _filename_ext = _filename.split(".")[-1]
143 if _filename_ext != "bc3" and _filename_ext != "BC3": 135 if (self.__filetype == "budget" or self.__filetype == "database") and \
136 _filename_ext != "bc3" and _filename_ext != "BC3":
144 print _("The file must have 'bc3' extension") 137 print _("The file must have 'bc3' extension")
138 elif self.__filetype == "durus" and _filename_ext != "durus":
139 print _("The file must have 'durus' extension")
145 else: 140 else:
146 self.__window.destroy() 141 self.__window.destroy()
147 if self.__file: 142 # TODO: the file exits? is it not binary?, can it be readed?
148 # TODO: the file exits? is it not binary?, can it be readed? 143 self._launchProgressWindow(self.__file)
149 self._launchProgressWindow(self.__file)
150
151 144
152 145
153 class ProgressWindow(object): 146 class ProgressWindow(object):
154 """importFiebdc.ProgressWindow: 147 """importFiebdc.ProgressWindow:
155 148
378 readFileMethod, budget, filename, cancelMethod, filetype) 371 readFileMethod, budget, filename, cancelMethod, filetype)
379 Ancestry: 372 Ancestry:
380 +--threading.Thread 373 +--threading.Thread
381 +-- importFiebdc.Thread 374 +-- importFiebdc.Thread
382 Atributes: 375 Atributes:
383 "__page": The page instanca that launch the thread 376 "__page": The page instance that launch the thread
384 "__mainWindow": gui.MainWindow instance 377 "__mainWindow": gui.MainWindow instance
385 "__readFileMethod": Method to read the selected file 378 "__readFileMethod": Method to read the selected file
386 "__budget 379 "__budget
387 "__filename": "file" 380 "__filename": "file"
388 "__cancelMethod": Method to cancel the read method 381 "__cancelMethod": Method to cancel the read method
389 "__filetype": "budget" or "database" 382 "__filetype": "budget", "database" or "durus"
390 "__cancel": Boolean value, True: the thread is stoped 383 "__cancel": Boolean value, True: the thread is stoped
391 Methods: 384 Methods:
392 __init__(self, page, mainWindow, 385 __init__(self, page, mainWindow,
393 readFileMethod, arg_tuple, cancelMethod) 386 readFileMethod, arg_tuple, cancelMethod)
394 run(self) 387 run(self)
405 mainWindow: gui.Mainwindow object 398 mainWindow: gui.Mainwindow object
406 readFileMethod: Method to read the selected file 399 readFileMethod: Method to read the selected file
407 budget: base.Budget object 400 budget: base.Budget object
408 filename: "file" 401 filename: "file"
409 cancelMethod: Method to cancel the read method 402 cancelMethod: Method to cancel the read method
410 feletype: "budget" or "basedate" 403 feletype: "budget", "database" or "durus"
411 Sets the instance atributes. 404 Sets the instance atributes.
412 """ 405 """
413 super(Thread, self).__init__() 406 super(Thread, self).__init__()
414 self.__page = page 407 self.__page = page
415 self.__mainWindow = mainWindow 408 self.__mainWindow = mainWindow
423 def run(self): 416 def run(self):
424 """run(self) 417 """run(self)
425 418
426 419
427 """ 420 """
428 _result = self.__readFileMethod(self.__budget, self.__filename, 421 _budget = self.__readFileMethod(self.__budget, self.__filename,
429 self.__page) 422 self.__page)
430 if _result is None: 423 if _budget is None:
431 self.__page.threadCanceled() 424 self.__page.threadCanceled()
432 else: 425 else:
433 _mainWindow = self.__mainWindow 426 _mainWindow = self.__mainWindow
434 _mainWindow._addBudget(_result) 427 _mainWindow._addBudget(_budget)
435 self.__page.closeWindow() 428 self.__page.threadFinishedSignal(_budget)
436 429 if self.__filetype == "database":
437 if self.__filetype == "basedate":
438 self.saveDurusDatabase() 430 self.saveDurusDatabase()
439 self.clear() 431 self.clear()
440 432
441 def saveDurusDatabase(self): 433 def saveDurusDatabase(self):
442 _path = globals.getHomePath("DURUS-DATABASE") 434 _path = globals.getHomePath("DURUS-DATABASE")
474 del self.__readFileMethod 466 del self.__readFileMethod
475 del self.__budget 467 del self.__budget
476 del self.__filename 468 del self.__filename
477 del self.__cancelMethod 469 del self.__cancelMethod
478 del self.__cancel 470 del self.__cancel
479
480
481
482