rem
stringlengths
0
322k
add
stringlengths
0
2.05M
context
stringlengths
8
228k
self.y_spin = wx.SpinButton(self, -1, (220, 20), (h*2, h), wx.SP_VERTICAL)
self.y_spin = wx.SpinButton(self, -1, (225, 20), (h*1.5, h), wx.SP_VERTICAL)
def __init__(self, parent, month=None, day = None, year=None): wx.Dialog.__init__(self, parent, -1, "Event Calendar", wx.DefaultPosition, (280, 360))
btn = wx.Button(self, -1, ' Ok ', (x_pos, y_pos), but_size)
btn = wx.Button(self, wx.ID_OK, ' Ok ', (x_pos, y_pos), but_size)
def __init__(self, parent, month=None, day = None, year=None): wx.Dialog.__init__(self, parent, -1, "Event Calendar", wx.DefaultPosition, (280, 360))
btn = wx.Button(self, -1, ' Close ', (x_pos + 120, y_pos), but_size)
btn = wx.Button(self, wx.ID_CANCEL, ' Close ', (x_pos + 120, y_pos), but_size)
def __init__(self, parent, month=None, day = None, year=None): wx.Dialog.__init__(self, parent, -1, "Event Calendar", wx.DefaultPosition, (280, 360))
def OnOk(self, event):
def OnOk(self, evt): self.result = ['None', str(self.calend.day), Month[self.calend.month], str(self.calend.year)]
def OnOk(self, event): self.EndModal(wx.ID_OK)
cmd = ['swig'] + swig_args + ['-I'+dir, '-c', '-o', cpp_file, i_file]
cmd = ['./wxSWIG/wxswig'] + swig_args + ['-I'+dir, '-c', '-o', cpp_file, i_file]
def run_swig(files, dir, gendir, package, USE_SWIG, force, swig_args, swig_deps=[]): from distutils.file_util import copy_file from distutils.dep_util import newer from distutils.spawn import spawn sources = [] for file in files: basefile = os.path.splitext(file)[0] i_file = os.path.join(dir, file) py_file = os.path.join(dir, gendir, basefile+'.py') cpp_file = os.path.join(dir, gendir, basefile+'.cpp') sources.append(cpp_file) if USE_SWIG: for dep in swig_deps: if newer(dep, py_file) or newer(dep, cpp_file): force = 1 break if force or newer(i_file, py_file) or newer(i_file, cpp_file): # we need forward slashes here even on win32 cpp_file = string.join(string.split(cpp_file, '\\'), '/') i_file = string.join(string.split(i_file, '\\'), '/') cmd = ['swig'] + swig_args + ['-I'+dir, '-c', '-o', cpp_file, i_file] spawn(cmd, verbose=1) # copy the generated python file to the package directory copy_file(py_file, package, update=not force, verbose=0) return sources
wxScrolledWindow.Refresh(self)
wxScrolledWindow.Refresh(self, false)
def Refresh(self): if self.doubleBuffered: self.painter.ClearBuffer() wxScrolledWindow.Refresh(self)
self.text = wxTextCtrl(self.frame, -1, "", style = wx.TE_MULTILINE | wx.TE_READONLY)
self.text = wx.TextCtrl(self.frame, -1, "", style = wx.TE_MULTILINE | wx.TE_READONLY)
def CreateOutputWindow(self, st): self.frame = wx.Frame(self.parent, -1, self.title, style=wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE) self.text = wxTextCtrl(self.frame, -1, "", style = wx.TE_MULTILINE | wx.TE_READONLY) self.frame.SetSize((450, 300)) self.frame.Show(True) EVT_CLOSE(self.frame, self.OnCloseWindow)
self.frame = wxFrame(None, -1, "Widget Tester", pos=(0,0), size=self.size)
self.frame = wx.Frame(None, -1, "Widget Tester", pos=(0,0), size=self.size)
def OnInit(self): self.frame = wxFrame(None, -1, "Widget Tester", pos=(0,0), size=self.size) self.SetTopWindow(self.frame) return True
def __str__(self): return str(self.asTuple()) def __repr__(self): return str(self.asTuple())
def __str__(self): return str(self.asTuple()) def __repr__(self): return str(self.asTuple()) def __len__(self): return len(self.asTuple()) def __getitem__(self, index): return self.asTuple()[index] def __setitem__(self, index, val): if index == 0: self.width = val elif index == 1: self.height = val else: raise IndexError
def __str__(self): return str(self.asTuple())
def __str__(self): return str(self.asTuple()) def __repr__(self): return str(self.asTuple())
def __str__(self): return str(self.asTuple()) def __repr__(self): return str(self.asTuple()) def __len__(self): return len(self.asTuple()) def __getitem__(self, index): return self.asTuple()[index] def __setitem__(self, index, val): if index == 0: self.x = val elif index == 1: self.y = val else: raise IndexError
def __str__(self): return str(self.asTuple())
def __str__(self): return str(self.asTuple()) def __repr__(self): return str(self.asTuple())
def __str__(self): return str(self.asTuple())
def __del__(self,oglshapesc=oglshapesc): if self.thisown == 1 : oglshapesc.delete_wxOGLConstraint(self)
def __del__(self,oglshapesc=oglshapesc): if self.thisown == 1 : oglshapesc.delete_wxOGLConstraint(self)
'six', 'seven', 'eight'], wxOK|wxCANCEL)
'six', 'seven', 'eight'], wxDEFAULT_DIALOG_STYLE|wxOK|wxCANCEL)
def runTest(frame, nb, log): dlg = wxSingleChoiceDialog(frame, 'Test Single Choice', 'The Caption', ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight'], wxOK|wxCANCEL) if dlg.ShowModal() == wxID_OK: log.WriteText('You selected: %s\n' % dlg.GetStringSelection()) dlg.Destroy()
self.shiftkey = event.ShiftDown() self.ctrlkey = event.ControlDown()
def OnLeftEvent(self, event): self.click = 'LEFT' self.shiftkey = event.ShiftDown() self.ctrlkey = event.ControlDown() self.ProcessClick(event)
b = wx.Button(self, -1, "Show the FloatBar sample", (50,50))
b = wx.Button(self, -1, "Show the FloatCanvas sample", (50,50))
def __init__(self, parent, log): self.log = log wx.Panel.__init__(self, parent, -1)
self.html.SetPage(About.MyAboutBox.text % (wx.VERSION_STRING, py_version))
self.html.SetPage(About.MyAboutBox.text % (wx.VERSION_STRING, ", ".join(wx.PlatformInfo[1:]), py_version))
def __init__(self, parent, id=-1, size=wx.DefaultSize):
libdirs = [opj(WXDIR, 'lib'), 'build\\ilib']
libdirs = [ opj(WXDIR, 'lib') ]
def libFlag(): if FINAL: rv = '' elif HYBRID: rv = 'h' else: rv = 'd' if UNICODE: rv = 'u' + rv return rv
cflags = [
cflags = [ '/Gy',
def libFlag(): if FINAL: rv = '' elif HYBRID: rv = 'h' else: rv = 'd' if UNICODE: rv = 'u' + rv return rv
if not FINAL and HYBRID and not bcpp_compiling: cflags = cflags + ['/Od', '/Z7'] lflags = ['/DEBUG', ] elif bcpp_compiling and not FINAL: cflags = cflags + ['/Od', '/v', '/y'] lflags = lflags + ['/v', ]
if not FINAL: cflags = cflags + ['/Od', '/v', '/y'] lflags = lflags + ['/v', ] else: if FINAL: pass elif HYBRID : pass else: pass
def libFlag(): if FINAL: rv = '' elif HYBRID: rv = 'h' else: rv = 'd' if UNICODE: rv = 'u' + rv return rv
self.SetValue(calltip)
self.Clear() self.AppendText(calltip)
def display(self, calltip): """Receiver for Shell.calltip signal.""" self.SetValue(calltip)
self._pen = wx.Pen(wx.BLACK, 1, wx.SOLID)
self._pen = BlackForegroundPen
def __init__(self, canvas = None): ShapeEvtHandler.__init__(self) self._eventHandler = self self.SetShape(self) self._id = 0 self._formatted = False self._canvas = canvas self._xpos = 0.0 self._ypos = 0.0 self._pen = wx.Pen(wx.BLACK, 1, wx.SOLID) self._brush = wx.WHITE_BRUSH self._font = wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL) self._textColour = wx.BLACK self._textColourName = wx.BLACK self._visible = False self._selected = False self._attachmentMode = ATTACHMENT_MODE_NONE self._spaceAttachments = True self._disableLabel = False self._fixedWidth = False self._fixedHeight = False self._drawHandles = True self._sensitivity = OP_ALL self._draggable = True self._parent = None self._formatMode = FORMAT_CENTRE_HORIZ | FORMAT_CENTRE_VERT self._shadowMode = SHADOW_NONE self._shadowOffsetX = 6 self._shadowOffsetY = 6 self._shadowBrush = wx.BLACK_BRUSH self._textMarginX = 5 self._textMarginY = 5 self._regionName = "0" self._centreResize = True self._maintainAspectRatio = False self._highlighted = False self._rotation = 0.0 self._branchNeckLength = 10 self._branchStemLength = 10 self._branchSpacing = 10 self._branchStyle = BRANCHING_ATTACHMENT_NORMAL self._regions = [] self._lines = [] self._controlPoints = [] self._attachmentPoints = [] self._text = [] self._children = [] # Set up a default region. Much of the above will be put into # the region eventually (the duplication is for compatibility) region = ShapeRegion() region.SetName("0") region.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL)) region.SetFormatMode(FORMAT_CENTRE_HORIZ | FORMAT_CENTRE_VERT) region.SetColour("BLACK") self._regions.append(region)
self._font = wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL)
self._font = NormalFont
def __init__(self, canvas = None): ShapeEvtHandler.__init__(self) self._eventHandler = self self.SetShape(self) self._id = 0 self._formatted = False self._canvas = canvas self._xpos = 0.0 self._ypos = 0.0 self._pen = wx.Pen(wx.BLACK, 1, wx.SOLID) self._brush = wx.WHITE_BRUSH self._font = wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL) self._textColour = wx.BLACK self._textColourName = wx.BLACK self._visible = False self._selected = False self._attachmentMode = ATTACHMENT_MODE_NONE self._spaceAttachments = True self._disableLabel = False self._fixedWidth = False self._fixedHeight = False self._drawHandles = True self._sensitivity = OP_ALL self._draggable = True self._parent = None self._formatMode = FORMAT_CENTRE_HORIZ | FORMAT_CENTRE_VERT self._shadowMode = SHADOW_NONE self._shadowOffsetX = 6 self._shadowOffsetY = 6 self._shadowBrush = wx.BLACK_BRUSH self._textMarginX = 5 self._textMarginY = 5 self._regionName = "0" self._centreResize = True self._maintainAspectRatio = False self._highlighted = False self._rotation = 0.0 self._branchNeckLength = 10 self._branchStemLength = 10 self._branchSpacing = 10 self._branchStyle = BRANCHING_ATTACHMENT_NORMAL self._regions = [] self._lines = [] self._controlPoints = [] self._attachmentPoints = [] self._text = [] self._children = [] # Set up a default region. Much of the above will be put into # the region eventually (the duplication is for compatibility) region = ShapeRegion() region.SetName("0") region.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL)) region.SetFormatMode(FORMAT_CENTRE_HORIZ | FORMAT_CENTRE_VERT) region.SetColour("BLACK") self._regions.append(region)
region.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL))
region.SetFont(NormalFont)
def __init__(self, canvas = None): ShapeEvtHandler.__init__(self) self._eventHandler = self self.SetShape(self) self._id = 0 self._formatted = False self._canvas = canvas self._xpos = 0.0 self._ypos = 0.0 self._pen = wx.Pen(wx.BLACK, 1, wx.SOLID) self._brush = wx.WHITE_BRUSH self._font = wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL) self._textColour = wx.BLACK self._textColourName = wx.BLACK self._visible = False self._selected = False self._attachmentMode = ATTACHMENT_MODE_NONE self._spaceAttachments = True self._disableLabel = False self._fixedWidth = False self._fixedHeight = False self._drawHandles = True self._sensitivity = OP_ALL self._draggable = True self._parent = None self._formatMode = FORMAT_CENTRE_HORIZ | FORMAT_CENTRE_VERT self._shadowMode = SHADOW_NONE self._shadowOffsetX = 6 self._shadowOffsetY = 6 self._shadowBrush = wx.BLACK_BRUSH self._textMarginX = 5 self._textMarginY = 5 self._regionName = "0" self._centreResize = True self._maintainAspectRatio = False self._highlighted = False self._rotation = 0.0 self._branchNeckLength = 10 self._branchStemLength = 10 self._branchSpacing = 10 self._branchStyle = BRANCHING_ATTACHMENT_NORMAL self._regions = [] self._lines = [] self._controlPoints = [] self._attachmentPoints = [] self._text = [] self._children = [] # Set up a default region. Much of the above will be put into # the region eventually (the duplication is for compatibility) region = ShapeRegion() region.SetName("0") region.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL)) region.SetFormatMode(FORMAT_CENTRE_HORIZ | FORMAT_CENTRE_VERT) region.SetColour("BLACK") self._regions.append(region)
if '-D__WXDEBUG__' in cflags: gl_libs = ['wx_gtkd_gl', 'GL', 'GLU'] else: gl_libs = ['wx_gtk_gl', 'GL', 'GLU']
gl_libs = os.popen(WX_CONFIG + ' --gl-libs', 'r').read()[:-1] gl_libs = string.split(gl_libs)
def opj(*args): path = apply(os.path.join, args) return os.path.normpath(path)
libraries = libs + gl_libs, extra_compile_args = cflags, extra_link_args = lflags,
libraries = libs, extra_compile_args = cflags, extra_link_args = gl_libs + lflags,
def opj(*args): path = apply(os.path.join, args) return os.path.normpath(path)
self.resizeCloumn(self, minWidth)
self.resizeColumn(self, minWidth)
def resizeLastColumn(self, minWidth): """ Resize the last column appropriately.
new_vs_x = cpos.x / sppu_x
new_vs_x = vs_x + (cpos.x / sppu_x)
def OnChildFocus(self, evt): # If the child window that gets the focus is not visible, # this handler will try to scroll enough to see it. evt.Skip() child = evt.GetWindow()
new_vs_y = cpos.y / sppu_y
new_vs_y = vs_y + (cpos.y / sppu_y)
def OnChildFocus(self, evt): # If the child window that gets the focus is not visible, # this handler will try to scroll enough to see it. evt.Skip() child = evt.GetWindow()
self.SetBackgroundColour(self._bc)
if wx.Platform != "__WXMAC__": self.SetBackgroundColour(self._bc)
def createDialog( self, parent, id, pos, size, style ): """Setup the graphic representation of the dialog""" wx.Panel.__init__ (self, parent, id, pos, size, style) self.SetMinSize(size) # play nice with sizers
self.EnsureVisible(line)
self.GotoLine(line)
def ShowPosition(self, pos): line = self.LineFromPosition(pos) self.EnsureVisible(line)
self.SetViewEOL(False)
self.SetEOLMode(wx.stc.STC_EOL_LF) self.SetViewEOL(False)
def SetUpEditor(self): """ This method carries out the work of setting up the demo editor. It's seperate so as not to clutter up the init code. """ import keyword self.SetLexer(stc.STC_LEX_PYTHON) self.SetKeyWords(0, " ".join(keyword.kwlist))
f = open(modifiedFilename, "w")
f = open(modifiedFilename, "wt")
def OnSave(self, event): if self.demoModules.Exists(modModified): if self.demoModules.GetActiveID() == modOriginal: overwriteMsg = "You are about to overwrite an already existing modified copy\n" + \ "Do you want to continue?" dlg = wx.MessageDialog(self, overwriteMsg, "wxPython Demo", wx.YES_NO | wx.NO_DEFAULT| wx.ICON_EXCLAMATION) result = dlg.ShowModal() if result == wx.ID_NO: return dlg.Destroy() self.demoModules.SetActive(modModified) modifiedFilename = GetModifiedFilename(self.demoModules.name)
file = open(filename, "r")
file = open(filename, "rt")
def LoadFromFile(self, modID, filename): self.modules[modID][2] = filename file = open(filename, "r") self.LoadFromSource(modID, file.read()) file.close()
file = open(filename, "w")
file = open(filename, "wt")
def UpdateFile(self, modID = None): """Updates the file from which a module was loaded with (possibly updated) source""" if modID is None: modID = self.modActive
helpID = wx.NewId() findID = wx.NewId() findnextID = wx.NewId()
def EmptyHandler(evt): pass
prevSelect = self.UpdateNotebook()
def RunModule(self): """Runs the active module"""
self.UpdateNotebook()
self.UpdateNotebook(prevSelect)
def RunModule(self): """Runs the active module"""
if select >= 0:
if select >= 0 and select < nb.GetPageCount():
def UpdatePage(page, pageText): pageExists = False pagePos = -1 for i in range(nb.GetPageCount()): if nb.GetPageText(i) == pageText: pageExists = True pagePos = i break if page: if not pageExists: # Add a new page
dc.SetPen(wx.Pen(wx.NamedColour(colour), int(width), style))
pen = wx.Pen(wx.NamedColour(colour), width, style) pen.SetCap(wx.CAP_BUTT) dc.SetPen(pen)
def draw(self, dc, printerScale, coord= None): colour = self.attributes['colour'] width = self.attributes['width'] * printerScale style= self.attributes['style'] dc.SetPen(wx.Pen(wx.NamedColour(colour), int(width), style)) if coord == None: dc.DrawLines(self.scaled) else: dc.DrawLines(coord) # draw legend line
dc.SetPen(wx.Pen(wx.NamedColour(colour),int(width)))
dc.SetPen(wx.Pen(wx.NamedColour(colour), width))
def draw(self, dc, printerScale, coord= None): colour = self.attributes['colour'] width = self.attributes['width'] * printerScale size = self.attributes['size'] * printerScale fillcolour = self.attributes['fillcolour'] fillstyle = self.attributes['fillstyle'] marker = self.attributes['marker']
dc = FloatDCWrapper(wx.BufferedDC(wx.ClientDC(self), self._Buffer))
dc = wx.BufferedDC(wx.ClientDC(self), self._Buffer)
def Draw(self, graphics, xAxis = None, yAxis = None, dc = None): """Draw objects in graphics with specified x and y axis. graphics- instance of PlotGraphics with list of PolyXXX objects xAxis - tuple with (min, max) axis range to view yAxis - same as xAxis dc - drawing context - doesn't have to be specified. If it's not, the offscreen buffer is used """ # check Axis is either tuple or none if type(xAxis) not in [type(None),tuple]: raise TypeError, "xAxis should be None or (minX,maxX)" if type(yAxis) not in [type(None),tuple]: raise TypeError, "yAxis should be None or (minY,maxY)" # check case for axis = (a,b) where a==b caused by improper zooms if xAxis != None: if xAxis[0] == xAxis[1]: return if yAxis != None: if yAxis[0] == yAxis[1]: return if dc == None: # allows using floats for certain functions dc = FloatDCWrapper(wx.BufferedDC(wx.ClientDC(self), self._Buffer)) dc.Clear() dc.BeginDrawing() # dc.Clear() # set font size for every thing but title and legend dc.SetFont(self._getFont(self._fontSizeAxis))
return int(ptx),int(pty),int(rectWidth),int(rectHeight)
return ptx, pty, rectWidth, rectHeight
def _point2ClientCoord(self, corner1, corner2): """Converts user point coords to client screen int coords x,y,width,height""" c1= Numeric.array(corner1) c2= Numeric.array(corner2) # convert to screen coords pt1= c1*self._pointScale+self._pointShift pt2= c2*self._pointScale+self._pointShift # make height and width positive pul= Numeric.minimum(pt1,pt2) # Upper left corner plr= Numeric.maximum(pt1,pt2) # Lower right corner rectWidth, rectHeight= plr-pul ptx,pty= pul return int(ptx),int(pty),int(rectWidth),int(rectHeight) # return ints
dc.SetPen(wx.Pen(wx.NamedColour('BLACK'),int(penWidth)))
dc.SetPen(wx.Pen(wx.NamedColour('BLACK'), penWidth))
def _drawAxes(self, dc, p1, p2, scale, shift, xticks, yticks): penWidth= self.printerScale # increases thickness for printing only dc.SetPen(wx.Pen(wx.NamedColour('BLACK'),int(penWidth))) # set length of tick marks--long ones make grid if self._gridEnabled: x,y,width,height= self._point2ClientCoord(p1,p2) yTickLength= width/2.0 +1 xTickLength= height/2.0 +1 else: yTickLength= 3 * self.printerScale # lengthens lines for printing xTickLength= 3 * self.printerScale if self._xSpec is not 'none': lower, upper = p1[0],p2[0] text = 1 for y, d in [(p1[1], -xTickLength), (p2[1], xTickLength)]: # miny, maxy and tick lengths a1 = scale*Numeric.array([lower, y])+shift a2 = scale*Numeric.array([upper, y])+shift dc.DrawLine(a1[0],a1[1],a2[0],a2[1]) # draws upper and lower axis line for x, label in xticks: pt = scale*Numeric.array([x, y])+shift dc.DrawLine(pt[0],pt[1],pt[0],pt[1] + d) # draws tick mark d units if text: dc.DrawText(label,pt[0],pt[1]) text = 0 # axis values not drawn on top side
dc = FloatDCWrapper(self.GetDC())
dc = self.GetDC()
def OnPrintPage(self, page): dc = FloatDCWrapper(self.GetDC()) # allows using floats for certain functions
class FloatDCWrapper: def __init__(self, aDC): self.theDC = aDC def DrawLine(self, x1,y1,x2,y2): self.theDC.DrawLine(int(x1),int(y1), int(x2),int(y2)) def DrawText(self, txt, x, y): self.theDC.DrawText(txt, int(x), int(y)) def DrawRotatedText(self, txt, x, y, angle): self.theDC.DrawRotatedText(txt, int(x), int(y), angle) def SetClippingRegion(self, x, y, width, height): self.theDC.SetClippingRegion(int(x), int(y), int(width), int(height)) def SetDeviceOrigin(self, x, y): self.theDC.SetDeviceOrigin(int(x), int(y)) def __getattr__(self, name): return getattr(self.theDC, name)
def OnPrintPage(self, page): dc = FloatDCWrapper(self.GetDC()) # allows using floats for certain functions
elif pt._type == CONTROL_POINT_DIAGONAL and (keys & KEYS or self.GetMaintainAspectRatio()):
elif pt._type == CONTROL_POINT_DIAGONAL and (keys & KEY_SHIFT or self.GetMaintainAspectRatio()):
def OnSizingBeginDragLeft(self, pt, x, y, keys = 0, attachment = 0): self._canvas.CaptureMouse()
self.rowHeights = [] self.colWidths = []
def CalcMin( self ): items = self.GetChildren() if not items: return wxSize(10, 10)
return (0, 1, 1, 1)
return (1, 1, 1, 1)
def GetPageInfo(self): return (0, 1, 1, 1) # disable page numbers
ext = ft.GetExtensions()[0] if ext[0] == ".": ext = ext[1:]
extList = ft.GetExtensions() if extList: ext = extList[0] if ext[0] == ".": ext = ext[1:] else: ext = ""
def Update(self, ft): #icon = ft.GetIcon() info = ft.GetIconInfo() if info is None: bmp = MyBitmapsFunc(0) ##print bmp.Ok(), bmp.GetWidth(), bmp.GetHeight() self.GetIconBmp().SetBitmap(bmp) self.GetIconFileTxt().SetValue("") self.GetIconIndexTxt().SetValue("") else: icon, file, idx = info #bmp = wxBitmapFromIcon(icon) #self.GetIconBmp().SetBitmap(bmp) self.GetIconBmp().SetIcon(icon) self.GetIconFileTxt().SetValue(file) self.GetIconIndexTxt().SetValue(str(idx))
wx.wxButton(dlg, wx.ID_OK, "Find Next", (280, 5), wx.DefaultSize).SetDefault() wx.wxButton(dlg, wx.ID_CANCEL, "Cancel", (280, 35), wx.DefaultSize)
wx.Button(dlg, wx.ID_OK, "Find Next", (280, 5), wx.DefaultSize).SetDefault() wx.Button(dlg, wx.ID_CANCEL, "Cancel", (280, 35), wx.DefaultSize)
def findDialog(parent=None, searchText='', wholeWordsOnly=0, caseSensitive=0): dlg = wx.Dialog(parent, -1, "Find", wx.DefaultPosition, (370, 120)) wx.StaticText(dlg, -1, 'Find what:', (7, 10)) wSearchText = wx.TextCtrl(dlg, -1, searchText, (70, 7), (195, -1)) wSearchText.SetValue(searchText) wx.wxButton(dlg, wx.ID_OK, "Find Next", (280, 5), wx.DefaultSize).SetDefault() wx.wxButton(dlg, wx.ID_CANCEL, "Cancel", (280, 35), wx.DefaultSize) wWholeWord = wx.CheckBox(dlg, -1, 'Match whole word only', (7, 35), wx.DefaultSize, wx.NO_BORDER) if wholeWordsOnly: wWholeWord.SetValue(1) wCase = wx.CheckBox(dlg, -1, 'Match case', (7, 55), wx.DefaultSize, wx.NO_BORDER) if caseSensitive: wCase.SetValue(1) wSearchText.SetSelection(0, len(wSearchText.GetValue())) wSearchText.SetFocus() result = DialogResults(dlg.ShowModal()) result.text = wSearchText.GetValue() result.wholeword = wWholeWord.GetValue() result.casesensitive = wCase.GetValue() dlg.Destroy() return result
frame = wx.Frame(None, -1, "Dialogs", size=(400, 200))
self.frame = frame = wx.Frame(None, -1, "Dialogs", size=(400, 200))
def OnInit(self): frame = wx.Frame(None, -1, "Dialogs", size=(400, 200)) panel = wx.Panel(frame, -1) self.panel = panel
frame.Show(1)
def OnInit(self): frame = wx.Frame(None, -1, "Dialogs", size=(400, 200)) panel = wx.Panel(frame, -1) self.panel = panel
self.nameList = wx.ListBox(panel, -1, (0, 0), (130, 180), dialogNames, style=wx.LB_SINGLE) self.Bind(wx.EVT_LISTBOX, self.OnNameListSelected, id=self.nameList.GetId())
self.nameList = wx.ListBox(panel, -1, size=(130, 180), choices=dialogNames, style=wx.LB_SINGLE) self.Bind(wx.EVT_LISTBOX, self.OnNameListSelected, self.nameList)
def OnInit(self): frame = wx.Frame(None, -1, "Dialogs", size=(400, 200)) panel = wx.Panel(frame, -1) self.panel = panel
self.text1 = wx.TextCtrl(panel, -1, pos=(150, 0), size=(200, 180), style=tstyle)
self.text1 = wx.TextCtrl(panel, -1, size=(200, 180), style=tstyle) sizer = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(self.nameList, 0, wx.EXPAND|wx.ALL, 20) sizer.Add(self.text1, 1, wx.EXPAND|wx.ALL, 20) panel.SetSizer(sizer)
def OnInit(self): frame = wx.Frame(None, -1, "Dialogs", size=(400, 200)) panel = wx.Panel(frame, -1) self.panel = panel
frame.Show(1)
def OnInit(self): frame = wx.Frame(None, -1, "Dialogs", size=(400, 200)) panel = wx.Panel(frame, -1) self.panel = panel
'A Message Box', wx.wxOK | wx.wxICON_INFORMATION)
'A Message Box', wx.OK | wx.ICON_INFORMATION)
def OnNameListSelected(self, evt): import pprint sel = evt.GetString() result = None if sel == 'alertDialog': result = alertDialog(message='Danger Will Robinson') elif sel == 'colorDialog': result = colorDialog() elif sel == 'directoryDialog': result = directoryDialog() elif sel == 'fileDialog': wildcard = "JPG files (*.jpg;*.jpeg)|*.jpeg;*.JPG;*.JPEG;*.jpg|GIF files (*.gif)|*.GIF;*.gif|All Files (*.*)|*.*" result = fileDialog(None, 'Open', '', '', wildcard) elif sel == 'findDialog': result = findDialog() elif sel == 'fontDialog': result = fontDialog() elif sel == 'messageDialog': result = messageDialog(None, 'Hello from Python and wxPython!', 'A Message Box', wx.wxOK | wx.wxICON_INFORMATION) #wx.wxYES_NO | wx.wxNO_DEFAULT | wx.wxCANCEL | wx.wxICON_INFORMATION) #result = messageDialog(None, 'message', 'title') elif sel == 'multipleChoiceDialog': result = multipleChoiceDialog(None, "message", "title", ['one', 'two', 'three']) elif sel == 'openFileDialog': result = openFileDialog() elif sel == 'saveFileDialog': result = saveFileDialog() elif sel == 'scrolledMessageDialog': msg = "Can't find the file dialog.py" try: # read this source file and then display it import sys filename = sys.argv[-1] fp = open(filename) message = fp.read() fp.close() except: pass result = scrolledMessageDialog(None, message, filename) elif sel == 'singleChoiceDialog': result = singleChoiceDialog(None, "message", "title", ['one', 'two', 'three']) elif sel == 'textEntryDialog': result = textEntryDialog(None, "message", "title", "text")
def CreateView(self, document, flags=0):
def CreateView(self, doc, flags=0):
def CreateView(self, document, flags=0): """ Creates a new view for the given document. If more than one view is allowed for the document (by virtue of multiple templates mentioning the same document type), a choice of view is presented to the user. """ templates = [] for temp in self._templates: if temp.IsVisible(): if temp.GetDocumentName() == doc.GetDocumentName(): templates.append(temp) if len(templates) == 0: return None
if os.path.exists("splash.png"): self.ShowSplash("splash.png")
if os.path.exists(TextEditorApplication.SPLASH): self.ShowSplash(TextEditorApplication.SPLASH)
def OnInit(self): # Call the super - this is important!!! pydocview.DocApp.OnInit(self)
if os.path.exists("splash.jpg"): aboutService = self.InstallService(pydocview.AboutService(image=wx.Image("splash.jpg")))
if os.path.exists(TextEditorApplication.SPLASH): aboutService = self.InstallService(pydocview.AboutService(image=wx.Image(TextEditorApplication.SPLASH)))
def OnInit(self): # Call the super - this is important!!! pydocview.DocApp.OnInit(self)
if os.path.exists("splash.jpg"):
if os.path.exists(TextEditorApplication.SPLASH):
def OnInit(self): # Call the super - this is important!!! pydocview.DocApp.OnInit(self)
In addition to the usual arguments, wxFloatBar accepts keyword args of: title(string): the title that should appear on the toolbar's frame when it is floating. floatable(bool): whether user actions (i.e., dragging) can float the toolbar or not.
wxToolBar subclass which can be dragged off its frame and later replaced there. Drag on the toolbar to release it, close it like a normal window to make it return to its original position. Programmatically, call SetFloatable(true) and then Float(true) to float, Float(false) to dock.
def __init__(self,*_args,**_kwargs): """ In addition to the usual arguments, wxFloatBar accepts keyword args of: title(string): the title that should appear on the toolbar's frame when it is floating. floatable(bool): whether user actions (i.e., dragging) can float the toolbar or not. """ args = (self,) + _args apply(wxToolBar.__init__, args, _kwargs) if _kwargs.has_key('floatable'): self.floatable = _kwargs['floatable'] assert type(self.floatable) == type(0) else: self.floatable = 0 self.floating = 0 if _kwargs.has_key('title'): self.title = _kwargs['title'] assert type(self.title) == type("") else: self.title = "" EVT_MOUSE_EVENTS(self, self.OnMouse) self.parentframe = wxPyTypeCast(args[1], 'wxFrame')
args = (self,) + _args apply(wxToolBar.__init__, args, _kwargs) if _kwargs.has_key('floatable'): self.floatable = _kwargs['floatable'] assert type(self.floatable) == type(0) else: self.floatable = 0 self.floating = 0 if _kwargs.has_key('title'): self.title = _kwargs['title'] assert type(self.title) == type("") else: self.title = "" EVT_MOUSE_EVENTS(self, self.OnMouse) self.parentframe = wxPyTypeCast(args[1], 'wxFrame') def IsFloatable(self): return self.floatable def SetFloatable(self, float): self.floatable = float if not hasattr(self, 'titleheight'): test = wxMiniFrame(NULL, -1, "TEST") test.SetClientSize(wxSize(0,0)) self.titleheight = test.GetSizeTuple()[1] test.Destroy() def IsFloating(self): return self.floating def Realize(self): wxToolBar.Realize(self) def GetTitle(self): return self.title def SetTitle(self, title): print 'SetTitle', title self.title = title if self.IsFloating(): self.floatframe.SetTitle(self.title) def Float(self, bool): "Floats or docks the toolbar programmatically." if bool: self.parentframe = wxPyTypeCast(self.GetParent(), 'wxFrame') print self.title if self.title: useStyle = wxDEFAULT_FRAME_STYLE else: useStyle = wxTHICK_FRAME self.floatframe = wxFrame(self.parentframe, -1, self.title, style = useStyle) self.Reparent(self.floatframe) self.parentframe.SetToolBar(None) self.floating = 1 psize = self.parentframe.GetSize() self.parentframe.SetSize(wxSize(0,0)) self.parentframe.SetSize(psize) self.floatframe.SetToolBar(self) self.oldcolor = self.GetBackgroundColour() w = psize.width h = self.GetSize().height if self.title: h = h + self.titleheight self.floatframe.SetSize(wxSize(w,h)) self.floatframe.SetClientSize(self.GetSize()) newpos = self.parentframe.GetPosition() newpos.y = newpos.y + _DOCKTHRESHOLD * 2 self.floatframe.SetPosition(newpos) self.floatframe.Show(true) EVT_CLOSE(self.floatframe, self.OnDock) else: self.Reparent(self.parentframe) self.parentframe.SetToolBar(self)
def __init__(self,*_args,**_kwargs): """ In addition to the usual arguments, wxFloatBar accepts keyword args of: title(string): the title that should appear on the toolbar's frame when it is floating. floatable(bool): whether user actions (i.e., dragging) can float the toolbar or not. """ args = (self,) + _args apply(wxToolBar.__init__, args, _kwargs) if _kwargs.has_key('floatable'): self.floatable = _kwargs['floatable'] assert type(self.floatable) == type(0) else: self.floatable = 0
def __init__(self,*_args,**_kwargs): """ In addition to the usual arguments, wxFloatBar accepts keyword args of: title(string): the title that should appear on the toolbar's frame when it is floating. floatable(bool): whether user actions (i.e., dragging) can float the toolbar or not. """ args = (self,) + _args apply(wxToolBar.__init__, args, _kwargs) if _kwargs.has_key('floatable'): self.floatable = _kwargs['floatable'] assert type(self.floatable) == type(0) else: self.floatable = 0 self.floating = 0 if _kwargs.has_key('title'): self.title = _kwargs['title'] assert type(self.title) == type("") else: self.title = "" EVT_MOUSE_EVENTS(self, self.OnMouse) self.parentframe = wxPyTypeCast(args[1], 'wxFrame')
self.floatframe.SetToolBar(None) self.floatframe.Destroy() size = self.parentframe.GetSize() self.parentframe.SetSize(wxSize(0,0)) self.parentframe.SetSize(size) self.SetBackgroundColour(self.oldcolor) def OnDock(self, e): self.Float(0) if hasattr(self, 'oldpos'): del self.oldpos def OnMove(self, e): homepos = self.parentframe.ClientToScreen(wxPoint(0,0)) floatpos = self.floatframe.GetPosition() if (abs(homepos.x - floatpos.x) < _DOCKTHRESHOLD and abs(homepos.y - floatpos.y) < _DOCKTHRESHOLD): self.Float(0) def OnMouse(self, e): if not self.IsFloatable(): e.Skip() return if e.ButtonDClick(1) or e.ButtonDClick(2) or e.ButtonDClick(3) or e.ButtonDown() or e.ButtonUp(): e.Skip() if e.ButtonDown(): self.CaptureMouse() self.oldpos = (e.GetX(), e.GetY()) if e.Entering(): self.oldpos = (e.GetX(), e.GetY()) if e.ButtonUp(): self.ReleaseMouse()
if _kwargs.has_key('title'): self.title = _kwargs['title'] assert type(self.title) == type("") else: self.title = "" EVT_MOUSE_EVENTS(self, self.OnMouse) self.parentframe = wxPyTypeCast(args[1], 'wxFrame') def IsFloatable(self): return self.floatable def SetFloatable(self, float): self.floatable = float if not hasattr(self, 'titleheight'): test = wxMiniFrame(NULL, -1, "TEST") test.SetClientSize(wxSize(0,0)) self.titleheight = test.GetSizeTuple()[1] test.Destroy() def IsFloating(self): return self.floating def Realize(self): wxToolBar.Realize(self) def GetTitle(self): return self.title def SetTitle(self, title): print 'SetTitle', title self.title = title
def Float(self, bool): "Floats or docks the toolbar programmatically." if bool: self.parentframe = wxPyTypeCast(self.GetParent(), 'wxFrame') print self.title if self.title: useStyle = wxDEFAULT_FRAME_STYLE else: useStyle = wxTHICK_FRAME self.floatframe = wxFrame(self.parentframe, -1, self.title, style = useStyle)
homepos = self.parentframe.ClientToScreen(wxPoint(0,0)) floatpos = self.floatframe.GetPosition() if (abs(homepos.x - floatpos.x) < _DOCKTHRESHOLD and abs(homepos.y - floatpos.y) < _DOCKTHRESHOLD): self.Float(0) return if e.Dragging(): if not self.IsFloating(): self.Float(true) self.oldpos = (e.GetX(), e.GetY()) else: if hasattr(self, 'oldpos'): loc = self.floatframe.GetPosition() pt = wxPoint(loc.x - (self.oldpos[0]-e.GetX()), loc.y - (self.oldpos[1]-e.GetY())) self.floatframe.Move(pt) def _SetFauxBarVisible(self, vis): return if vis: if self.parentframe.GetToolBar() == None: if not hasattr(self, 'nullbar'): self.nullbar = wxToolBar(self.parentframe, -1) print "Adding fauxbar." self.nullbar.Reparent(self.parentframe) print "Reparented." self.parentframe.SetToolBar(self.nullbar) print "Set toolbar" col = wxNamedColour("GREY") self.nullbar.SetBackgroundColour(col) print "Set color"
self.floatframe.SetTitle(self.title) def Float(self, bool): "Floats or docks the toolbar programmatically." if bool: self.parentframe = wxPyTypeCast(self.GetParent(), 'wxFrame') print self.title if self.title: useStyle = wxDEFAULT_FRAME_STYLE else: useStyle = wxTHICK_FRAME self.floatframe = wxFrame(self.parentframe, -1, self.title, style = useStyle) self.Reparent(self.floatframe) self.parentframe.SetToolBar(None) self.floating = 1 psize = self.parentframe.GetSize() self.parentframe.SetSize(wxSize(0,0)) self.parentframe.SetSize(psize) self.floatframe.SetToolBar(self) self.oldcolor = self.GetBackgroundColour() w = psize.width h = self.GetSize().height if self.title: h = h + self.titleheight self.floatframe.SetSize(wxSize(w,h)) self.floatframe.SetClientSize(self.GetSize()) newpos = self.parentframe.GetPosition() newpos.y = newpos.y + _DOCKTHRESHOLD * 2 self.floatframe.SetPosition(newpos) self.floatframe.Show(true) EVT_CLOSE(self.floatframe, self.OnDock) else: self.Reparent(self.parentframe) self.parentframe.SetToolBar(self) self.floating = 0 self.floatframe.SetToolBar(None) self.floatframe.Destroy()
def OnMouse(self, e): if not self.IsFloatable(): e.Skip() return
print "Set size" else: print self.parentframe.GetToolBar() else: if self.parentframe.GetToolBar() != None: print "Removing fauxbar" self.nullbar.Reparent(self.floatframe) self.parentframe.SetToolBar(None) size = self.parentframe.GetSize() self.parentframe.SetSize(wxSize(0,0)) self.parentframe.SetSize(size)
self.SetBackgroundColour(self.oldcolor) def OnDock(self, e): self.Float(0) if hasattr(self, 'oldpos'): del self.oldpos def OnMove(self, e): homepos = self.parentframe.ClientToScreen(wxPoint(0,0)) floatpos = self.floatframe.GetPosition() if (abs(homepos.x - floatpos.x) < _DOCKTHRESHOLD and abs(homepos.y - floatpos.y) < _DOCKTHRESHOLD): self.Float(0) def OnMouse(self, e): if not self.IsFloatable(): e.Skip() return if e.ButtonDClick(1) or e.ButtonDClick(2) or e.ButtonDClick(3) or e.ButtonDown() or e.ButtonUp(): e.Skip() if e.ButtonDown(): self.CaptureMouse() self.oldpos = (e.GetX(), e.GetY()) if e.Entering(): self.oldpos = (e.GetX(), e.GetY()) if e.ButtonUp(): self.ReleaseMouse() if self.IsFloating(): homepos = self.parentframe.ClientToScreen(wxPoint(0,0)) floatpos = self.floatframe.GetPosition() if (abs(homepos.x - floatpos.x) < _DOCKTHRESHOLD and abs(homepos.y - floatpos.y) < _DOCKTHRESHOLD): self.Float(0) return if e.Dragging(): if not self.IsFloating(): self.Float(true) self.oldpos = (e.GetX(), e.GetY()) else: if hasattr(self, 'oldpos'): loc = self.floatframe.GetPosition() pt = wxPoint(loc.x - (self.oldpos[0]-e.GetX()), loc.y - (self.oldpos[1]-e.GetY())) self.floatframe.Move(pt) def _SetFauxBarVisible(self, vis): return if vis: if self.parentframe.GetToolBar() == None: if not hasattr(self, 'nullbar'): self.nullbar = wxToolBar(self.parentframe, -1) print "Adding fauxbar." self.nullbar.Reparent(self.parentframe) print "Reparented." self.parentframe.SetToolBar(self.nullbar) print "Set toolbar" col = wxNamedColour("GREY") self.nullbar.SetBackgroundColour(col) print "Set color" size = self.parentframe.GetSize() self.parentframe.SetSize(wxSize(0,0)) self.parentframe.SetSize(size) print "Set size" else: print self.parentframe.GetToolBar() else: if self.parentframe.GetToolBar() != None: print "Removing fauxbar" self.nullbar.Reparent(self.floatframe) self.parentframe.SetToolBar(None) size = self.parentframe.GetSize() self.parentframe.SetSize(wxSize(0,0)) self.parentframe.SetSize(size)
def _SetFauxBarVisible(self, vis): return if vis: if self.parentframe.GetToolBar() == None: if not hasattr(self, 'nullbar'): self.nullbar = wxToolBar(self.parentframe, -1) print "Adding fauxbar." self.nullbar.Reparent(self.parentframe) print "Reparented." self.parentframe.SetToolBar(self.nullbar) print "Set toolbar" col = wxNamedColour("GREY") self.nullbar.SetBackgroundColour(col) print "Set color" size = self.parentframe.GetSize() self.parentframe.SetSize(wxSize(0,0)) self.parentframe.SetSize(size) print "Set size" else: print self.parentframe.GetToolBar() else: if self.parentframe.GetToolBar() != None: print "Removing fauxbar" self.nullbar.Reparent(self.floatframe) self.parentframe.SetToolBar(None) size = self.parentframe.GetSize() self.parentframe.SetSize(wxSize(0,0)) self.parentframe.SetSize(size)
bottomPanel.SetOwnBackroundColour("light blue")
bottomPanel.SetOwnBackgroundColour("light blue")
def __init__(self): wx.Frame.__init__(self, None, -1, "Widget Layout Tester")
self.testPanel.SetOwnBackroundColour((205, 183, 181))
self.testPanel.SetOwnBackgroundColour((205, 183, 181))
def __init__(self): wx.Frame.__init__(self, None, -1, "Widget Layout Tester")
class BasePopupFrame(wx.MiniFrame):
class BasePopupFrame(wx.Frame):
def GetSelection(self): """ Extend GetSelection to never return the root item if the root item is hidden. """ selection = super(IterableTreeCtrl, self).GetSelection() if selection == self.GetRootItem() and \ (self.GetWindowStyle() & wx.TR_HIDE_ROOT): return wx.TreeItemId() # Return an invalid TreeItemId else: return selection
fucntions, in order to reduce the clutter in the API docs.
functions, in order to reduce the clutter in the API docs.
def Notify(self): """ The timer has expired so call the callable. """ if self.callable and getattr(self.callable, 'im_self', True): self.runCount += 1 self.running = False self.result = self.callable(*self.args, **self.kwargs) self.hasRun = True if not self.running: # if it wasn't restarted, then cleanup wx.CallAfter(self.Stop)
self.printData.SetPrintMode(wx.PRINT_MODE_PRINTER)
def __init__(self, parent, frame, log): wx.Panel.__init__(self, parent, -1) self.log = log self.frame = frame
self.Bind(wx.EVT_BUTTON, self.OnPrintSetup, id=ID_Setup)
self.Bind(wx.EVT_BUTTON, self.OnPrintSetup, btn)
def __init__(self, parent, frame, log): wx.Panel.__init__(self, parent, -1) self.log = log self.frame = frame
self.Bind(wx.EVT_BUTTON, self.OnPrintPreview, id=ID_Preview)
self.Bind(wx.EVT_BUTTON, self.OnPrintPreview, btn)
def __init__(self, parent, frame, log): wx.Panel.__init__(self, parent, -1) self.log = log self.frame = frame
self.Bind(wx.EVT_BUTTON, self.OnDoPrint, id=ID_Print)
self.Bind(wx.EVT_BUTTON, self.OnDoPrint, btn)
def __init__(self, parent, frame, log): wx.Panel.__init__(self, parent, -1) self.log = log self.frame = frame
printerDialog = wx.PrintDialog(self) printerDialog.GetPrintDialogData().SetPrintData(self.printData)
data = wx.PrintDialogData(self.printData) printerDialog = wx.PrintDialog(self, data)
def OnPrintSetup(self, event): printerDialog = wx.PrintDialog(self) printerDialog.GetPrintDialogData().SetPrintData(self.printData) printerDialog.GetPrintDialogData().SetSetupDialog(True) printerDialog.ShowModal(); self.printData = printerDialog.GetPrintDialogData().GetPrintData() printerDialog.Destroy()
self.preview = wx.PrintPreview(printout, printout2, self.printData)
self.preview = wx.PrintPreview(printout, printout2, data)
def OnPrintPreview(self, event): self.log.WriteText("OnPrintPreview\n") printout = MyPrintout(self.canvas, self.log) printout2 = MyPrintout(self.canvas, self.log) self.preview = wx.PrintPreview(printout, printout2, self.printData)
pdd = wx.PrintDialogData() pdd.SetPrintData(self.printData)
pdd = wx.PrintDialogData(self.printData) pdd.SetToPage(2)
def OnDoPrint(self, event): pdd = wx.PrintDialogData() pdd.SetPrintData(self.printData) printer = wx.Printer(pdd) printout = MyPrintout(self.canvas, self.log)
if not printer.Print(self.frame, printout):
if not printer.Print(self.frame, printout, True):
def OnDoPrint(self, event): pdd = wx.PrintDialogData() pdd.SetPrintData(self.printData) printer = wx.Printer(pdd) printout = MyPrintout(self.canvas, self.log)
changeCallback= lambda x:x
changeCallback= lambda x:x, labelWidth = 0
def __init__ (self, parent, id= -1, 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 ): """ :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 :param changeCallback: Optional callback called for all changes in value of the control """ # 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
self.labelWidth = labelWidth
def __init__ (self, parent, id= -1, 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 ): """ :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 :param changeCallback: Optional callback called for all changes in value of the control """ # 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
label.SetSize((w+5, h))
if self.labelWidth > 0: label.SetSize((self.labelWidth+5, h)) else: label.SetSize((w+5, h))
def createLabel( self ): """Create the label/caption""" 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)) return label
self.GetEventHandler().OnEndSize(bound_x, bound_y)
self.GetEventHandler().OnBeginSize(bound_x, bound_y)
def OnSizingBeginDragLeft(self, pt, x, y, keys = 0, attachment = 0): self._canvas.CaptureMouse()
H = ((y3 - y2) / (x32 - x2))
H = ((y3 - y2) / (x2 - x2))
def DrawArcToEllipse(x1, y1, width1, height1, x2, y2, x3, y3): a1 = width1 / 2 b1 = height1 / 2 # Check that x2 != x3 if abs(x2 - x3)<0.05: x4 = x2 if y3>y2: y4 = y1 - sqrt((b1 * b1 - (((x2 - x1) * (x2 - x1)) * (b1 * b1) / (a1 * a1)))) else: y4 = y1 + sqrt((b1 * b1 - (((x2 - x1) * (x2 - x1)) * (b1 * b1) / (a1 * a1)))) return x4, y4 # Calculate the x and y coordinates of the point where arc intersects ellipse A = (1 / (a1 * a1)) B = ((y3 - y2) * (y3 - y2)) / ((x3 - x2) * (x3 - x2) * b1 * b1) C = (2 * (y3 - y2) * (y2 - y1)) / ((x3 - x2) * b1 * b1) D = ((y2 - y1) * (y2 - y1)) / (b1 * b1) E = (A + B) F = (C - (2 * A * x1) - (2 * B * x2)) G = ((A * x1 * x1) + (B * x2 * x2) - (C * x2) + D - 1) H = ((y3 - y2) / (x32 - x2)) K = ((F * F) - (4 * E * G)) if K >= 0: # In this case the line intersects the ellipse, so calculate intersection if x2 >= x1: ellipse1_x = ((F*-1) + sqrt(K)) / (2 * E) ellipse1_y = ((H * (ellipse1_x - x2)) + y2) else: ellipse1_x = (((F*-1) - sqrt(K)) / (2 * E)) ellipse1_y = ((H * (ellipse1_x - x2)) + y2) else: # in this case, arc does not intersect ellipse, so just draw arc ellipse1_x = x3 ellipse1_y = y3 return ellipse1_x, ellipse1_y
buttonPanel.SetAutoLayout(1)
def __init__(self, parent, log): wx.Panel.__init__(self, parent, -1) self.log = log
self.SetAutoLayout(1)
def __init__(self, parent, log): wx.Panel.__init__(self, parent, -1) self.log = log
class Tile(wx.Panel):
class Tile(wx.Window):
def __init__(self, parent, log): wx.Panel.__init__(self, parent, -1) self.log = log
wx.Panel.__init__(self, parent, -1, size=size, style=wx.CLIP_CHILDREN)
wx.Window.__init__(self, parent, -1, size=size, style=wx.CLIP_CHILDREN)
def __init__(self, parent, log, factor=1, thingToWatch=None, bgColor=None, active=1, size=(38,38), borderWidth=3): wx.Panel.__init__(self, parent, -1, size=size, style=wx.CLIP_CHILDREN) self.tile = InnerTile(self, log, factor, thingToWatch, bgColor) self.log = log sizer = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(self.tile, 1, wx.EXPAND | wx.ALL, borderWidth) self.SetAutoLayout(1) self.SetSizer(sizer) self.Layout() self.SetBackgroundColour(Tile.normal) if active: # Register myself for mouse events over self.tile in order to # create typical button/hyperlink visual effects. em.eventManager.Register(self.setHover, wx.EVT_ENTER_WINDOW, self.tile) em.eventManager.Register(self.setNormal, wx.EVT_LEAVE_WINDOW, self.tile) em.eventManager.Register(self.setActive, wx.EVT_LEFT_DOWN, self.tile) em.eventManager.Register(self.setHover, wx.EVT_LEFT_UP, self.tile)
self.SetAutoLayout(1)
def __init__(self, parent, log, factor=1, thingToWatch=None, bgColor=None, active=1, size=(38,38), borderWidth=3): wx.Panel.__init__(self, parent, -1, size=size, style=wx.CLIP_CHILDREN) self.tile = InnerTile(self, log, factor, thingToWatch, bgColor) self.log = log sizer = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(self.tile, 1, wx.EXPAND | wx.ALL, borderWidth) self.SetAutoLayout(1) self.SetSizer(sizer) self.Layout() self.SetBackgroundColour(Tile.normal) if active: # Register myself for mouse events over self.tile in order to # create typical button/hyperlink visual effects. em.eventManager.Register(self.setHover, wx.EVT_ENTER_WINDOW, self.tile) em.eventManager.Register(self.setNormal, wx.EVT_LEAVE_WINDOW, self.tile) em.eventManager.Register(self.setActive, wx.EVT_LEFT_DOWN, self.tile) em.eventManager.Register(self.setHover, wx.EVT_LEFT_UP, self.tile)
class InnerTile(wx.Panel):
class InnerTile(wx.Window):
def setNormal(self, event): self.SetBackgroundColour(Tile.normal) self.Refresh()
wx.Panel.__init__(self, parent, -1)
wx.Window.__init__(self, parent, -1)
def __init__(self, parent, log, factor, thingToWatch=None, bgColor=None): wx.Panel.__init__(self, parent, -1) self.log=log if bgColor: self.SetBackgroundColour(bgColor) if thingToWatch: self.factor = factor self.thingToWatch = thingToWatch self.state = 0 self.toggleOnOff() # Watch for the mouse click to enable/disable myself. em.eventManager.Register(self.toggleOnOff, wx.EVT_LEFT_UP, self)
def __del__(self): if hasattr(self, "set_colour_val"): del self.set_colour_val
def __del__(self): if hasattr(self, "set_colour_val"): del self.set_colour_val
self.set_colour_val = wxColour(bcolour[0], bcolour[1], bcolour[2])
def SetColourValue(self, bcolour): self.set_colour_val = wxColour(bcolour[0], bcolour[1], bcolour[2]) self.set_colour = bcolour
self.SetBackgroundColour(self.set_colour_val)
self.SetBackgroundColour(self.Get_wxColour())
def SetColourValue(self, bcolour): self.set_colour_val = wxColour(bcolour[0], bcolour[1], bcolour[2]) self.set_colour = bcolour
return list( self.history )
return []
def GetHistory( self ): """Return the current history list""" if self.historyCallBack != None: return self.historyCallBack() else: return list( self.history )
result.text = wSearchText.GetValue() result.wholeword = wWholeWord.GetValue() result.casesensitive = wCase.GetValue()
result.searchText = wSearchText.GetValue() result.wholeWordsOnly = wWholeWord.GetValue() result.caseSensitive = wCase.GetValue()
def findDialog(parent=None, searchText='', wholeWordsOnly=0, caseSensitive=0): dlg = wx.Dialog(parent, -1, "Find", wx.DefaultPosition, (380, 120)) wx.StaticText(dlg, -1, 'Find what:', (7, 10)) wSearchText = wx.TextCtrl(dlg, -1, searchText, (80, 7), (195, -1)) wSearchText.SetValue(searchText) wx.Button(dlg, wx.ID_OK, "Find Next", (285, 5), wx.DefaultSize).SetDefault() wx.Button(dlg, wx.ID_CANCEL, "Cancel", (285, 35), wx.DefaultSize) wWholeWord = wx.CheckBox(dlg, -1, 'Match whole word only', (7, 35), wx.DefaultSize, wx.NO_BORDER) if wholeWordsOnly: wWholeWord.SetValue(1) wCase = wx.CheckBox(dlg, -1, 'Match case', (7, 55), wx.DefaultSize, wx.NO_BORDER) if caseSensitive: wCase.SetValue(1) wSearchText.SetSelection(0, len(wSearchText.GetValue())) wSearchText.SetFocus() result = DialogResults(dlg.ShowModal()) result.text = wSearchText.GetValue() result.wholeword = wWholeWord.GetValue() result.casesensitive = wCase.GetValue() dlg.Destroy() return result
aFontData.SetInitialFont(font)
fontData.SetInitialFont(font)
def fontDialog(parent=None, fontData=None, font=None): if fontData is None: fontData = wx.FontData() fontData.SetColour(wx.BLACK) fontData.SetInitialFont(wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)) if font is not None: aFontData.SetInitialFont(font) dialog = wx.FontDialog(parent, fontData) result = DialogResults(dialog.ShowModal()) if result.accepted: fontData = dialog.GetFontData() result.fontData = fontData result.color = fontData.GetColour().Get() result.colour = result.color result.font = fontData.GetChosenFont() else: result.color = None result.colour = None result.font = None dialog.Destroy() return result
dialog = wx.SingleChoiceDialog(parent, message, title, lst, style)
dialog = wx.SingleChoiceDialog(parent, message, title, list(lst), style | wx.DEFAULT_DIALOG_STYLE)
def singleChoiceDialog(parent=None, message='', title='', lst=[], style=wx.OK | wx.CANCEL | wx.CENTRE): dialog = wx.SingleChoiceDialog(parent, message, title, lst, style) result = DialogResults(dialog.ShowModal()) result.selection = dialog.GetStringSelection() dialog.Destroy() return result
self.frame = frame = wx.Frame(None, -1, "Dialogs", size=(400, 200))
self.frame = frame = wx.Frame(None, -1, "Dialogs", size=(400, 240))
def OnInit(self): self.frame = frame = wx.Frame(None, -1, "Dialogs", size=(400, 200)) panel = wx.Panel(frame, -1) self.panel = panel
def __del__(self): try: self.RestoreStdio() finally: wx.PyApp.__del__(self)
def __del__(self, destroy=wx.PyApp.__del__): self.RestoreStdio() destroy(self)
def __del__(self): try: self.RestoreStdio() # Just in case the MainLoop was overridden finally: wx.PyApp.__del__(self)
_sys.stdout, _sys.stderr = self.saveStdio
try: _sys.stdout, _sys.stderr = self.saveStdio except: pass
def RestoreStdio(self): _sys.stdout, _sys.stderr = self.saveStdio
elif evt.LeftUp and self._draggedShape and self._dragState == ContinueDraggingLeft:
elif evt.LeftUp() and self._draggedShape and self._dragState == ContinueDraggingLeft:
def OnMouseEvent(self, evt): dc = wx.ClientDC(self) self.PrepareDC(dc) x, y = evt.GetLogicalPosition(dc)