2003-11-12 21:34:20 +00:00
|
|
|
#----------------------------------------------------------------------
|
|
|
|
# Name: wxPython.lib.filebrowsebutton
|
|
|
|
# Purpose: Composite controls that provide a Browse button next to
|
|
|
|
# either a wxTextCtrl or a wxComboBox. The Browse button
|
|
|
|
# launches a wxFileDialog and loads the result into the
|
|
|
|
# other control.
|
|
|
|
#
|
|
|
|
# Author: Mike Fletcher
|
|
|
|
#
|
|
|
|
# RCS-ID: $Id$
|
|
|
|
# Copyright: (c) 2000 by Total Control Software
|
|
|
|
# Licence: wxWindows license
|
|
|
|
#----------------------------------------------------------------------
|
2003-12-17 00:34:40 +00:00
|
|
|
# 12/02/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
|
|
|
#
|
|
|
|
# o 2.5 Compatability changes
|
|
|
|
#
|
|
|
|
|
|
|
|
import os
|
|
|
|
import types
|
2003-11-12 21:34:20 +00:00
|
|
|
|
2003-12-17 00:34:40 +00:00
|
|
|
import wx
|
2003-11-12 21:34:20 +00:00
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
2003-12-17 00:34:40 +00:00
|
|
|
class FileBrowseButton(wx.Panel):
|
2004-06-17 05:52:01 +00:00
|
|
|
"""
|
|
|
|
A control to allow the user to type in a filename or browse with
|
|
|
|
the standard file dialog to select file
|
2003-11-12 21:34:20 +00:00
|
|
|
"""
|
|
|
|
def __init__ (self, parent, id= -1,
|
2004-06-17 05:52:01 +00:00
|
|
|
pos = wx.DefaultPosition,
|
|
|
|
size = wx.DefaultSize,
|
|
|
|
style = wx.TAB_TRAVERSAL,
|
|
|
|
labelText= "File Entry:",
|
|
|
|
buttonText= "Browse",
|
|
|
|
toolTip= "Type filename or click browse to choose file",
|
|
|
|
# following are the values for a file dialog box
|
|
|
|
dialogTitle = "Choose a file",
|
|
|
|
startDirectory = ".",
|
|
|
|
initialValue = "",
|
|
|
|
fileMask = "*.*",
|
|
|
|
fileMode = wx.OPEN,
|
|
|
|
# callback for when value changes (optional)
|
|
|
|
changeCallback= lambda x:x
|
2003-11-12 21:34:20 +00:00
|
|
|
):
|
2004-06-17 05:52:01 +00:00
|
|
|
"""
|
|
|
|
:param labelText: Text for label to left of text field
|
|
|
|
:param buttonText: Text for button which launches the file dialog
|
|
|
|
:param toolTip: Help text
|
|
|
|
:param dialogTitle: Title used in file dialog
|
|
|
|
:param startDirectory: Default directory for file dialog startup
|
|
|
|
: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
|
2005-01-13 21:14:15 +00:00
|
|
|
:param changeCallback: Optional callback called for all changes in value of the control
|
2004-06-17 05:52:01 +00:00
|
|
|
"""
|
|
|
|
|
2003-11-12 21:34:20 +00:00
|
|
|
# store variables
|
|
|
|
self.labelText = labelText
|
|
|
|
self.buttonText = buttonText
|
|
|
|
self.toolTip = toolTip
|
|
|
|
self.dialogTitle = dialogTitle
|
|
|
|
self.startDirectory = startDirectory
|
|
|
|
self.initialValue = initialValue
|
|
|
|
self.fileMask = fileMask
|
|
|
|
self.fileMode = fileMode
|
|
|
|
self.changeCallback = changeCallback
|
|
|
|
self.callCallback = True
|
|
|
|
|
|
|
|
|
|
|
|
# create the dialog
|
|
|
|
self.createDialog(parent, id, pos, size, style )
|
|
|
|
# Setting a value causes the changeCallback to be called.
|
|
|
|
# In this case that would be before the return of the
|
|
|
|
# constructor. Not good. So a default value on
|
|
|
|
# SetValue is used to disable the callback
|
|
|
|
self.SetValue( initialValue, 0)
|
|
|
|
|
|
|
|
|
|
|
|
def createDialog( self, parent, id, pos, size, style ):
|
|
|
|
"""Setup the graphic representation of the dialog"""
|
2003-12-17 00:34:40 +00:00
|
|
|
wx.Panel.__init__ (self, parent, id, pos, size, style)
|
2005-01-13 21:14:15 +00:00
|
|
|
self.SetMinSize(size) # play nice with sizers
|
|
|
|
|
2003-12-17 00:34:40 +00:00
|
|
|
box = wx.BoxSizer(wx.HORIZONTAL)
|
2003-11-12 21:34:20 +00:00
|
|
|
|
|
|
|
self.label = self.createLabel( )
|
2003-12-17 00:34:40 +00:00
|
|
|
box.Add( self.label, 0, wx.CENTER )
|
2003-11-12 21:34:20 +00:00
|
|
|
|
|
|
|
self.textControl = self.createTextControl()
|
2003-12-17 00:34:40 +00:00
|
|
|
box.Add( self.textControl, 1, wx.LEFT|wx.CENTER, 5)
|
2003-11-12 21:34:20 +00:00
|
|
|
|
|
|
|
self.browseButton = self.createBrowseButton()
|
2003-12-17 00:34:40 +00:00
|
|
|
box.Add( self.browseButton, 0, wx.LEFT|wx.CENTER, 5)
|
2003-11-12 21:34:20 +00:00
|
|
|
|
|
|
|
# add a border around the whole thing and resize the panel to fit
|
2003-12-17 00:34:40 +00:00
|
|
|
outsidebox = wx.BoxSizer(wx.VERTICAL)
|
|
|
|
outsidebox.Add(box, 1, wx.EXPAND|wx.ALL, 3)
|
2003-11-12 21:34:20 +00:00
|
|
|
outsidebox.Fit(self)
|
|
|
|
|
|
|
|
self.SetAutoLayout(True)
|
|
|
|
self.SetSizer( outsidebox )
|
|
|
|
self.Layout()
|
|
|
|
if type( size ) == types.TupleType:
|
2003-12-17 00:34:40 +00:00
|
|
|
size = apply( wx.Size, size)
|
|
|
|
self.SetDimensions(-1, -1, size.width, size.height, wx.SIZE_USE_EXISTING)
|
2003-11-12 21:34:20 +00:00
|
|
|
|
|
|
|
# if size.width != -1 or size.height != -1:
|
|
|
|
# self.SetSize(size)
|
|
|
|
|
|
|
|
def SetBackgroundColour(self,color):
|
2003-12-17 00:34:40 +00:00
|
|
|
wx.Panel.SetBackgroundColour(self,color)
|
2003-11-12 21:34:20 +00:00
|
|
|
self.label.SetBackgroundColour(color)
|
|
|
|
|
|
|
|
def createLabel( self ):
|
|
|
|
"""Create the label/caption"""
|
2003-12-17 00:34:40 +00:00
|
|
|
label = wx.StaticText(self, -1, self.labelText, style =wx.ALIGN_RIGHT )
|
2003-11-12 21:34:20 +00:00
|
|
|
font = label.GetFont()
|
|
|
|
w, h, d, e = self.GetFullTextExtent(self.labelText, font)
|
2003-12-17 00:34:40 +00:00
|
|
|
label.SetSize((w+5, h))
|
2003-11-12 21:34:20 +00:00
|
|
|
return label
|
|
|
|
|
|
|
|
def createTextControl( self):
|
|
|
|
"""Create the text control"""
|
2003-12-17 00:34:40 +00:00
|
|
|
textControl = wx.TextCtrl(self, -1)
|
2003-11-12 21:34:20 +00:00
|
|
|
textControl.SetToolTipString( self.toolTip )
|
|
|
|
if self.changeCallback:
|
2003-12-17 00:34:40 +00:00
|
|
|
textControl.Bind(wx.EVT_TEXT, self.OnChanged)
|
|
|
|
textControl.Bind(wx.EVT_COMBOBOX, self.OnChanged)
|
2003-11-12 21:34:20 +00:00
|
|
|
return textControl
|
|
|
|
|
|
|
|
def OnChanged(self, evt):
|
|
|
|
if self.callCallback and self.changeCallback:
|
|
|
|
self.changeCallback(evt)
|
|
|
|
|
|
|
|
def createBrowseButton( self):
|
|
|
|
"""Create the browse-button control"""
|
2003-12-17 00:34:40 +00:00
|
|
|
button =wx.Button(self, -1, self.buttonText)
|
2003-11-12 21:34:20 +00:00
|
|
|
button.SetToolTipString( self.toolTip )
|
2003-12-17 00:34:40 +00:00
|
|
|
button.Bind(wx.EVT_BUTTON, self.OnBrowse)
|
2003-11-12 21:34:20 +00:00
|
|
|
return button
|
|
|
|
|
|
|
|
|
|
|
|
def OnBrowse (self, event = None):
|
|
|
|
""" Going to browse for file... """
|
|
|
|
current = self.GetValue()
|
|
|
|
directory = os.path.split(current)
|
|
|
|
if os.path.isdir( current):
|
|
|
|
directory = current
|
|
|
|
current = ''
|
|
|
|
elif directory and os.path.isdir( directory[0] ):
|
|
|
|
current = directory[1]
|
|
|
|
directory = directory [0]
|
|
|
|
else:
|
|
|
|
directory = self.startDirectory
|
2003-12-17 00:34:40 +00:00
|
|
|
dlg = wx.FileDialog(self, self.dialogTitle, directory, current,
|
|
|
|
self.fileMask, self.fileMode)
|
2003-11-12 21:34:20 +00:00
|
|
|
|
2003-12-17 00:34:40 +00:00
|
|
|
if dlg.ShowModal() == wx.ID_OK:
|
2003-11-12 21:34:20 +00:00
|
|
|
self.SetValue(dlg.GetPath())
|
|
|
|
dlg.Destroy()
|
|
|
|
|
|
|
|
|
|
|
|
def GetValue (self):
|
2004-06-17 05:52:01 +00:00
|
|
|
"""
|
|
|
|
retrieve current value of text control
|
|
|
|
"""
|
2003-11-12 21:34:20 +00:00
|
|
|
return self.textControl.GetValue()
|
|
|
|
|
|
|
|
def SetValue (self, value, callBack=1):
|
2004-06-17 05:52:01 +00:00
|
|
|
"""set current value of text control"""
|
2003-11-12 21:34:20 +00:00
|
|
|
save = self.callCallback
|
|
|
|
self.callCallback = callBack
|
|
|
|
self.textControl.SetValue(value)
|
|
|
|
self.callCallback = save
|
|
|
|
|
|
|
|
|
|
|
|
def Enable (self, value):
|
|
|
|
""" Convenient enabling/disabling of entire control """
|
|
|
|
self.label.Enable (value)
|
|
|
|
self.textControl.Enable (value)
|
|
|
|
return self.browseButton.Enable (value)
|
|
|
|
|
|
|
|
def GetLabel( self ):
|
|
|
|
""" Retrieve the label's current text """
|
|
|
|
return self.label.GetLabel()
|
|
|
|
|
|
|
|
def SetLabel( self, value ):
|
|
|
|
""" Set the label's current text """
|
|
|
|
rvalue = self.label.SetLabel( value )
|
|
|
|
self.Refresh( True )
|
|
|
|
return rvalue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FileBrowseButtonWithHistory( FileBrowseButton ):
|
2004-06-17 05:52:01 +00:00
|
|
|
"""
|
|
|
|
with following additions:
|
2003-11-12 21:34:20 +00:00
|
|
|
__init__(..., history=None)
|
|
|
|
|
|
|
|
history -- optional list of paths for initial history drop-down
|
|
|
|
(must be passed by name, not a positional argument)
|
|
|
|
If history is callable it will must return a list used
|
|
|
|
for the history drop-down
|
2004-06-17 05:52:01 +00:00
|
|
|
|
2003-11-12 21:34:20 +00:00
|
|
|
changeCallback -- as for FileBrowseButton, but with a work-around
|
2003-12-17 00:34:40 +00:00
|
|
|
for win32 systems which don't appear to create wx.EVT_COMBOBOX
|
2003-11-12 21:34:20 +00:00
|
|
|
events properly. There is a (slight) chance that this work-around
|
|
|
|
will cause some systems to create two events for each Combobox
|
|
|
|
selection. If you discover this condition, please report it!
|
2004-06-17 05:52:01 +00:00
|
|
|
|
2003-11-12 21:34:20 +00:00
|
|
|
As for a FileBrowseButton.__init__ otherwise.
|
2004-06-17 05:52:01 +00:00
|
|
|
|
2003-11-12 21:34:20 +00:00
|
|
|
GetHistoryControl()
|
|
|
|
Return reference to the control which implements interfaces
|
|
|
|
required for manipulating the history list. See GetHistoryControl
|
|
|
|
documentation for description of what that interface is.
|
2004-06-17 05:52:01 +00:00
|
|
|
|
2003-11-12 21:34:20 +00:00
|
|
|
GetHistory()
|
|
|
|
Return current history list
|
2004-06-17 05:52:01 +00:00
|
|
|
|
2003-11-12 21:34:20 +00:00
|
|
|
SetHistory( value=(), selectionIndex = None )
|
|
|
|
Set current history list, if selectionIndex is not None, select that index
|
2004-06-17 05:52:01 +00:00
|
|
|
|
2003-11-12 21:34:20 +00:00
|
|
|
"""
|
|
|
|
def __init__( self, *arguments, **namedarguments):
|
|
|
|
self.history = namedarguments.get( "history" )
|
|
|
|
if self.history:
|
|
|
|
del namedarguments["history"]
|
|
|
|
|
|
|
|
self.historyCallBack=None
|
|
|
|
if callable(self.history):
|
|
|
|
self.historyCallBack=self.history
|
|
|
|
self.history=None
|
|
|
|
apply( FileBrowseButton.__init__, ( self,)+arguments, namedarguments)
|
|
|
|
|
|
|
|
|
|
|
|
def createTextControl( self):
|
|
|
|
"""Create the text control"""
|
2003-12-17 00:34:40 +00:00
|
|
|
textControl = wx.ComboBox(self, -1, style = wx.CB_DROPDOWN )
|
2003-11-12 21:34:20 +00:00
|
|
|
textControl.SetToolTipString( self.toolTip )
|
2003-12-17 00:34:40 +00:00
|
|
|
textControl.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
|
2003-11-12 21:34:20 +00:00
|
|
|
if self.changeCallback:
|
2003-12-17 00:34:40 +00:00
|
|
|
textControl.Bind(wx.EVT_TEXT, self.changeCallback)
|
|
|
|
textControl.Bind(wx.EVT_COMBOBOX, self.changeCallback)
|
2003-11-12 21:34:20 +00:00
|
|
|
if self.history:
|
|
|
|
history=self.history
|
|
|
|
self.history=None
|
|
|
|
self.SetHistory( history, control=textControl)
|
|
|
|
return textControl
|
|
|
|
|
|
|
|
|
|
|
|
def GetHistoryControl( self ):
|
2004-06-17 05:52:01 +00:00
|
|
|
"""
|
|
|
|
Return a pointer to the control which provides (at least)
|
|
|
|
the following methods for manipulating the history list:
|
|
|
|
|
2003-11-12 21:34:20 +00:00
|
|
|
Append( item ) -- add item
|
|
|
|
Clear() -- clear all items
|
|
|
|
Delete( index ) -- 0-based index to delete from list
|
|
|
|
SetSelection( index ) -- 0-based index to select in list
|
2004-06-17 05:52:01 +00:00
|
|
|
|
2003-11-12 21:34:20 +00:00
|
|
|
Semantics of the methods follow those for the wxComboBox control
|
|
|
|
"""
|
|
|
|
return self.textControl
|
|
|
|
|
|
|
|
|
|
|
|
def SetHistory( self, value=(), selectionIndex = None, control=None ):
|
|
|
|
"""Set the current history list"""
|
|
|
|
if control is None:
|
|
|
|
control = self.GetHistoryControl()
|
|
|
|
if self.history == value:
|
|
|
|
return
|
|
|
|
self.history = value
|
|
|
|
# Clear history values not the selected one.
|
|
|
|
tempValue=control.GetValue()
|
|
|
|
# clear previous values
|
|
|
|
control.Clear()
|
|
|
|
control.SetValue(tempValue)
|
|
|
|
# walk through, appending new values
|
|
|
|
for path in value:
|
|
|
|
control.Append( path )
|
|
|
|
if selectionIndex is not None:
|
|
|
|
control.SetSelection( selectionIndex )
|
|
|
|
|
|
|
|
|
|
|
|
def GetHistory( self ):
|
|
|
|
"""Return the current history list"""
|
|
|
|
if self.historyCallBack != None:
|
|
|
|
return self.historyCallBack()
|
2005-05-18 18:03:29 +00:00
|
|
|
elif self.history:
|
2003-11-12 21:34:20 +00:00
|
|
|
return list( self.history )
|
2005-05-18 18:03:29 +00:00
|
|
|
else:
|
|
|
|
return []
|
2003-11-12 21:34:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
def OnSetFocus(self, event):
|
|
|
|
"""When the history scroll is selected, update the history"""
|
|
|
|
if self.historyCallBack != None:
|
|
|
|
self.SetHistory( self.historyCallBack(), control=self.textControl)
|
|
|
|
event.Skip()
|
|
|
|
|
|
|
|
|
2003-12-17 00:34:40 +00:00
|
|
|
if wx.Platform == "__WXMSW__":
|
2003-11-12 21:34:20 +00:00
|
|
|
def SetValue (self, value, callBack=1):
|
|
|
|
""" Convenient setting of text control value, works
|
2003-12-17 00:34:40 +00:00
|
|
|
around limitation of wx.ComboBox """
|
2003-11-12 21:34:20 +00:00
|
|
|
save = self.callCallback
|
|
|
|
self.callCallback = callBack
|
|
|
|
self.textControl.SetValue(value)
|
|
|
|
self.callCallback = save
|
|
|
|
|
|
|
|
# Hack to call an event handler
|
|
|
|
class LocalEvent:
|
|
|
|
def __init__(self, string):
|
|
|
|
self._string=string
|
|
|
|
def GetString(self):
|
|
|
|
return self._string
|
|
|
|
if callBack==1:
|
|
|
|
# The callback wasn't being called when SetValue was used ??
|
|
|
|
# So added this explicit call to it
|
|
|
|
self.changeCallback(LocalEvent(value))
|
|
|
|
|
|
|
|
|
|
|
|
class DirBrowseButton(FileBrowseButton):
|
|
|
|
def __init__(self, parent, id = -1,
|
2003-12-17 00:34:40 +00:00
|
|
|
pos = wx.DefaultPosition, size = wx.DefaultSize,
|
|
|
|
style = wx.TAB_TRAVERSAL,
|
2003-11-12 21:34:20 +00:00
|
|
|
labelText = 'Select a directory:',
|
|
|
|
buttonText = 'Browse',
|
|
|
|
toolTip = 'Type directory name or browse to select',
|
|
|
|
dialogTitle = '',
|
|
|
|
startDirectory = '.',
|
|
|
|
changeCallback = None,
|
2005-03-01 23:52:44 +00:00
|
|
|
dialogClass = wx.DirDialog,
|
|
|
|
newDirectory = False):
|
2003-11-12 21:34:20 +00:00
|
|
|
FileBrowseButton.__init__(self, parent, id, pos, size, style,
|
|
|
|
labelText, buttonText, toolTip,
|
|
|
|
dialogTitle, startDirectory,
|
|
|
|
changeCallback = changeCallback)
|
2004-01-05 19:54:39 +00:00
|
|
|
self.dialogClass = dialogClass
|
2005-03-01 23:52:44 +00:00
|
|
|
self.newDirectory = newDirectory
|
2003-11-12 21:34:20 +00:00
|
|
|
#
|
2004-01-05 19:54:39 +00:00
|
|
|
|
2003-11-12 21:34:20 +00:00
|
|
|
def OnBrowse(self, ev = None):
|
2005-03-01 23:52:44 +00:00
|
|
|
style=0
|
|
|
|
|
|
|
|
if self.newDirectory:
|
|
|
|
style|=wx.DD_NEW_DIR_BUTTON
|
|
|
|
|
2004-01-05 19:54:39 +00:00
|
|
|
dialog = self.dialogClass(self,
|
|
|
|
message = self.dialogTitle,
|
2005-03-01 23:52:44 +00:00
|
|
|
defaultPath = self.startDirectory,
|
|
|
|
style = style)
|
|
|
|
|
2003-12-17 00:34:40 +00:00
|
|
|
if dialog.ShowModal() == wx.ID_OK:
|
2003-11-12 21:34:20 +00:00
|
|
|
self.SetValue(dialog.GetPath())
|
2004-01-05 19:54:39 +00:00
|
|
|
dialog.Destroy()
|
2003-11-12 21:34:20 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
#from skeletonbuilder import rulesfile
|
|
|
|
class SimpleCallback:
|
|
|
|
def __init__( self, tag ):
|
|
|
|
self.tag = tag
|
|
|
|
def __call__( self, event ):
|
|
|
|
print self.tag, event.GetString()
|
2003-12-17 00:34:40 +00:00
|
|
|
class DemoFrame( wx.Frame ):
|
2003-11-12 21:34:20 +00:00
|
|
|
def __init__(self, parent):
|
2003-12-17 00:34:40 +00:00
|
|
|
wx.Frame.__init__(self, parent, -1, "File entry with browse", size=(500,260))
|
|
|
|
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
|
|
|
|
panel = wx.Panel (self,-1)
|
|
|
|
innerbox = wx.BoxSizer(wx.VERTICAL)
|
2003-11-12 21:34:20 +00:00
|
|
|
control = FileBrowseButton(
|
|
|
|
panel,
|
|
|
|
initialValue = "z:\\temp",
|
|
|
|
)
|
2003-12-17 00:34:40 +00:00
|
|
|
innerbox.Add( control, 0, wx.EXPAND )
|
2003-11-12 21:34:20 +00:00
|
|
|
middlecontrol = FileBrowseButtonWithHistory(
|
|
|
|
panel,
|
|
|
|
labelText = "With History",
|
|
|
|
initialValue = "d:\\temp",
|
|
|
|
history = ["c:\\temp", "c:\\tmp", "r:\\temp","z:\\temp"],
|
|
|
|
changeCallback= SimpleCallback( "With History" ),
|
|
|
|
)
|
2003-12-17 00:34:40 +00:00
|
|
|
innerbox.Add( middlecontrol, 0, wx.EXPAND )
|
2003-11-12 21:34:20 +00:00
|
|
|
middlecontrol = FileBrowseButtonWithHistory(
|
|
|
|
panel,
|
|
|
|
labelText = "History callback",
|
|
|
|
initialValue = "d:\\temp",
|
|
|
|
history = self.historyCallBack,
|
|
|
|
changeCallback= SimpleCallback( "History callback" ),
|
|
|
|
)
|
2003-12-17 00:34:40 +00:00
|
|
|
innerbox.Add( middlecontrol, 0, wx.EXPAND )
|
2003-11-12 21:34:20 +00:00
|
|
|
self.bottomcontrol = control = FileBrowseButton(
|
|
|
|
panel,
|
|
|
|
labelText = "With Callback",
|
2003-12-17 00:34:40 +00:00
|
|
|
style = wx.SUNKEN_BORDER|wx.CLIP_CHILDREN ,
|
2003-11-12 21:34:20 +00:00
|
|
|
changeCallback= SimpleCallback( "With Callback" ),
|
|
|
|
)
|
2003-12-17 00:34:40 +00:00
|
|
|
innerbox.Add( control, 0, wx.EXPAND)
|
2003-11-12 21:34:20 +00:00
|
|
|
self.bottommostcontrol = control = DirBrowseButton(
|
|
|
|
panel,
|
|
|
|
labelText = "Simple dir browse button",
|
2003-12-17 00:34:40 +00:00
|
|
|
style = wx.SUNKEN_BORDER|wx.CLIP_CHILDREN)
|
|
|
|
innerbox.Add( control, 0, wx.EXPAND)
|
|
|
|
ID = wx.NewId()
|
|
|
|
innerbox.Add( wx.Button( panel, ID,"Change Label", ), 1, wx.EXPAND)
|
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnChangeLabel , id=ID)
|
|
|
|
ID = wx.NewId()
|
|
|
|
innerbox.Add( wx.Button( panel, ID,"Change Value", ), 1, wx.EXPAND)
|
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnChangeValue, id=ID )
|
2003-11-12 21:34:20 +00:00
|
|
|
panel.SetAutoLayout(True)
|
|
|
|
panel.SetSizer( innerbox )
|
|
|
|
self.history={"c:\\temp":1, "c:\\tmp":1, "r:\\temp":1,"z:\\temp":1}
|
|
|
|
|
|
|
|
def historyCallBack(self):
|
|
|
|
keys=self.history.keys()
|
|
|
|
keys.sort()
|
|
|
|
return keys
|
|
|
|
|
|
|
|
def OnFileNameChangedHistory (self, event):
|
|
|
|
self.history[event.GetString ()]=1
|
|
|
|
|
|
|
|
def OnCloseMe(self, event):
|
|
|
|
self.Close(True)
|
|
|
|
def OnChangeLabel( self, event ):
|
|
|
|
self.bottomcontrol.SetLabel( "Label Updated" )
|
|
|
|
def OnChangeValue( self, event ):
|
|
|
|
self.bottomcontrol.SetValue( "r:\\somewhere\\over\\the\\rainbow.htm" )
|
|
|
|
|
|
|
|
def OnCloseWindow(self, event):
|
|
|
|
self.Destroy()
|
|
|
|
|
2003-12-17 00:34:40 +00:00
|
|
|
class DemoApp(wx.App):
|
2003-11-12 21:34:20 +00:00
|
|
|
def OnInit(self):
|
2003-12-17 00:34:40 +00:00
|
|
|
wx.InitAllImageHandlers()
|
|
|
|
frame = DemoFrame(None)
|
2003-11-12 21:34:20 +00:00
|
|
|
frame.Show(True)
|
|
|
|
self.SetTopWindow(frame)
|
|
|
|
return True
|
|
|
|
|
|
|
|
def test( ):
|
|
|
|
app = DemoApp(0)
|
|
|
|
app.MainLoop()
|
|
|
|
print 'Creating dialog'
|
|
|
|
test( )
|
|
|
|
|
2003-07-02 23:13:10 +00:00
|
|
|
|
|
|
|
|