Mercurial > pyarq-presupuestos
changeset 4:4e976a99efb9
update ImportPriceDatabase
author | Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es> |
---|---|
date | Sun, 31 Oct 2010 23:12:06 +0100 |
parents | a221c14c3c31 |
children | 6502bfdaa84d |
files | Gtk/gui.py Gtk/importFiebdc.py |
diffstat | 2 files changed, 43 insertions(+), 48 deletions(-) [+] |
line wrap: on
line diff
--- a/Gtk/gui.py Sun Oct 31 21:01:48 2010 +0100 +++ b/Gtk/gui.py Sun Oct 31 23:12:06 2010 +0100 @@ -104,7 +104,6 @@ _menuitemOpenPriceDatabase(self, widget) _menuitemOpen _menuitemClose(self, widget) - _menuitemText(self, widget) _delete_event(self, widget, event) _destroy(self, widget) """ @@ -224,34 +223,6 @@ self.__notebook.append_page(_page.widget, _page.title) self.__page_list.append(_page) - def _testBudgetList2(self): - """def _testBudgetList2(self) - - Test if the number of budgets ("__budget_list") is greater - than the number of pages ("__page_list"), if it is greater - appendPage method is called to create a page to show the new budget - and save the budget in a durus file. - """ - if len(self.__budget_list) > len(self.__page_list): - self._appendPage() - #-# in test mode - # TODO: It must be in a thread - _last_budget = self.__budget_list[-1] - _path = globals.getHomePath("DURUS-DATABASE") - _file_whit_path_bc3 = _last_budget.filename - _filename_bc3 = _file_whit_path_bc3.split("/")[-1] - _filename = _filename_bc3.split(".")[-2] - _file = _path + _filename + ".durus" - print utils.mapping(_("Saving file: $1"), (_file,)) - _time = time.time() - _durus_file = durusdatabase.DurusFile(_file,True) - _durus_file.setBudget(_last_budget) - _durus_file.close() - print utils.mapping(_("Saving time: $1 seconds"), - (("%.2f" %(time.time()-_time) ),)) - #-# - return False - return True def _menuitemImportFiebdc(self, widget): """def _menuitemImportFiebdc(self, widget) @@ -268,9 +239,10 @@ _budget_file = fiebdc.Read() _read_method = _budget_file.readFile _filename = "file" + _filetype = "budget" _exit_method = _budget_file.cancel _file_window = importFiebdc.FileSelectionWindow(self, - _read_method, _budget, _filename, _exit_method) + _read_method, _budget, _filename, _exit_method, _filetype) def _menuitemImportPriceDatabase(self, widget): """def _menuitemImportPriceDatabase(self, widget) @@ -282,25 +254,21 @@ Creates and shows a window to open a budget file. """ - #TODO: change timeout, it is deprecated - #TODO: the .durus file must be direted saved - gobject.timeout_add(100, self._testBudgetList2) _budget = base.Budget() self.__budget_temp_list.append(_budget) _budget_file = fiebdc.Read() _read_method = _budget_file.readFile _filename = "file" + _filetype = "basedate" _exit_method = _budget_file.cancel _file_window = importFiebdc.FileSelectionWindow(self, - _read_method, _budget, _filename, _exit_method) + _read_method, _budget, _filename, _exit_method, _filetype) def _menuitemOpenPriceDatabase(self, widget): - """def _menuitemImportPriceDatabase(self, widget) + """def _menuitemOpenPriceDatabase(self, widget) widget: the widget where the event is emitted from Callback to open a budget file. - Inits a timeout to test if a budgets is appended to "__budget_list" - calling _testBudgetList method if it is true. Creates and shows a window to open a budget file. """ @@ -382,15 +350,16 @@ """ """ def __init__(self, mainWindow, readFileMethod, budget, filename, - cancelMethod): + cancelMethod, filetype): """def __init__(self, mainWindow, readFileMethod, budget, filename, - cancelMethod) + cancelMethod, filetype) """ self.__mainWindow = mainWindow self.__readFileMethod = readFileMethod self.__budget = budget self.__filename = filename + self.__filetype = filetype self.__cancelMethod = cancelMethod self.__children = None self.__cancel = [False, False] @@ -465,7 +434,7 @@ if self.__children is None: self.__children = importFiebdc.Thread(self, self.__mainWindow, self.__readFileMethod, self.__budget, self.__filename, - self.__cancelMethod) + self.__cancelMethod, self.__filetype) self.__children.start() def _launchTimeout(self):
--- a/Gtk/importFiebdc.py Sun Oct 31 21:01:48 2010 +0100 +++ b/Gtk/importFiebdc.py Sun Oct 31 23:12:06 2010 +0100 @@ -30,8 +30,10 @@ import threading gobject.threads_init() +# pyArq-Presupuestos Modules from Generic import utils from Generic import globals +from Generic import durusdatabase import gui class FileSelectionWindow(object): @@ -40,8 +42,8 @@ Description: Class to show the selection file window Constructor: - importFiebdc.FileSelectionWindow(mainWindow, readFileMethod, - budget, arg_List, cancelMethod) + importFiebdc.FileSelectionWindow(mainWindow, readFileMethod, budget, + filename, cancelMethod, filetype) Ancestry: +-- object +-- FileSelectionWindow @@ -50,6 +52,7 @@ "__readFileMethod": Method to read the selected file "__budget": Budget object "__filename": "file" + "__filetype": "budget" or "database" "__cancelMethod": Method to cancel the read method "__file": The selected file "__window": The selection file window @@ -64,15 +67,16 @@ """ def __init__(self, mainWindow, readFileMethod, budget, filename, - cancelMethod): + cancelMethod, filetype): """def __init__(self, mainWindow, readFileMethod, budget, - filename, cancelMethod) + filename, cancelMethod, filetype) mainWindow: gui.MainWindow object readFileMethod: Method to read the selected file budget: base.Budget object filename: "file" cancelMethod: Method to cancel the read method + fileytpe: "budget" or "database" Sets the init atributes, creates the file selection window Connects the events: * clicked ok button: _openFile @@ -84,6 +88,7 @@ self.__readFileMethod = readFileMethod self.__budget = budget self.__filename = filename + self.__filetype = filetype self.__cancelMethod = cancelMethod self.__file = None self.__window = gtk.FileChooserDialog(title=_("Open File"), @@ -105,7 +110,7 @@ _emptyPage = gui.EmptyPage(self.__mainWindow, self.__readFileMethod, self.__budget, self.__filename, - self.__cancelMethod) + self.__cancelMethod, self.__filetype) self.__mainWindow.getNotebook().append_page(_emptyPage.widget, _emptyPage.title) self.__mainWindow.getPageList().append(_emptyPage) @@ -370,7 +375,7 @@ Thread class to read a file without freeze the gui Constructor: importFiebdc.Thread(page, mainWindow, - readFileMethod, arg_tuple, cancelMethod) + readFileMethod, budget, filename, cancelMethod, filetype) Ancestry: +--threading.Thread +-- importFiebdc.Thread @@ -378,8 +383,10 @@ "__page": The page instanca that launch the thread "__mainWindow": gui.MainWindow instance "__readFileMethod": Method to read the selected file - "__arg_tuple": ("file", base.Budget()) + "__budget + "__filename": "file" "__cancelMethod": Method to cancel the read method + "__filetype": "budget" or "database" "__cancel": Boolean value, True: the thread is stoped Methods: __init__(self, page, mainWindow, @@ -390,7 +397,7 @@ """ def __init__(self, page, mainWindow, - readFileMethod, budget, filename, cancelMethod): + readFileMethod, budget, filename, cancelMethod, filetype): """def __init__(self, page, mainWindow, readFileMethod, budget, filename, cancelMethod) @@ -400,6 +407,7 @@ budget: base.Budget object filename: "file" cancelMethod: Method to cancel the read method + feletype: "budget" or "basedate" Sets the instance atributes. """ super(Thread, self).__init__() @@ -409,6 +417,7 @@ self.__budget = budget self.__filename = filename self.__cancelMethod = cancelMethod + self.__filetype = filetype self.__cancel = False def run(self): @@ -424,7 +433,24 @@ _mainWindow = self.__mainWindow _mainWindow._addBudget(_result) self.__page.closeWindow() + + if self.__filetype == "basedate": + self.saveDurusDatabase() self.clear() + + def saveDurusDatabase(self): + _path = globals.getHomePath("DURUS-DATABASE") + _file_whit_path_bc3 = self.__budget.filename + _filename_bc3 = _file_whit_path_bc3.split("/")[-1] + _filename = _filename_bc3.split(".")[-2] + _file = _path + _filename + ".durus" + print utils.mapping(_("Saving file: $1"), (_file,)) + _time = time.time() + _durus_file = durusdatabase.DurusFile(_file,True) + _durus_file.setBudget(self.__budget) + _durus_file.close() + print utils.mapping(_("Saving time: $1 seconds"), + (("%.2f" %(time.time()-_time) ),)) def cancel(self): """cancel(self)