diff 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
line wrap: on
line diff
--- a/Gtk/gui.py	Sun Oct 31 23:12:06 2010 +0100
+++ b/Gtk/gui.py	Sat Nov 06 21:30:33 2010 +0100
@@ -70,7 +70,7 @@
           (globals.getAppPath("ICON"),))
 
 # Autodetect desktop
-if globals.desktop["autodetect"] is True:
+if globals.desktop["autodetect"]:
     openwith.autodetect_desktop()
     print utils.mapping(_("pyArq-Presupuestos running on $1"),
                         (globals.desktop["desktop"],))
@@ -205,7 +205,7 @@
         
         Appends a budget in the "__budget_list"
         """
-        if budget != None:
+        if not budget is None:
             _budget = budget
             if _budget in self.__budget_temp_list:
                 self.__budget_temp_list.remove(_budget)
@@ -229,8 +229,6 @@
         
         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.
         """
@@ -249,17 +247,15 @@
         
         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.
+        
+        Creates and shows a window to open a price database file.
         """
         _budget = base.Budget()
         self.__budget_temp_list.append(_budget)
         _budget_file = fiebdc.Read()
         _read_method = _budget_file.readFile
         _filename = "file"
-        _filetype = "basedate"
+        _filetype = "database"
         _exit_method = _budget_file.cancel
         _file_window = importFiebdc.FileSelectionWindow(self,
             _read_method, _budget, _filename, _exit_method, _filetype)
@@ -268,32 +264,19 @@
         """def _menuitemOpenPriceDatabase(self, widget)
         
         widget: the widget where the event is emitted from
-        Callback to open a budget file.
-        
-        Creates and shows a window to open a budget file.
+        Callback to open a price database from a durus file.
+        
+        Creates and shows a window to open a durus database
         """
-        _openDialog = OpenDurusDatabase(self._OpenDurusDatabase)
-        _openDialog.main()
-
-    def _OpenDurusDatabase(self, file):
-        """def _menuitemImportFiebdc(self, widget)
-        
-        widget: the widget where the event is emitted from
-        
-        Callback to open a budget file from a durus file.
-        """
-        _file = file
-        print utils.mapping(_("Loading file: $1:"), (_file,))
-        _time = time.time()
-        _durus_file = durusdatabase.DurusFile(_file,False)
-        _budget = _durus_file.getBudget()
-        _durus_file.close()
-        print utils.mapping(("Loadig time: $1 seconds"),
-             (("%.2f" %(time.time()-_time)),))
-        self.__budget_list.append(_budget)
-        _page = Page(_budget)
-        self.__notebook.append_page(_page.widget, _page.title)
-        self.__page_list.append(_page)
+        _budget = None
+        self.__budget_temp_list.append(_budget)
+        _budget_file = durusdatabase.Read()
+        _read_method = _budget_file.readFile
+        _filename = "file"
+        _filetype = "durus"
+        _exit_method = _budget_file.cancel
+        _file_window = importFiebdc.FileSelectionWindow(self,
+            _read_method, _budget, _filename, _exit_method, _filetype)
 
     def _menuitemClose(self, widget):
         """def _menuitemClose(self, widget)
@@ -305,12 +288,17 @@
         _page_num = self.__notebook.get_current_page()
         if _page_num == -1:
             return
-        _page = self.__page_list.pop(_page_num)
+        #_page = self.__page_list.pop(_page_num)
+        _page = self.__page_list[_page_num]
         if isinstance(_page, Page):
             #not loading budget
             self.__budget_list.pop(_page_num)
-        _page.clear()
-        self.__notebook.remove_page(_page_num)
+        if isinstance(_page, EmptyPage) and _page.filetype == "durus":
+            print _("Cancel reading Durus database has not been implemented.")
+        else:
+            self.__page_list.pop(_page_num)
+            _page.clear()
+            self.__notebook.remove_page(_page_num)
 
     def _delete_event(self, widget, event):
         """_delete_event(self, widget, event)
@@ -405,7 +393,8 @@
         _progressframe.set_shadow_type(gtk.SHADOW_IN)
         _progressframe.show()
         self.__progress_bar = gtk.ProgressBar()
-        self.__progress_bar.show()
+        if self.__filetype != "durus":
+            self.__progress_bar.show()
         _progressframe.add(self.__progress_bar)
         self.__statusbar.pack_start(_progressframe, False, False, 0)
         self.__widget.pack_end(self.__statusbar, False, True, 0)
@@ -445,9 +434,12 @@
             2- update time label
             3- If the other timetouts are stoped the window is closed
         """
