def OnInit(self): frame = wx.Frame(None) self.SetTopWindow(frame) TaskBarIcon(frame) return True
box = wx.BoxSizer(wx.VERTICAL) box.Add((10,10), 1) box.Add(hbox, 0, wx.EXPAND) box.Add((10,10), 2) self.SetSizer(box) self.Fit() #---------------------------------------------------------------------- if __name__ == '__main__': app = wx.App(redirect=False) frm = wx.Frame(None, title='MessagePanel Test') pnl = MessagePanel(frm, flags=wx.ICON_EXCLAMATION, caption="Please stand by...", message="""\ This is a test. This is a test of the emergency broadcast system. Had this been a real emergency, you would have already been reduced to a pile of radioactive cinders and wondering why 'duck and cover' didn't help. This is only a test...""") frm.Sizer = wx.BoxSizer() frm.Sizer.Add(pnl, 1, wx.EXPAND) frm.Fit() frm.Show() app.MainLoop()
if msg != '$P': return None, None tag = fields[2] tStr = fields[5] except IndexError: errors.append( u'{} {}: {}'.format(_('line'), lineNo, _('unrecognised input')) ) return None, None try: secs = int(tStr) / 1000.0 # Convert from 1000's of a second. except ValueError: errors.append( u'{} {}: {}'.format( _('line'), lineNo, _('invalid time')) ) return None, None else: t = datetime.datetime.combine( JChip.dateToday, datetime.time() ) + datetime.timedelta( seconds = secs ) return tag, t def OrionImportDialog( parent, id = wx.ID_ANY ): return ChipImportDialog( 'Orion', parseTagTime, parent, id ) if __name__ == '__main__': app = wx.App(False) mainWin = wx.Frame(None,title="CrossMan", size=(600,400)) Model.setRace( Model.Race() ) mainWin.Show() dlg = OrionImportDialog( mainWin ) dlg.ShowModal() dlg.Destroy()
new_pixel = [] for (r,g,b) in pixels: if r < 128: r = 255 - r if g < 128: g = 255 - g if b < 128: b = 255 - b new_pixels = (r, g, b) new_pixel.append(new_pixels) img.putdata(new_pixel) img.show() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__": app = wx.App(False) frame = wx.Frame(None, -1, 'PhotoShop') frame.SetDimensions(0,0,200,50) # Create open file dialog openFileDialog = wx.FileDialog(frame, "Open", "", "", "PNG files (*.png)|*.png", wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) openFileDialog.ShowModal() print(openFileDialog.GetPath()) i = openFileDialog.GetPath() app = wx.App(False) frame = MyForm().Show() app.MainLoop()
import wx def onButton(event): print("Button pressed.") app = wx.App() frame = wx.Frame(None, -1, 'win.py') frame.SetSize(0,0,200,50) # Create open file dialog openFileDialog = wx.FileDialog(frame, "Open", "", "", "", wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) openFileDialog.ShowModal() fileNamePath = openFileDialog.GetPath() openFileDialog.Destroy()
def OnImportGame(self,evt): #Reset dispplay self.changed=False self.saved=False self.elts=list() self.CreateTree() from config import MSE_PATH import os.path import MSE if not os.path.isfile(MSE_PATH): dlg = wx.FileDialog(self, "Where is MSE ?", self.dir, "", "All Files(*.*)|*.*", wx.OPEN) try: if dlg.ShowModal() == wx.ID_OK: # Your code filename=dlg.GetPath() import config config.MSE_PATH=MSE_PATH=filename config.set('mse','path',MSE_PATH) finally: dlg.Destroy() thedir,mse=os.path.split(MSE_PATH) src=os.path.join(thedir,'data') games=set() styles=dict() others=dict() names=[x for x in os.listdir(src) if os.path.isdir(os.path.join(src,x)) and len(x.split('.'))>1] for name in names: game_name,_typ=name.split('.',1) if _typ.lower()=="mse-game": games.add(game_name) elif _typ.lower()=='mse-style': gname,style_name=game_name.split('-',1) styles.setdefault(gname,[]).append(style_name) else: others.setdefault(_typ,[]).append(game_name) #Now create a frame with all games & their style f=wx.Frame(self) f.Title="MSE Template Browser" f.Sizer=wx.BoxSizer() tree=wx.TreeCtrl(f) root=tree.AddRoot('MSE Templates:') for g in sorted(games): item=tree.AppendItem(root,g) tree.SetPyData(item,('game',g)) if g in styles: for style in sorted(styles[g]): sitem=tree.AppendItem(item,style) tree.SetPyData(sitem,('style','%s-%s'%(g,style))) f.Sizer.Add(tree,1,wx.EXPAND|wx.ALL,0) bmp=wx.StaticBitmap(f,size=(200,300)) bmp.BackgroundColour=wx.NamedColour('WHITE') f.Sizer.Add(bmp,1,wx.EXPAND|wx.ALL,0) def findicon(filename): for line in file(filename,'rb'): if line.startswith('icon:'): _,dst=line.strip().split(':',1) return dst.strip() def updpict(evt): item=tree.Selection try: typ,name=tree.GetPyData(item) except TypeError: return fname=os.path.join(src,name) if typ=="game": fname+='.mse-game' icon=os.path.join(fname,"game") else: fname+='.mse-style' icon=os.path.join(fname,"style") icon=findicon(icon) if icon: bmp.ClearBackground() #double the image; there are to small. img=wx.Image(os.path.join(fname,icon)) #img=img.Rescale(img.Width*2,img.Height*2) bmp.SetBitmap(wx.BitmapFromImage(img)) f.Layout() def OnReadTemplate(evt): item=tree.Selection try: typ,name=tree.GetPyData(item) except TypeError: return from tempfile import mktemp fname=mktemp('.tmpl') elts=MSE.ImportTemplate(name,dst=fname) shapes=dict() props=dict() for eltName in elts: elt=elts[eltName] item=self.AddElt(elt) blank,shape,page=self.tree.GetPyData(item) print "here: should distinguish between script name & game name" for pName in elt.params: p=elt.params[pName] page.GetPropertyByName(pName).SetValue(p.value) if elt.Type=='template': shape.SetHeight(elt['card height']) shape.SetWidth(elt['card width']) shape.SetX(elt['card width']/2) shape.SetY(elt['card height']/2) else: shape.SetHeight(elt['height']) shape.SetWidth(elt['width']) shape.SetX(elt['left']+elt['width']/2) shape.SetY(elt['top']+elt['height']/2) self.file = "" self.Title="MSE_"+name f.Close() tree.Bind(wx.EVT_TREE_SEL_CHANGED,updpict) tree.Bind(wx.EVT_TREE_ITEM_ACTIVATED,OnReadTemplate) bmp.Bind(wx.EVT_LEFT_DCLICK,OnReadTemplate) tree.Expand(root) f.Show() return
return #wx標準でも戻り値はNoneである return super().Bind(event, handler, source=source, id=id, id2=id2) def columnEvent(self,event): if self.bindFunctions[event.GetEventType()]: event.SetColumn(self.getColFromWx(event.GetColumn()).col) self.bindFunctions[event.GetEventType()](event) else: event.Skip() def GetItemText(self, item, col): return self.lst[item][col] if __name__ == "__main__": app = wx.App() frame = wx.Frame() obj = virtualListCtrl(frame) l = [] for i in range(100000): l.append(i) print("ok") print(obj) obj += l print(obj) print("ok") obj.RefreshItems(0, 100000) print("ok") print(len(obj)) class Column:
# printing if not self.IsPreview(): if ep < stcEndPos: print _('warning: on page %s: not enough chars rendered, diff:' ) % (page, stcEndPos - ep) return True #---------------------------------------------------------------------- if __name__ == '__main__': testFile = 'STCPrinting.py' app = wx.PySimpleApp() wx.InitAllImageHandlers() frame = wx.Frame(None, -1, '') # prepare an stc frame.stc = wx.stc.StyledTextCtrl(frame, -1) frame.stc.SetText(open(testFile).read()) config = os.path.abspath('../Config/stc-styles.rc.cfg') from STCStyleEditor import initSTC initSTC(frame.stc, config, 'python') # print dlg for prepared stc dlg = STCPrintDlg(frame, frame.stc, testFile) try: dlg.ShowModal() finally: dlg.Destroy() wx.CallAfter(frame.Destroy) app.MainLoop()
def __init__(self): self._Onrun_UI = wx.Frame(None, id=wx.ID_ANY, title=wx.EmptyString, pos=wx.DefaultPosition, size=wx.Size(927, 596), style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL) self._Onrun_UI.SetSizeHints(wx.DefaultSize, wx.DefaultSize) self._Onrun_UI.SetBackgroundColour(wx.Colour(255, 255, 255)) fgSizer1 = wx.FlexGridSizer(2, 1, 0, 0) fgSizer1.SetFlexibleDirection(wx.BOTH) fgSizer1.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED) self.m_staticText1 = wx.StaticText(self._Onrun_UI, wx.ID_ANY, u"Modbus Data Sampling", wx.DefaultPosition, wx.DefaultSize, wx.ALIGN_CENTER_HORIZONTAL) self.m_staticText1.Wrap(-1) self.m_staticText1.SetFont( wx.Font(18, wx.FONTFAMILY_SCRIPT, wx.FONTSTYLE_ITALIC, wx.FONTWEIGHT_BOLD, False, "Comic Sans MS")) self.m_staticText1.SetForegroundColour(wx.Colour(0, 64, 128)) self.m_staticText1.SetBackgroundColour(wx.Colour(244, 244, 244)) fgSizer1.Add(self.m_staticText1, 0, wx.EXPAND, 5) self.m_panel1 = wx.Panel(self._Onrun_UI, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL) fgSizer2 = wx.FlexGridSizer(3, 1, 0, 0) fgSizer2.SetFlexibleDirection(wx.BOTH) fgSizer2.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED) self.m_panel2 = wx.Panel(self.m_panel1, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL) fgSizer3 = wx.FlexGridSizer(1, 2, 0, 0) fgSizer3.SetFlexibleDirection(wx.BOTH) fgSizer3.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED) self.m_panel6 = wx.Panel(self.m_panel2, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL) fgSizer8 = wx.FlexGridSizer(2, 1, 0, 0) fgSizer8.SetFlexibleDirection(wx.BOTH) fgSizer8.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED) self.m_staticText2 = wx.StaticText(self.m_panel6, wx.ID_ANY, u"Read Data", wx.DefaultPosition, wx.DefaultSize, 0) self.m_staticText2.Wrap(-1) self.m_staticText2.SetFont( wx.Font(11, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, "Arial")) self.m_staticText2.SetForegroundColour(wx.Colour(0, 128, 255)) fgSizer8.Add(self.m_staticText2, 0, wx.ALL, 5) self.dv_data = wx.dataview.DataViewListCtrl(self.m_panel6, wx.ID_ANY, wx.DefaultPosition, wx.Size(400, 250), 0) self.dv_col_nama = self.dv_data.AppendTextColumn( u"Name", wx.dataview.DATAVIEW_CELL_INERT, 240, wx.ALIGN_LEFT, wx.dataview.DATAVIEW_COL_RESIZABLE) self.dv_col_value = self.dv_data.AppendTextColumn( u"Average Value", wx.dataview.DATAVIEW_CELL_INERT, 150, wx.ALIGN_LEFT, wx.dataview.DATAVIEW_COL_RESIZABLE) fgSizer8.Add(self.dv_data, 0, wx.ALL, 5) self.m_panel6.SetSizer(fgSizer8) self.m_panel6.Layout() fgSizer8.Fit(self.m_panel6) fgSizer3.Add(self.m_panel6, 1, wx.EXPAND | wx.ALL, 5) self.m_panel7 = wx.Panel(self.m_panel2, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL) fgSizer9 = wx.FlexGridSizer(2, 1, 0, 0) fgSizer9.SetFlexibleDirection(wx.BOTH) fgSizer9.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED) self.m_staticText3 = wx.StaticText(self.m_panel7, wx.ID_ANY, u"Read Log", wx.DefaultPosition, wx.DefaultSize, 0) self.m_staticText3.Wrap(-1) self.m_staticText3.SetFont( wx.Font(11, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, "Arial")) self.m_staticText3.SetForegroundColour(wx.Colour(255, 0, 0)) fgSizer9.Add(self.m_staticText3, 0, wx.ALL, 5) lb_readlogChoices = [] self.lb_readlog = wx.ListBox(self.m_panel7, wx.ID_ANY, wx.DefaultPosition, wx.Size(450, 250), lb_readlogChoices, wx.LB_ALWAYS_SB) fgSizer9.Add(self.lb_readlog, 0, wx.ALL, 5) self.m_panel7.SetSizer(fgSizer9) self.m_panel7.Layout() fgSizer9.Fit(self.m_panel7) fgSizer3.Add(self.m_panel7, 1, wx.EXPAND | wx.ALL, 5) self.m_panel2.SetSizer(fgSizer3) self.m_panel2.Layout() fgSizer3.Fit(self.m_panel2) fgSizer2.Add(self.m_panel2, 1, wx.EXPAND | wx.ALL, 5) ### self.m_panel61 = wx.Panel(self.m_panel1, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL) fgSizer7 = wx.FlexGridSizer(3, 1, 0, 0) fgSizer7.SetFlexibleDirection(wx.BOTH) fgSizer7.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED) self.m_staticText5 = wx.StaticText(self.m_panel61, wx.ID_ANY, u"Check Data Graph", wx.DefaultPosition, wx.DefaultSize, 0) self.m_staticText5.Wrap(-1) self.m_staticText5.SetFont( wx.Font(12, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False, "Arial")) self.m_staticText5.SetForegroundColour(wx.Colour(0, 128, 128)) fgSizer7.Add(self.m_staticText5, 0, wx.ALL, 5) fgSizer91 = wx.FlexGridSizer(3, 2, 0, 0) fgSizer91.SetFlexibleDirection(wx.BOTH) fgSizer91.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED) self.m_staticText7 = wx.StaticText(self.m_panel61, wx.ID_ANY, u"Choose Date", wx.DefaultPosition, wx.DefaultSize, 0) self.m_staticText7.Wrap(-1) fgSizer91.Add(self.m_staticText7, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5) self.date_picker_01 = wx.adv.DatePickerCtrl( self.m_panel61, wx.ID_ANY, wx.DefaultDateTime, wx.DefaultPosition, wx.DefaultSize, wx.adv.DP_DEFAULT | wx.adv.DP_DROPDOWN) fgSizer91.Add(self.date_picker_01, 0, wx.ALL, 5) self.m_staticText8 = wx.StaticText(self.m_panel61, wx.ID_ANY, u"Choose Device", wx.DefaultPosition, wx.DefaultSize, 0) self.m_staticText8.Wrap(-1) fgSizer91.Add(self.m_staticText8, 0, wx.ALL, 5) devicelist_graphChoices = [] self.devicelist_graph = wx.Choice(self.m_panel61, wx.ID_ANY, wx.DefaultPosition, wx.Size(250, -1), devicelist_graphChoices, 0) self.devicelist_graph.SetSelection(0) fgSizer91.Add(self.devicelist_graph, 0, wx.ALL, 5) fgSizer7.Add(fgSizer91, 1, wx.EXPAND, 5) self.cmd_generategraph = wx.Button(self.m_panel61, wx.ID_ANY, u"Generate Graph", wx.DefaultPosition, wx.DefaultSize, 0) fgSizer7.Add(self.cmd_generategraph, 0, wx.ALL, 5) self.m_panel61.SetSizer(fgSizer7) self.m_panel61.Layout() fgSizer7.Fit(self.m_panel61) fgSizer2.Add(self.m_panel61, 1, wx.EXPAND | wx.ALL, 5) ### self.m_panel5 = wx.Panel(self.m_panel1, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL) gSizer1 = wx.GridSizer(1, 2, 0, 0) self.cmd_start6969 = wx.Button(self.m_panel5, wx.ID_ANY, u"START", wx.DefaultPosition, wx.DefaultSize, 0) gSizer1.Add(self.cmd_start6969, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT, 5) self.cmd_stop6969 = wx.Button(self.m_panel5, wx.ID_ANY, u"STOP", wx.DefaultPosition, wx.DefaultSize, 0) gSizer1.Add(self.cmd_stop6969, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5) self.m_panel5.SetSizer(gSizer1) self.m_panel5.Layout() gSizer1.Fit(self.m_panel5) fgSizer2.Add(self.m_panel5, 1, wx.EXPAND | wx.ALL, 5) self.m_panel1.SetSizer(fgSizer2) self.m_panel1.Layout() fgSizer2.Fit(self.m_panel1) fgSizer1.Add(self.m_panel1, 1, wx.EXPAND | wx.ALL, 5) self._Onrun_UI.SetSizer(fgSizer1) self._Onrun_UI.Layout() self._Onrun_UI.Centre(wx.BOTH) # Connect Events self._Onrun_UI.Bind(wx.EVT_CLOSE, self.Destroye) self.cmd_generategraph.Bind(wx.EVT_BUTTON, self.generatedagraph) self.cmd_start6969.Bind(wx.EVT_BUTTON, self.StartRecord) self.cmd_stop6969.Bind(wx.EVT_BUTTON, self.StopRecord) self.cmd_stop6969.Disable()
def grid_test(): df = pd.DataFrame(np.random.randn(100, 5)) frame = wx.Frame(None, title='Grid') grid = Grid(frame) grid.set_data(df) frame.Show()
def setUp(self): self.app = wx.App() wx.Log.SetActiveTarget(wx.LogStderr()) self.frame = wx.Frame(None, title='WTC: ' + self.__class__.__name__) self.frame.Show() self.frame.PostSizeEvent()
question.SetLabel(label="Game Over!") result.SetLabel(label="Yup, the game is finally over!") guessButton.Disable() nextButton.Disable() hintButton.Disable() def hint(event): input_word.SetValue(query[0]) app = wx.App() # The definition of splash screen is done after an object for the wx.App class has been defined. Same applies to all the other widgets splash_image = wx.Image("splash.png", wx.BITMAP_TYPE_PNG) bmp = splash_image.ConvertToBitmap() wx.SplashScreen(bmp, wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_TIMEOUT, 2000, None, -1) wx.Yield() win = wx.Frame(None, title="Jumbled Words Game", size=(460, 285)) win.SetIcon(wx.Icon('star.ico', wx.BITMAP_TYPE_ICO)) win.CenterOnScreen() bkg = wx.Panel(win) # Provide some color to the boring background bkg.SetBackgroundColour('#F9F7ED') guessButton = wx.Button(bkg, label='Guess') guessButton.Bind(wx.EVT_BUTTON, guess) guessButton.SetDefault() # Unless the player has pressed the Start button, the Guess button will be disabled guessButton.Disable() nextButton = wx.Button(bkg, label='Start') nextButton.Bind(wx.EVT_BUTTON, next) hintButton = wx.Button(bkg, label='Hint') hintButton.Bind(wx.EVT_BUTTON, hint) hintButton.Disable()
import wx app = wx.App() frame = wx.Frame(None, -1, title='wxtest.py', pos=(300, 400), size=(200, 150)) frame.Centre() frame.Show() app.MainLoop()
evt = wx.CommandEvent(wx.wxEVT_COMMAND_LISTBOX_SELECTED, self.Id) evt.SetInt(i) self.AddPendingEvent(evt) if __name__ == '__main__': class MyList(SkinVListBox): def __init__(self, parent): SkinVListBox.__init__(self, parent) def OnGetLineHeight(self, i): return 20 def OnDrawItem(self, dc, rect, n): dc.SetBrush(wx.RED_BRUSH) #@UndefinedVariable dc.DrawRectangleRect(rect) def OnDrawBackground(self, dc, rect, n): pass a = wx.PySimpleApp() f = wx.Frame(None) l = MyList(f) l.SetItemCount(10) f.Show() a.MainLoop()
mainSizer.Add(self.button, 0, wx.CENTER) self.SetSizerAndFit(mainSizer) def OnClick(self, *args, **kwargs): pass def EvtText(self, *args, **kwargs): pass def EvtChar(self, *args, **kwargs): pass def EvtComboBox(self, *args, **kwargs): pass def EvtCheckBox(self, *args, **kwargs): pass def EvtRadioBox(self, *args, **kwargs): pass def EvtBigText(self, *args, **kwargs): pass app = wx.App(False) frame = wx.Frame(None) panel = ExamplePanel(frame) frame.Show() app.MainLoop()
def load(event): file = open(filename.GetValue()) contents.SetValue(file.read()) file.close() def save(event): file = open(filename.GetValue(), "w") file.write(contents.GetValue()) file.close() app = wx.App() win = wx.Frame(None, title="修改文件", size=(410, 335)) bkg = wx.Panel(win) loadbtn = wx.Button(bkg, label="打开") loadbtn.Bind(wx.EVT_BUTTON, load) savelbtn = wx.Button(bkg, label="保存") savelbtn.Bind(wx.EVT_BUTTON, save) filename = wx.TextCtrl(bkg) contents = wx.TextCtrl(bkg, style=wx.TE_MULTILINE | wx.HSCROLL) hbox = wx.BoxSizer() hbox.Add(filename, proportion=1, flag=wx.EXPAND) hbox.Add(loadbtn, proportion=0, flag=wx.LEFT, border=5)
for i, pt_list in enumerate(self.point_lists): plot_pts = num.array(pt_list) clr = [float(c) / 255. for c in self.clr_list[i]] self.subplot.plot(plot_pts[:, 0], plot_pts[:, 1], color=clr) theta = num.arange(0, 45 * 2 * num.pi, 0.02) rad0 = (0.8 * theta / (2 * num.pi) + 1) r0 = rad0 * (8 + num.sin(theta * 7 + rad0 / 1.8)) x0 = r0 * num.cos(theta) y0 = r0 * num.sin(theta) rad1 = (0.8 * theta / (2 * num.pi) + 1) r1 = rad1 * (6 + num.sin(theta * 7 + rad1 / 1.9)) x1 = r1 * num.cos(theta) y1 = r1 * num.sin(theta) points = [[(xi, yi) for xi, yi in zip(x0, y0)], [(xi, yi) for xi, yi in zip(x1, y1)]] clrs = [[225, 200, 160], [219, 112, 147]] app = wx.PySimpleApp(0) frame = wx.Frame(None, wx.ID_ANY, 'WxPython and Matplotlib', size=(300, 300)) panel = DemoPlotPanel(frame, points, clrs) frame.Show() app.MainLoop()
# -*- coding: utf-8 -*- # 对话框 import wx app = wx.App() frame = wx.Frame(None, -1, title='Dialog...', size=(300, 200)) frame.Show() # 消息对话框 dlg = wx.MessageDialog(None, 'Is this the coolest thing ever!', 'MessageDialog', wx.YES_NO | wx.ICON_QUESTION) result = dlg.ShowModal() print('result: ', result) # 文本输入对话框 entry_dlg = wx.TextEntryDialog(None, 'what is your name?', 'A question', 'xiaoming') if entry_dlg.ShowModal() == wx.ID_OK: response = entry_dlg.GetValue() print('response: ', response) # 单选列表 select_dlg = wx.SingleChoiceDialog(None, 'what version of python are you using?', 'Single Choice', ['2.7', '3.4', '3.5.2', '3.6']) if select_dlg.ShowModal() == wx.ID_OK: response = select_dlg.GetStringSelection() print('response: ', response)
def __init__(self, parent=None, ID=-1, *args, **kw): # First do special handling of some keywords: # stereo, position, size, width, height, style stereo = 0 self._last_mouse_pos = None self.__is_frozen = False if 'stereo' in kw: if kw['stereo']: stereo = 1 del kw['stereo'] position = wx.DefaultPosition if 'position' in kw: position = kw['position'] del kw['position'] size = wx.DefaultSize if 'size' in kw: size = kw['size'] if not isinstance(size, wx.Size): size = apply(wx.Size, size) del kw['size'] if 'width' in kw and 'height' in kw: size = wx.Size(kw['width'], kw['height']) del kw['width'] del kw['height'] # wx.WANTS_CHARS says to give us e.g. TAB # wx.NO_FULL_REPAINT_ON_RESIZE cuts down resize flicker under GTK style = wx.WANTS_CHARS | wx.NO_FULL_REPAINT_ON_RESIZE if 'style' in kw: style = style | kw['style'] del kw['style'] # if there is no parent, make a frame window if parent is None: parent = wx.Frame(None, -1, "wxRenderWindow", position, size) parent.Show(1) self._wxFrame = parent # initialize the wxWindow -- take care here to ensure double-buffering is # enabled under Linux if wx.Platform != '__WXMSW__': attribList = [ wx.glcanvas.WX_GL_RGBA, wx.glcanvas.WX_GL_DOUBLEBUFFER, wx.glcanvas.WX_GL_DEPTH_SIZE, 16 ] baseClass.__init__(self, parent, id=ID, pos=position, size=size, style=style, attribList=attribList) else: baseClass.__init__(self, parent, ID, position, size, style) # create the RenderWindow and initialize it self._RenderWindow = vtk.vtkRenderWindow() self.__Created = 0 # create the RenderWindow and initialize it self._RenderWindowInteractor = vtk.vtkGenericRenderWindowInteractor() self._RenderWindowInteractor.SetRenderWindow(self._RenderWindow) self._RenderWindowInteractor.GetRenderWindow().AddObserver( 'CursorChangedEvent', self.CursorChangedEvent) try: self._RenderWindowInteractor.GetRenderWindow().SetSize( size.width, size.height) except AttributeError: self._RenderWindowInteractor.GetRenderWindow().SetSize( size[0], size[1]) if stereo: self._RenderWindowInteractor.GetRenderWindow( ).StereoCapableWindowOn() self._RenderWindowInteractor.GetRenderWindow( ).SetStereoTypeToCrystalEyes() # The superclass can't be initialized until _RenderWindow # has been declared. PaneFrame.PaneFrame.__init__(self) self.__handle = None self.__has_painted = False self.__is_mapped = False self._own_mouse = False self._mouse_capture_button = 0 self._cursor_map = { 0: wx.CURSOR_ARROW, # VTK_CURSOR_DEFAULT 1: wx.CURSOR_ARROW, # VTK_CURSOR_ARROW 2: wx.CURSOR_SIZENESW, # VTK_CURSOR_SIZENE 3: wx.CURSOR_SIZENWSE, # VTK_CURSOR_SIZENWSE 4: wx.CURSOR_SIZENESW, # VTK_CURSOR_SIZESW 5: wx.CURSOR_SIZENWSE, # VTK_CURSOR_SIZESE 6: wx.CURSOR_SIZENS, # VTK_CURSOR_SIZENS 7: wx.CURSOR_SIZEWE, # VTK_CURSOR_SIZEWE 8: wx.CURSOR_SIZING, # VTK_CURSOR_SIZEALL 9: wx.CURSOR_HAND, # VTK_CURSOR_HAND 10: wx.CURSOR_CROSS, # VTK_CURSOR_CROSSHAIR } # private variable for better Enter/Leave handling self.__ActiveButton = 0 self.__SaveState = 0 self._Inside = 0 # refresh window by doing a Render wx.EVT_PAINT(self, self.OnPaint) # turn off background erase to reduce flicker wx.EVT_ERASE_BACKGROUND(self, lambda e: None) # Bind the events to the event converters self.Bind(wx.EVT_RIGHT_DOWN, self.OnButtonDown) self.Bind(wx.EVT_LEFT_DOWN, self.OnButtonDown) self.Bind(wx.EVT_MIDDLE_DOWN, self.OnButtonDown) self.Bind(wx.EVT_RIGHT_UP, self.OnButtonUp) self.Bind(wx.EVT_LEFT_UP, self.OnButtonUp) self.Bind(wx.EVT_MIDDLE_UP, self.OnButtonUp) # double click events self.Bind(wx.EVT_RIGHT_DCLICK, self.OnButtonDClick) self.Bind(wx.EVT_LEFT_DCLICK, self.OnButtonDClick) self.Bind(wx.EVT_MIDDLE_DCLICK, self.OnButtonDClick) self.Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheel) self.Bind(wx.EVT_MOTION, self.OnMotion) self.Bind(wx.EVT_ENTER_WINDOW, self.OnEnter) self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave) # If we use EVT_KEY_DOWN instead of EVT_CHAR, capital versions # of all characters are always returned. EVT_CHAR also performs # other necessary keyboard-dependent translations. self.Bind(wx.EVT_CHAR, self.OnKeyDown) self.Bind(wx.EVT_KEY_UP, self.OnKeyUp) self.Bind(wx.EVT_SIZE, self.OnSize) # the wx 2.8.7.1 documentation states that you HAVE to handle # this event if you make use of CaptureMouse, which we do. if _useCapture and hasattr(wx, 'EVT_MOUSE_CAPTURE_LOST'): self.Bind(wx.EVT_MOUSE_CAPTURE_LOST, self.OnMouseCaptureLost) # pretend that we're a base window - let atamai help us out self._BindInteractor() # debug debug debug return # Bind the events to the event converters wx.EVT_MOUSE_EVENTS(self, self.ConvertMouseEvent) wx.EVT_KEY_DOWN(self, self.ConvertKeyEvent) wx.EVT_KEY_UP(self, self.ConvertKeyEvent) wx.EVT_SIZE(self, self.ConvertSizeEvent) # wx.EVT_MOVE(self, self.ConvertMoveEvent) wx.EVT_SET_FOCUS(self, self.ConvertFocusEvent) wx.EVT_KILL_FOCUS(self, self.ConvertFocusEvent)
multitask.add(execute(s)) pending[:] = [] except StopIteration: raise except: print 'waitonsock', sys.exc_info(), traceback.print_exc() multitask.add(waitonsock(sock1)) # this will trigger multitask out of wait loop logger.debug('starting multitask.run()') if _trace: sys.settrace(traceit) try: multitask.run() except KeyboardInterrupt: interrupt_main() except: logger.exception('exception in multitask.run()') thread.start_new_thread(threadproc, (None,)) if __name__ == '__main__': if sys.argv[-1] == '--test': sys.exit() # no tests logging.basicConfig() logger.setLevel(logging.DEBUG if sys.argv[-1] == '-d' else logging.CRITICAL) app = wx.PySimpleApp() frame = wx.Frame(parent=None, id=wx.ID_ANY, title='DHT display') #testDisplay(frame) testDHT(frame) frame.Fit() frame.Show(True) app.MainLoop() sys.exit()
class TestLog: def __init__(self): pass def write(self, msg): print msg #---------------------------------------------------------------------- overview = eclib.errdlg.__doc__ title = "ErrorDialog" #-----------------------------------------------------------------------------# if __name__ == '__main__': try: import run except ImportError: app = wx.PySimpleApp(False) frame = wx.Frame(None, title="File Info Dialog Demo") sizer = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(TestPanel(frame, TestLog()), 1, wx.EXPAND) frame.CreateStatusBar() frame.SetSizer(sizer) frame.SetInitialSize((300, 300)) frame.Show() app.MainLoop() else: run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
def ShowExpanded(self): """ Show the panel externally expanded. When a panel is minimised, it can be shown full-size in a pop-out window, which is referred to as being (externally) expanded. :returns: ``True`` if the panel was expanded, ``False`` if it was not (possibly due to it not being minimised, or already being expanded). :note: When a panel is expanded, there exist two panels - the original panel (which is referred to as the dummy panel) and the expanded panel. The original is termed a dummy as it sits in the ribbon bar doing nothing, while the expanded panel holds the panel children. :see: :meth:`~RibbonPanel.HideExpanded`, :meth:`~RibbonPanel.GetExpandedPanel` """ if not self.IsMinimised(): return False if self._expanded_dummy is not None or self._expanded_panel != None: return False size = self.GetBestSize() pos = self.GetExpandedPosition( wx.Rect(self.GetScreenPosition(), self.GetSize()), size, self._preferred_expand_direction).GetTopLeft() # Need a top-level frame to contain the expanded panel container = wx.Frame(None, wx.ID_ANY, self.GetLabel(), pos, size, wx.FRAME_NO_TASKBAR | wx.BORDER_NONE) self._expanded_panel = MyRibbonPanel( parent=container, id=wx.ID_ANY, label=self.GetLabel(), minimised_icon=self._minimised_icon, pos=wx.Point(0, 0), size=size, agwStyle=self._flags, recurse=True) self._expanded_panel.SetArtProvider(self._art) self._expanded_panel._expanded_dummy = self # Move all children to the new panel. # Conceptually it might be simpler to reparent self entire panel to the # container and create a new panel to sit in its place while expanded. # This approach has a problem though - when the panel is reinserted into # its original parent, it'll be at a different position in the child list # and thus assume a new position. # NB: Children iterators not used as behaviour is not well defined # when iterating over a container which is being emptied for child in self.GetChildren(): child.Reparent(self._expanded_panel) child.Show() # Move sizer to new panel if self.GetSizer(): sizer = self.GetSizer() self.SetSizer(None, False) self._expanded_panel.SetSizer(sizer) self._expanded_panel._minimised = False self._expanded_panel.SetSize(size) self._expanded_panel.Realize() self.Refresh() container.Show() self._expanded_panel.SetFocus() return True
self.SetSize(self.GetSize() + (OTHER_WIDTH, 0)) self.splitter.SplitVertically(self.splitter.GetWindow1(), self._selectList, -OTHER_WIDTH) else: self.selectBtn.SetLabel(">>>") sashPos = self.splitter.GetSashPosition() self.splitter.Unsplit() self._selectList.Destroy() cs = self.GetClientSize() self.SetClientSize((sashPos, cs.height)) #---------------------------------------------------------------------------- if __name__ == '__main__': app = wx.App(redirect=False) frm = wx.Frame(None, title="Test Frame") pnl = wx.Panel(frm) txt = wx.TextCtrl(pnl, -1, "text", pos=(20, 20)) btn = wx.Button(pnl, -1, "button", pos=(20, 50)) frm.Show() ewf = EventWatcher(frm) ewf.watch(frm) ewf.Show() #import wx.lib.inspection #wx.lib.inspection.InspectionTool().Show() app.MainLoop()
def setUp(self): controller = TestCaseController(IncredibleMock(), IncredibleMock()) plugin = FakePlugin({}, controller) self.tc_editor = TestCaseEditor( plugin, wx.Frame(None), controller, None)
def showGLFrame(): f = wx.Frame(None, size=(800, 800)) c = LMGLCanvas(f) f.Show() return c
#!/usr/bin/env python3 __Author__ = "limugen" import wx app = wx.App() win = wx.Frame(None,title="Translate Files to",size=(410,335)) bkg = wx.Panel(win) loadButton = wx.Button(bkg,label='Open') saveButton = wx.Button(bkg,label='Save') filename = wx.TextCtrl(bkg) contents = wx.TextCtrl(bkg,style=wx.TE_MULTILINE |wx.HSCROLL) hbox = wx.BoxSizer() hbox.Add(filename,proportion=1,flag=wx.EXPAND) hbox.Add(loadButton,proportion=0,flag=wx.LEFT,border=5) hbox.Add(saveButton,proportion=0,flag=wx.LEFT,border=5) vbox = wx.BoxSizer(wx.VERTICAL) vbox.Add(hbox,proportion=0,flage=wx.EXPAND | wx.ALL,border=5) vbox.Add(contents,proportion=1,flage=wx.EXPAND | wx.LEFT | wx.BOTTOM | wx.RIGHT,border=5) bkg.SetSizer(vbox) win.Show() app.MainLoop()
import wx def load(event): file = open(fileName.GetValue()) fileContent.SetValue(file.read()) file.close() def save(event): file = open(fileName.GetValue(), 'w') file.write(fileContent.GetValue()) file.close() app = wx.App() win = wx.Frame(None, title="EditPlus") win.Show() openButton = wx.Button(win, label='Open', pos=(225, 5), size=(80, 25)) openButton.Bind(wx.EVT_BUTTON, load) saveButton = wx.Button(win, label='Save', pos=(315, 5), size=(80, 25)) saveButton.Bind(wx.EVT_BUTTON, save) fileName = wx.TextCtrl(win, pos=(5, 5), size=(210, 25)) fileContent = wx.TextCtrl(win, pos=(5, 35), size=(390, 260), style=wx.TE_MULTILINE | wx.HSCROLL) app.MainLoop()
import wx import wx.html2 class Panel_gis(wx.Panel): def __init__(self,parent): wx.Panel.__init__(self,parent=parent) sizer = wx.BoxSizer(wx.VERTICAL) self.browser = wx.html2.WebView.New(self) self.browser.LoadURL(r"templates\index.jpg") sizer.Add(self.browser, 1, wx.EXPAND, 10) self.SetSizer(sizer) app = wx.App() frame = wx.Frame(None,-1) pane = Panel_gis(frame) frame.Show() app.MainLoop()
def main(): app = wx.App(False) frame = wx.Frame(None, title="Query Editor", size=(600, 400)) panel = QueryEditorPanel(frame) frame.Show(True) app.MainLoop()
def OnInit(self): frame = wx.Frame(parent=None, title='What the hell!!!') frame.Show() return True