Commits

Anonymous committed f2d6afa

Changes to persisting windows sizes

Comments (0)

Files changed (2)

 
 [wxID_WXBOAFILEDIALOG, wxID_WXBOAFILEDIALOGBTCANCEL, wxID_WXBOAFILEDIALOGBTOK, wxID_WXBOAFILEDIALOGCHTYPES, wxID_WXBOAFILEDIALOGHTMLWINDOW1, wxID_WXBOAFILEDIALOGSTATICTEXT1, wxID_WXBOAFILEDIALOGSTATICTEXT2, wxID_WXBOAFILEDIALOGTCFILENAME] = map(lambda _init_ctrls: wxNewId(), range(8))
 
-class wxBoaFileDialog(wxDialog):
+class wxBoaFileDialog(wxDialog, Utils.FrameRestorerMixin):
     currentDir = '.'
     _lastSize = None
+    _fileListCtrlSize = (384, 152)
+    _dialogClientSize = (400, 256)
     _custom_classes = {'wxHtmlWindow': ['wxUrlClickHtmlWindow']}
     def _init_utils(self):
         pass
         EVT_HTML_URL_CLICK(self.htmlWindow1, self.OnHtmlPathClick)
 
         self.lcFiles = createFileDlgFolderListClass()(self, self,
-              defaultDir, pos = wxPoint(8, 21), size = wxSize(384, 152))
+              defaultDir, pos = wxPoint(8, 21), size = self._fileListCtrlSize)
         self.lcFiles.SetConstraints(LayoutAnchors(self.lcFiles, true, true, true, true))
 
-        if self._lastSize:
-            self.SetClientSize(self._lastSize)
+        self.winConfOption = 'filedialog'
+        self.loadDims()
 
         EVT_LEFT_DCLICK(self.lcFiles, self.OnOpen)
 
     #def OnSize(self, event):
     #    self.Layout()
 
+    def setDimensions(self, dims):
+        self.SetClientSize(dims)        
+
+    def getDimensions(self):
+        return self.GetClientSize()
+    
+    def setDefaultDimensions(self):
+        if self._lastSize:
+            self.SetClientSize(self._lastSize)
+        else:
+            self.SetClientSize(self._dialogClientSize)
+
     def Destroy(self):
         self.htmlBackCol = None
         self.lcFiles.destroy(dont_pop=self.dont_pop)
             dir = self.GetDirectory()
             wxBoaFileDialog.currentDir = dir
             wxBoaFileDialog._lastSize = self.GetClientSize()
+            self.saveDims()
             self.EndModal(wxID_OK)
 
     def OnOpen(self, event):
     return namespace
 
 class FrameRestorerMixin:
+    """ Used by top level windows to restore from gidden or iconised state
+    and to load and persist window dimensions 
+    
+    Classes using the mixin mus define self.setDefaultDimensions()
+    """
     confFile = 'Explorer'
     confSection = 'windowdims'
 
             self.Iconize(false)
         self.Raise()
 
+    def setDimensions(self, dims):
+        apply(self.SetDimensions, dims)        
+
+    def getDimensions(self):
+        return self.GetPosition().asTuple() + self.GetSize().asTuple()        
+
     def loadDims(self):
         conf = createAndReadConfig(self.confFile)
-        dims = eval(conf.get(self.confSection , self.winConfOption))
+        if not conf.has_option(self.confSection, self.winConfOption):
+            dims = None
+        else:
+            dims = eval(conf.get(self.confSection , self.winConfOption))
+
         if dims:
-            apply(self.SetDimensions, dims)
+            self.setDimensions(dims)
         else:
             self.setDefaultDimensions()
 
     def saveDims(self, dims=()):
         if dims == ():
-            dims = self.GetPosition().asTuple() + self.GetSize().asTuple()
+            dims = self.getDimensions()
         conf = createAndReadConfig(self.confFile)
         conf.set(self.confSection, self.winConfOption, `dims`)
         writeConfig(conf)