-        gobject.timeout_add(500, self._updateProgressBar)
         gobject.timeout_add(1000, self._updateLabel, time.time())
-        self.__cancel = [False, False]
+        if self.__filetype != "durus":
+            gobject.timeout_add(500, self._updateProgressBar)
+            self.__cancel = [False, False]
+        else:
+            self.__cancel = [True, False]
         gobject.timeout_add(1000, self._autoClose)
 
     def _updateProgressBar(self):
@@ -492,14 +484,14 @@
         else:
             return True
 
-    def closeWindow(self):
+    def threadFinishedSignal(self, budget):
         """def closeWindow(self)
         
         Sets the __children atribute to None
         This causes that the timeouts is ended.
         This method is called from thread when it is finished
-        TODO: it must called threadFinished or somethig
         """
+        self.__budget = budget
         self.__children = None
         self.stopLoading()
         _page = Page(self.__budget)
@@ -536,16 +528,24 @@
         return self.__widget
 
     def getTitle(self):
-        """def getTtle(self)
+        """def getTitle(self)
         
         Return the title of the page, a gtk.Label objetc
         """
         return self.__title
+    def getFiletype(self):
+        """def getFiletipe(self)
+        
+        Return the title of the page, a gtk.Label objetc
+        """
+        return self.__filetype
 
     widget = property(getWidget, None, None,
                       "Main widget showed in the pane")
     title = property(getTitle, None, None,
                       "Page Title")
+    filetype = property(getFiletype, None, None,
+                      "Filetype: budget, basedata or durus")
 
 class Page(object):
     """gui.Page:
@@ -4399,58 +4399,4 @@
         
         return the main widget (gtk.ScrolledWindow)
         """
-        return self.__widget
-    widget = property(getWidget, None, None,
-        "The main widget (gtk.ScrolledWindow)")
-
-
-class OpenDurusDatabase(object):
-    """gui.OpenFiebdc
-    
-    Description:
-        Class to show a dialog to open a durus price database
-    Constructor:
-       OpenDurusDatabase()
-    Ancestry:
-    +-- object
-      +-- OpenDurusDatabase
-    Atributes:
-        "_openMethod": The method to open the file
-        "__file": the filename to open
-        "__window": the File Selection window
-    Methods:
-        __init__(self)
-        setActiveCode(self, code)
-    """
-    def __init__(self, openMethod):
-        self.__openMethod = openMethod
-        self.__file = None
-        self.__window = gtk.FileSelection("Abrir Archivo")
-        self.__window.connect("destroy", self.destroy)
-        self.__window.ok_button.connect("clicked", self._openFile)
-        self.__window.cancel_button.connect("clicked", 
-            lambda w: self.__window.destroy())
-        self.__window.set_filename(globals.getHomePath("DURUS-DATABASE"))
-        self.__window.show()
-
-    def destroy(self, widget):
-        gtk.main_quit()
-
-    def main(self):
-        gtk.main()
-
-    def _openFile(self, w):
-        self.__file = self.__window.get_filename()
-        _filename = os.path.basename(self.__file)
-        _filename_list = _filename.split(".")
-        _filename_ext = _filename_list[-1]
-        if _filename == "":
-            print _("No file selected")
-        elif len(_filename_list) < 2 or _filename_ext != "durus":
-            print _("The filename must have durus extension")
-        else:
-            try:
-                self.__openMethod(self.__window.get_filename())
-                self.__window.destroy()
-            except IOError:
-                print utils.mapping("IOError, $1", (self.__file,))
+        return self.__widget
\ No newline at end of file