]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/wx/lib/filebrowsebutton.py
always use wxPyPanel
[wxWidgets.git] / wxPython / wx / lib / filebrowsebutton.py
index 0a492fd7fcc21f5161e0cdcc4cd3f574a90e4bc5..e2e829da025609246e7cbbd5f52ea7afc2a594db 100644 (file)
@@ -42,7 +42,8 @@ class FileBrowseButton(wx.Panel):
                   fileMask = "*.*",
                   fileMode = wx.OPEN,
                   # callback for when value changes (optional)
-                  changeCallback= lambda x:x
+                  changeCallback= lambda x:x,
+                  labelWidth = 0
         ):
         """
         :param labelText:      Text for label to left of text field
@@ -53,6 +54,7 @@ class FileBrowseButton(wx.Panel):
         :param fileMask:       File mask (glob pattern, such as *.*) to use in file dialog
         :param fileMode:       wx.OPEN or wx.SAVE, indicates type of file dialog to use
         :param changeCallback: Optional callback called for all changes in value of the control
+        :param labelWidth:     Width of the label
         """
       
         # store variables
@@ -66,13 +68,7 @@ class FileBrowseButton(wx.Panel):
         self.fileMode = fileMode
         self.changeCallback = changeCallback
         self.callCallback = True
-
-
-        # get background to match it
-        try:
-            self._bc = parent.GetBackgroundColour()
-        except:
-            pass
+        self.labelWidth = labelWidth
 
         # create the dialog
         self.createDialog(parent, id, pos, size, style )
@@ -88,15 +84,6 @@ class FileBrowseButton(wx.Panel):
         wx.Panel.__init__ (self, parent, id, pos, size, style)
         self.SetMinSize(size) # play nice with sizers
 
-        # try to set the background colour
-        try:
-            #Question: is this still needed on other platforms?
-            #It should have transparent background on Mac
-            if wx.Platform != "__WXMAC__":
-                self.SetBackgroundColour(self._bc)
-        except:
-            pass
-
         box = wx.BoxSizer(wx.HORIZONTAL)
 
         self.label = self.createLabel( )
@@ -132,7 +119,10 @@ class FileBrowseButton(wx.Panel):
         label = wx.StaticText(self, -1, self.labelText, style =wx.ALIGN_RIGHT )
         font = label.GetFont()
         w, h, d, e = self.GetFullTextExtent(self.labelText, font)
-        label.SetSize((w+5, h))
+        if self.labelWidth > 0:
+            label.SetSize((self.labelWidth+5, h))
+        else:
+            label.SetSize((w+5, h))
         return label
 
     def createTextControl( self):
@@ -257,8 +247,8 @@ class FileBrowseButtonWithHistory( FileBrowseButton ):
         textControl.SetToolTipString( self.toolTip )
         textControl.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
         if self.changeCallback:
-            textControl.Bind(wx.EVT_TEXT, self.changeCallback)
-            textControl.Bind(wx.EVT_COMBOBOX, self.changeCallback)
+            textControl.Bind(wx.EVT_TEXT, self.OnChanged)
+            textControl.Bind(wx.EVT_COMBOBOX, self.OnChanged)
         if self.history:
             history=self.history
             self.history=None
@@ -304,8 +294,10 @@ class FileBrowseButtonWithHistory( FileBrowseButton ):
         """Return the current history list"""
         if self.historyCallBack != None:
             return self.historyCallBack()
-        else:
+        elif self.history:
             return list( self.history )
+        else:
+            return []
 
 
     def OnSetFocus(self, event):