def OnRunDynamicWizard(self, evt): # Create the wizard and the pages #wizard = wx.PreWizard() #wizard.SetExtraStyle(wx.WIZARD_EX_HELPBUTTON) #wizard.Create(self, self.ID_wiz, "Simple Wizard", # images.WizTest1.GetBitmap()) wizard = wiz(self, -1, "Dynamic Wizard", wx.BitmapBundle(images.WizTest1.GetBitmap())) page1 = TitledPage(wizard, "Page 1") page2 = SkipNextPage(wizard, "Page 2") page3 = TitledPage(wizard, "Page 3") page4 = UseAltBitmapPage(wizard, "Page 4") page5 = TitledPage(wizard, "Page 5") self.page1 = page1 page1.sizer.Add( wx.StaticText( page1, -1, """ This wizard shows the ability to choose at runtime the order of the pages and also which bitmap is shown. """)) wizard.FitToPage(page1) page5.sizer.Add(wx.StaticText(page5, -1, "\nThis is the last page.")) # Set the initial order of the pages page1.SetNext(page2) page2.SetPrev(page1) page2.SetNext(page3) page3.SetPrev(page2) page3.SetNext(page4) page4.SetPrev(page3) page4.SetNext(page5) page5.SetPrev(page4) wizard.GetPageAreaSizer().Add(page1) if wizard.RunWizard(page1): wx.MessageBox("Wizard completed successfully", "That's all folks!") else: wx.MessageBox("Wizard was cancelled", "That's all folks!")
def OnRunSimpleWizard(self, evt): # Create the wizard and the pages wizard = wiz(self, -1, "Simple Wizard", wx.BitmapBundle(images.WizTest1.GetBitmap())) page1 = TitledPage(wizard, "Page 1") page2 = TitledPage(wizard, "Page 2") page3 = TitledPage(wizard, "Page 3") page4 = TitledPage(wizard, "Page 4") self.page1 = page1 page1.sizer.Add( wx.StaticText( page1, -1, """ This wizard is totally useless, but is meant to show how to chain simple wizard pages together in a non-dynamic manner. IOW, the order of the pages never changes, and so the wxWizardPageSimple class can easily be used for the pages.""")) wizard.FitToPage(page1) page4.sizer.Add(wx.StaticText(page4, -1, "\nThis is the last page.")) # Use the convenience Chain function to connect the pages WizardPageSimple.Chain(page1, page2) WizardPageSimple.Chain(page2, page3) WizardPageSimple.Chain(page3, page4) wizard.GetPageAreaSizer().Add(page1) if wizard.RunWizard(page1): wx.MessageBox("Wizard completed successfully", "That's all folks!") else: wx.MessageBox("Wizard was cancelled", "That's all folks!")
def get_btn_bitmap(bitmap): path = os.path.join(os.path.dirname(__file__), "bitmaps", bitmap) png = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) if WX_VERSION >= (3, 1, 6): return wx.BitmapBundle(png) else: return png
def _populateToolBar(self, tb): bmps = [wx.Bitmap(name) for name in toolImgFiles] size = bmps[0].GetSize() tb.SetToolBitmapSize(size) tools = [] for bmp in bmps: tool = tb.AddTool(-1, 'label', wx.BitmapBundle(bmp)) self.assertTrue(isinstance(tool, wx.ToolBarToolBase)) tools.append(tool) tb.Realize() return tools
def test_wizard3(self): # Same as above but use the Chain function to connect the pages bmp = wx.BitmapBundle(wx.Bitmap(pngFile)) wiz = wx.adv.Wizard(self.frame, title="Test Wizard 2", bitmap=bmp) pages = [] for i in range(5): pages.append(MySimpleWizPage(wiz, str(i + 1))) wx.adv.WizardPageSimple.Chain(pages[0], pages[1]) wx.adv.WizardPageSimple.Chain(pages[1], pages[2]) wx.adv.WizardPageSimple.Chain(pages[2], pages[3]) wx.adv.WizardPageSimple.Chain(pages[3], pages[4]) wiz.FitToPage(pages[0]) wx.CallLater(100, self._autoPilot, wiz) wiz.RunWizard(pages[0]) wiz.Destroy()
def AddToolbarModeButtons(self, tb, Modes): """ Add the mode buttons to the tool bar. :param ToolBar `tb`: the toolbar instance :param list `Modes`: a list of modes to add, out of the box valid modes are subclassed from :class:`~lib.floatcanvas.GUIMode.GUIBase` or modes can also be user defined. """ self.ModesDict = {} for Mode in Modes: tool = tb.AddTool(wx.ID_ANY, label=Mode[0], shortHelp=Mode[0], bitmap=wx.BitmapBundle(Mode[2]), kind=wx.ITEM_RADIO) self.Bind(wx.EVT_TOOL, self.SetMode, tool) self.ModesDict[tool.GetId()] = Mode[1]
def test_wizard2(self): # Create the wizard bmp = wx.BitmapBundle(wx.Bitmap(pngFile)) wiz = wx.adv.Wizard(self.frame, title="Test Wizard 2", bitmap=bmp) # create the pages pages = [] for i in range(5): pages.append(MySimpleWizPage(wiz, str(i + 1))) # set the next/prev pages for idx, p in enumerate(pages): p.SetNext(pages[idx + 1] if idx < len(pages) - 1 else None) p.SetPrev(pages[idx - 1] if idx > 0 else None) wiz.FitToPage(pages[0]) wx.CallLater(100, self._autoPilot, wiz) wiz.RunWizard(pages[0]) wiz.Destroy()
def __init__(self, parent, log): wx.Panel.__init__(self, parent, -1) self.log = log panel = wx.Panel(self, -1) buttons = wx.BoxSizer(wx.HORIZONTAL) for word in "These are toggle buttons".split(): b = wx.ToggleButton(panel, -1, word) self.Bind(wx.EVT_TOGGLEBUTTON, self.OnToggle, b) buttons.Add(b, flag=wx.ALL, border=5) panel.SetAutoLayout(True) panel.SetSizer(buttons) buttons.Fit(panel) panel.Move((50, 50)) b = wx.ToggleButton(self, -1, "can have bitmaps too", pos=(50, 125)) b.SetBitmap(wx.BitmapBundle(images.Mondrian.Bitmap)) b.SetInitialSize() # adjust default size for the bitmap self.Bind(wx.EVT_TOGGLEBUTTON, self.OnToggle, b)
def __init__(self, parent, log): wx.Panel.__init__(self, parent, -1, style=wx.NO_FULL_REPAINT_ON_RESIZE) self.log = log if 0: # a test case for catching wx.PyAssertionError #wx.GetApp().SetAssertMode(wx.PYAPP_ASSERT_SUPPRESS) #wx.GetApp().SetAssertMode(wx.PYAPP_ASSERT_EXCEPTION) #wx.GetApp().SetAssertMode(wx.PYAPP_ASSERT_DIALOG) #wx.GetApp().SetAssertMode(wx.PYAPP_ASSERT_EXCEPTION | wx.PYAPP_ASSERT_DIALOG) try: bmp = wx.Bitmap("nosuchfile.bmp", wx.BITMAP_TYPE_BMP) mask = wx.Mask(bmp, wx.BLUE) except wx.PyAssertionError: self.log.write("Caught wx.PyAssertionError! I will fix the problem.\n") bmp = images.Test2.GetBitmap() mask = wx.MaskColour(bmp, wx.BLUE) else: bmp = images.Test2.GetBitmap() mask = wx.Mask(bmp, wx.BLUE) bmp.SetMask(mask) b = wx.BitmapButton(self, -1, bmp, (20, 20), (bmp.GetWidth()+10, bmp.GetHeight()+10)) b.SetToolTip("This is a bitmap button.") self.Bind(wx.EVT_BUTTON, self.OnClick, b) b = wx.BitmapButton(self, -1, bmp, (20, 120), style = wx.NO_BORDER) # hide a little surprise in the button... img = images.Robin.GetImage() # we need to make it be the same size as the primary image, so # grab a subsection of this new image cropped = img.GetSubImage((20, 20, bmp.GetWidth(), bmp.GetHeight())) b.SetBitmapPressed(wx.BitmapBundle(cropped.ConvertToBitmap())) b.SetToolTip("This is a bitmap button with \nwx.NO_BORDER style.") self.Bind(wx.EVT_BUTTON, self.OnClick, b)
def __init__(self, parent, log): wx.Panel.__init__(self, parent, -1, style=wx.NO_FULL_REPAINT_ON_RESIZE) self.log = log b = wx.Button(self, 10, "Default Button", (20, 20)) self.Bind(wx.EVT_BUTTON, self.OnClick, b) b.SetDefault() b.SetSize(b.GetBestSize()) b = wx.Button(self, 20, "HELLO AGAIN!", (20, 80)) self.Bind(wx.EVT_BUTTON, self.OnClick, b) b.SetToolTip("This is a Hello button...") b = wx.Button(self, 40, "Flat Button?", (20, 160), style=wx.NO_BORDER) b.SetToolTip("This button has a style flag of wx.NO_BORDER.\n" "On some platforms that will give it a flattened look.") self.Bind(wx.EVT_BUTTON, self.OnClick, b) b = wx.Button(self, 50, "wx.Button with icon", (20, 220)) b.SetToolTip("wx.Button can how have an icon on the left, right,\n" "above or below the label.") self.Bind(wx.EVT_BUTTON, self.OnClick, b) b.SetBitmap( wx.BitmapBundle(images.Mondrian.Bitmap), wx. LEFT # Left is the default, the image can be on the other sides too #wx.RIGHT #wx.TOP #wx.BOTTOM ) b.SetBitmapMargins( (2, 2)) # default is 4 but that seems too big to me. # Setting the bitmap and margins changes the best size, so # reset the initial size since we're not using a sizer in this # example which would have taken care of this for us. b.SetInitialSize()
def test_headercolCtor2(self): bmp = wx.BitmapBundle(wx.Bitmap(pngFile)) hc = wx.HeaderColumnSimple(bmp, flags=wx.COL_RESIZABLE) hc.BitmapBundle
def __init__(self, parent, log): wx.Frame.__init__(self, parent, title="BalloonTip wxPython Demo ;-)") self.statusbar = self.CreateStatusBar(2) self.statusbar.SetStatusWidths([-2, -1]) # statusbar fields statusbar_fields = [("Welcome To WxPython " + wx.VERSION_STRING), ("BalloonTip Demo")] for i in range(len(statusbar_fields)): self.statusbar.SetStatusText(statusbar_fields[i], i) self.SetIcon(images.Mondrian.GetIcon()) self.SetMenuBar(self.CreateMenuBar()) panel = wx.Panel(self, -1) mainsizer = wx.FlexGridSizer(3, 4, hgap=2, vgap=2) # Add A Button button = wx.Button(panel, -1, "Press Me!") # Add A TextCtrl textctrl = wx.TextCtrl(panel, -1, "I Am A TextCtrl") # Add A CheckBox checkbox = wx.CheckBox(panel, -1, "3-State Checkbox", style=wx.CHK_3STATE | wx.CHK_ALLOW_3RD_STATE_FOR_USER) samplelist = [ 'One', 'Two', 'Three', 'Four', 'Kick', 'The', 'Demo', 'Out', 'The', 'Door', ';-)' ] # Add A Choice choice = wx.Choice(panel, -1, choices=samplelist) # Add A Gauge gauge = wx.Gauge(panel, -1, 50, style=wx.GA_SMOOTH) # Add A ListBox listbox = wx.ListBox(panel, -1, choices=samplelist, style=wx.LB_SINGLE) # Add A TreeCtrl isz = (16, 16) treecontrol = wx.TreeCtrl(panel, -1) il = wx.ImageList(isz[0], isz[1]) fldridx = il.Add( wx.ArtProvider.GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, isz)) fldropenidx = il.Add( wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN, wx.ART_OTHER, isz)) fileidx = il.Add( wx.ArtProvider.GetBitmap(wx.ART_REPORT_VIEW, wx.ART_OTHER, isz)) treecontrol.SetImageList(il) self.il = il root = treecontrol.AddRoot("ROOT") treecontrol.SetItemData(root, None) treecontrol.SetItemImage(root, fldridx, wx.TreeItemIcon_Normal) treecontrol.SetItemImage(root, fldropenidx, wx.TreeItemIcon_Expanded) for ii in range(11): child = treecontrol.AppendItem(root, samplelist[ii]) treecontrol.SetItemData(child, None) treecontrol.SetItemImage(child, fldridx, wx.TreeItemIcon_Normal) treecontrol.SetItemImage(child, fldropenidx, wx.TreeItemIcon_Selected) # Add A Slider slider = wx.Slider(panel, -1, 25, 1, 100, style=wx.SL_HORIZONTAL | wx.SL_AUTOTICKS) # | wx.SL_LABELS) slider.SetTickFreq(5) # Add Another TextCtrl textctrl2 = wx.TextCtrl(panel, -1, "Another TextCtrl") # Add A GenStaticText statictext = StaticText(panel, -1, "Hello World!") statictext.SetFont( wx.Font(9, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False)) bmp = wx.ArtProvider.GetBitmap(wx.ART_INFORMATION, wx.ART_TOOLBAR, (16, 16)) # Add A GenBitmapButton bitmapbutton = BitmapButton(panel, -1, bmp) button2 = wx.Button(panel, -1, "Disable BalloonTip") tbicon = TaskBarIcon() tbicon.SetIcon(wx.BitmapBundle(images.Mondrian.GetIcon())) controls = list(panel.GetChildren()) controls.append(tbicon) self.tbicon = tbicon # Add The Controls To The Main FlexGridSizer mainsizer.Add(button, 0, wx.EXPAND | wx.ALL, 10) mainsizer.Add(textctrl, 0, wx.EXPAND | wx.ALL, 10) mainsizer.Add(checkbox, 0, wx.EXPAND | wx.ALL, 10) mainsizer.Add(choice, 0, wx.EXPAND | wx.ALL, 10) mainsizer.Add(gauge, 0, wx.ALL, 10) mainsizer.Add(listbox, 0, wx.EXPAND | wx.ALL, 10) mainsizer.Add(treecontrol, 0, wx.EXPAND, wx.ALL, 10) mainsizer.Add(slider, 0, wx.ALL, 10) mainsizer.Add(textctrl2, 0, wx.ALL, 10) mainsizer.Add(statictext, 0, wx.EXPAND | wx.ALL, 10) mainsizer.Add(bitmapbutton, 0, wx.ALL, 10) mainsizer.Add(button2, 0, wx.ALL, 10) panel.SetSizer(mainsizer) mainsizer.Layout() # Declare The BalloonTip Background Colours bgcolours = [ None, wx.WHITE, wx.GREEN, wx.BLUE, wx.CYAN, wx.RED, None, None, wx.LIGHT_GREY, None, wx.WHITE, None, None ] # Declare The BalloonTip Top-Left Icons icons = [] for ii in range(4): bmp = wx.ArtProvider.GetBitmap(eval(ArtIDs[ii]), wx.ART_TOOLBAR, (16, 16)) icons.append(bmp) icons.extend([None] * 5) for ii in range(4, 9): bmp = wx.ArtProvider.GetBitmap(eval(ArtIDs[ii]), wx.ART_TOOLBAR, (16, 16)) icons.append(bmp) # Declare The BalloonTip Top Titles titles = [ "Button Help", "Texctrl Help", "CheckBox Help", "Choice Help", "Gauge Help", "", "", "Read Me Carefully!", "SpinCtrl Help", "StaticText Help", "BitmapButton Help", "Button Help", "Taskbar Help" ] fontone = wx.Font(9, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, True) fonttwo = wx.Font(14, wx.FONTFAMILY_SCRIPT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False) fontthree = wx.Font(9, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_ITALIC, wx.FONTWEIGHT_NORMAL, False) fontfour = wx.Font(8, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, True) # Declare The BalloonTip Top Titles Fonts titlefonts = [ None, None, fontone, None, fonttwo, fontthree, None, None, None, fontfour, fontthree, None, None ] # Declare The BalloonTip Top Titles Colours titlecolours = [ None, None, wx.WHITE, wx.YELLOW, None, wx.WHITE, wx.BLUE, wx.RED, None, None, wx.LIGHT_GREY, None, None ] # Declare The BalloonTip Messages msg1 = "This Is The Default BalloonTip Window\nYou Can Customize It! "\ "Look At The Demo!" msg2 = "You Can Change The Background Colour\n Of The Balloon Window." msg3 = "You Can Also Change The Font And The\nColour For The Title." msg4 = "I Have Nothing Special To Suggest!\n\nWelcome To wxPython " + \ wx.VERSION_STRING + " !" msg5 = "What About If I Don't Want The Icon?\nNo Problem!" msg6 = "I Don't Have The Icon Nor The Title.\n\nDo You Love Me Anyway?" msg7 = "Some Comments On The Window Shape:\n\n- BT_ROUNDED: Creates A "\ "Rounded Rectangle;\n- BT_RECTANGLE: Creates A Rectangle.\n" msg8 = "Some Comments On The BalloonTip Style:\n\n"\ "BT_LEAVE: The BalloonTip Is Destroyed When\nThe Mouse Leaves"\ "The Target Widget;\n\nBT_CLICK: The BalloonTip Is Destroyed When\n"\ "You Click Any Region Of The BalloonTip;\n\nBT_BUTTON: The BalloonTip"\ " Is Destroyed When\nYou Click On The Top-Right Small Button." msg9 = "Some Comments On Delay Time:\n\nBy Default, The Delay Time After Which\n"\ "The BalloonTip Is Destroyed Is Very Long.\nYou Can Change It By Using"\ " The\nSetEndDelay() Method." msg10 = "I Have Nothing Special To Suggest!\n\nRead Me FAST, You Have Only 3 "\ "Seconds!" msg11 = "I Hope You Will Enjoy BalloonTip!\nIf This Is The Case, Please\n"\ "Post Some Comments On wxPython\nMailing List!" msg12 = "This Button Enable/Disable Globally\nThe BalloonTip On Your Application." msg13 = "This Is A BalloonTip For The\nTaskBar Icon Of Your Application.\n"\ "All The Styles For BalloonTip Work." messages = [ msg1, msg2, msg3, msg4, msg5, msg6, msg7, msg8, msg9, msg10, msg11, msg12, msg13 ] # Declare The BalloonTip Tip Messages Colours messagecolours = [ None, None, None, wx.WHITE, wx.BLUE, None, wx.BLUE, None, None, wx.RED, wx.GREEN, wx.BLUE, None ] fontone = wx.Font(8, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, True) fonttwo = wx.Font(8, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_ITALIC, wx.FONTWEIGHT_NORMAL, False) fontthree = wx.Font(8, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, True) # Declare The BalloonTip Tip Messages Fonts messagefonts = [ None, None, None, fontone, None, None, fonttwo, None, fontthree, None, None, None, None ] # Declare The BalloonTip Frame Shapes windowshapes = [ BT.BT_ROUNDED, BT.BT_RECTANGLE, BT.BT_ROUNDED, BT.BT_RECTANGLE, BT.BT_ROUNDED, BT.BT_RECTANGLE, BT.BT_ROUNDED, BT.BT_ROUNDED, BT.BT_ROUNDED, BT.BT_RECTANGLE, BT.BT_ROUNDED, BT.BT_RECTANGLE, BT.BT_RECTANGLE ] # Declare The BalloonTip Destruction Style tipstyles = [ BT.BT_LEAVE, BT.BT_CLICK, BT.BT_BUTTON, BT.BT_LEAVE, BT.BT_CLICK, BT.BT_LEAVE, BT.BT_CLICK, BT.BT_BUTTON, BT.BT_BUTTON, BT.BT_CLICK, BT.BT_LEAVE, BT.BT_LEAVE, BT.BT_BUTTON ] # Set The Targets/Styles For The BalloonTip for ii, widget in enumerate(controls): tipballoon = BT.BalloonTip(topicon=icons[ii], toptitle=titles[ii], message=messages[ii], shape=windowshapes[ii], tipstyle=tipstyles[ii]) # Set The Target tipballoon.SetTarget(widget) # Set The Balloon Colour tipballoon.SetBalloonColour(bgcolours[ii]) # Set The Font For The Top Title tipballoon.SetTitleFont(titlefonts[ii]) # Set The Colour For The Top Title tipballoon.SetTitleColour(titlecolours[ii]) # Set The Font For The Tip Message tipballoon.SetMessageFont(messagefonts[ii]) # Set The Colour For The Tip Message tipballoon.SetMessageColour(messagecolours[ii]) # Set The Delay After Which The BalloonTip Is Created tipballoon.SetStartDelay(1000) if ii == 9: # Set The Delay After Which The BalloonTip Is Destroyed tipballoon.SetEndDelay(3000) # Store The Last BalloonTip Reference To Enable/Disable Globall The # BalloonTip. You Can Store Any Of Them, Not Necessarily The Last One. self.lasttip = tipballoon self.gauge = gauge self.count = 0 button2.Bind(wx.EVT_BUTTON, self.OnActivateBalloon) self.Bind(wx.EVT_IDLE, self.IdleHandler) frameSizer = wx.BoxSizer(wx.VERTICAL) frameSizer.Add(panel, 1, wx.EXPAND) self.SetSizer(frameSizer) frameSizer.Layout() self.Fit() self.CenterOnParent()
def test_dataviewIconText2(self): icon = wx.Icon(pngFile) dit = dv.DataViewIconText('Smile!', wx.BitmapBundle(icon)) dit.Icon dit.Text
def test_BitmapBundleCtor4(self): b4 = wx.BitmapBundle(wx.Image(pngFile)) self.assertTrue(b4.IsOk())
def test_BitmapBundleCtor3(self): b3 = wx.BitmapBundle(wx.Icon(icoFile)) self.assertTrue(b3.IsOk())
def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition, size=wx.DefaultSize, style=0, name='InfoBar'): """ Default class constructor. :param `parent`: parent window. Must not be ``None``; :param integer `id`: window identifier. A value of -1 indicates a default value; :param `pos`: the control position. A value of (-1, -1) indicates a default position, chosen by either the windowing system or wxPython, depending on platform; :type `pos`: tuple or :class:`wx.Point` :param `size`: the control size. A value of (-1, -1) indicates a default size, chosen by either the windowing system or wxPython, depending on platform; :type `size`: tuple or :class:`wx.Size` :param integer `style`: the :class:`InfoBar` style (unused at present); :param string `name`: the control name. """ wx.Control.__init__(self, parent, id, pos, size, style | wx.BORDER_NONE, name=name) self.SetInitialSize(size) self.Init() # calling Hide() before Create() ensures that we're created initially # hidden self.Hide() # use special, easy to notice, colours colBg = wx.SystemSettings.GetColour(wx.SYS_COLOUR_INFOBK) self.SetBackgroundColour(colBg) self.SetOwnForegroundColour( wx.SystemSettings.GetColour(wx.SYS_COLOUR_INFOTEXT)) # create the controls: icon,text and the button to dismiss the # message. # the icon is not shown unless it's assigned a valid bitmap self._icon = wx.StaticBitmap(self, wx.ID_ANY, wx.NullBitmap) self._text = AutoWrapStaticText(self, "") if wx.Platform == '__WXGTK__': bmp = wx.ArtProvider.GetBitmap(wx.ART_CLOSE, wx.ART_BUTTON) else: # THIS CRASHES PYTHON ALTOGETHER!! # sizeBmp = wx.ArtProvider.GetSizeHint(wx.ART_BUTTON) sizeBmp = (16, 16) bmp = GetCloseButtonBitmap(self, sizeBmp, colBg) self._button = wx.BitmapButton(self, wx.ID_ANY, bmp, style=wx.BORDER_NONE) if wx.Platform != '__WXGTK__': self._button.SetBitmapPressed( wx.BitmapBundle( GetCloseButtonBitmap(self, sizeBmp, colBg, wx.CONTROL_PRESSED))) self._button.SetBitmapCurrent( wx.BitmapBundle( GetCloseButtonBitmap(self, sizeBmp, colBg, wx.CONTROL_CURRENT))) self._button.SetBackgroundColour(colBg) self._button.SetToolTip(_("Hide this notification message.")) # center the text inside the sizer with an icon to the left of it and a # button at the very right # # NB: AddButton() relies on the button being the last control in the sizer # and being preceded by a spacer sizer = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(self._icon, wx.SizerFlags().Centre().Border()) sizer.Add(self._text, 200, wx.ALIGN_CENTER_VERTICAL) sizer.AddStretchSpacer() sizer.Add(self._button, wx.SizerFlags().Centre().Border()) self.SetSizer(sizer) self.Bind(wx.EVT_BUTTON, self.OnButton)
def __init__(self, parent, log): wx.Frame.__init__(self, parent, -1, 'Test ToolBar', size=(600, 400)) self.log = log self.timer = None self.Bind(wx.EVT_CLOSE, self.OnCloseWindow) client = wx.Panel(self) client.SetBackgroundColour(wx.WHITE) if FRAMETB: # Use the wxFrame internals to create the toolbar and # associate it all in one tidy method call. By using # CreateToolBar or SetToolBar the "client area" of the # frame will be adjusted to exclude the toolbar. tb = self.CreateToolBar(TBFLAGS) # Here's a 'simple' toolbar example, and how to bind it using SetToolBar() #tb = wx.ToolBarSimple(self, -1, wx.DefaultPosition, wx.DefaultSize, # wx.TB_HORIZONTAL | wx.NO_BORDER | wx.TB_FLAT) #self.SetToolBar(tb) # But we're doing it a different way here. else: # The toolbar can also be a child of another widget, and # be managed by a sizer, although there may be some # implications of doing this on some platforms. tb = wx.ToolBar(client, style=TBFLAGS) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(tb, 0, wx.EXPAND) client.SetSizer(sizer) log.write("Default toolbar tool size: %s\n" % tb.GetToolBitmapSize()) self.CreateStatusBar() tsize = (24, 24) new_bmp = wx.ArtProvider.GetBitmapBundle(wx.ART_NEW, wx.ART_TOOLBAR, tsize) open_bmp = wx.ArtProvider.GetBitmapBundle(wx.ART_FILE_OPEN, wx.ART_TOOLBAR, tsize) copy_bmp = wx.ArtProvider.GetBitmapBundle(wx.ART_COPY, wx.ART_TOOLBAR, tsize) paste_bmp = wx.ArtProvider.GetBitmapBundle(wx.ART_PASTE, wx.ART_TOOLBAR, tsize) null_bmp = wx.BitmapBundle(wx.NullBitmap) tb.SetToolBitmapSize(tsize) #tb.AddTool(10, new_bmp, "New", "Long help for 'New'") tb.AddTool(10, "New", new_bmp, null_bmp, wx.ITEM_NORMAL, "New", "Long help for 'New'", None) self.Bind(wx.EVT_TOOL, self.OnToolClick, id=10) self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=10) #tb.AddTool(20, open_bmp, "Open", "Long help for 'Open'") tb.AddTool(20, "Open", open_bmp, null_bmp, wx.ITEM_NORMAL, "Open", "Long help for 'Open'", None) self.Bind(wx.EVT_TOOL, self.OnToolClick, id=20) self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=20) tb.AddSeparator() tb.AddTool(30, "Copy", copy_bmp, null_bmp, wx.ITEM_NORMAL, "Copy", "Long help for 'Copy'", None) self.Bind(wx.EVT_TOOL, self.OnToolClick, id=30) self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=30) tb.AddTool(40, "Paste", paste_bmp, null_bmp, wx.ITEM_NORMAL, "Paste", "Long help for 'Paste'", None) self.Bind(wx.EVT_TOOL, self.OnToolClick, id=40) self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=40) tb.AddSeparator() #tool = tb.AddCheckTool(50, images.Tog1.GetBitmap(), shortHelp="Toggle this") tool = tb.AddTool(50, "Checkable", wx.BitmapBundle(images.Tog1.GetBitmap()), shortHelp="Toggle this", kind=wx.ITEM_CHECK) self.Bind(wx.EVT_TOOL, self.OnToolClick, id=50) self.Bind(wx.EVT_TOOL_ENTER, self.OnToolEnter) self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick) # Match all self.Bind(wx.EVT_TIMER, self.OnClearSB) tb.AddSeparator() cbID = wx.NewIdRef() tb.AddControl( wx.ComboBox(tb, cbID, "", choices=["", "This", "is a", "wx.ComboBox"], size=(150, -1), style=wx.CB_DROPDOWN)) self.Bind(wx.EVT_COMBOBOX, self.OnCombo, id=cbID) tb.AddStretchableSpace() search = TestSearchCtrl(tb, size=(150, -1), doSearch=self.DoSearch) tb.AddControl(search) # Final thing to do for a toolbar is call the Realize() method. This # causes it to render (more or less, that is). tb.Realize()
def test_bannerwindow1(self): banner = wx.adv.BannerWindow(self.frame, dir=wx.LEFT) banner.SetBitmap(wx.BitmapBundle(wx.Bitmap(pngFile)))
def test_menuitemCtor(self): m1 = wx.MenuItem() m2 = wx.MenuItem(None, -1, "Menu Item", "Help text", wx.ITEM_NORMAL) m2.SetBitmap(wx.BitmapBundle(wx.Bitmap(pngFile)))
def test_tglbtnCtors(self): btn = wx.ToggleButton(self.frame, label='label') btn = wx.ToggleButton(self.frame, -1, 'label', (10, 10), (100, -1), wx.BU_LEFT) bmp = wx.BitmapBundle(wx.Bitmap(pngFile)) btn.SetBitmap(bmp)
def test_BitmapBundleCtor2(self): b2 = wx.BitmapBundle(wx.Bitmap(5, 10, 32)) self.assertTrue(b2.IsOk())
def CreateColorBitmapBundle(self, c): return wx.BitmapBundle(self.CreateColorBitmap(c))
def _buildOutputSections(self, sizer): internalSizer = wx.BoxSizer(wx.VERTICAL) cliLabel = wx.StaticText(self, label="KiKit CLI command:", size=wx.DefaultSize, style=wx.ALIGN_LEFT) internalSizer.Add(cliLabel, 0, wx.EXPAND | wx.ALL, 2) self.platformSelector = wx.Choice(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, PLATFORMS, 0) if os.name == "nt": self.platformSelector.SetSelection(PLATFORMS.index("Windows")) else: self.platformSelector.SetSelection(0) # Choose posix by default self.platformSelector.Bind(wx.EVT_CHOICE, lambda evt: self.buildOutputSections()) internalSizer.Add(self.platformSelector, 0, wx.EXPAND | wx.ALL, 2) self.kikitCmdWidget = wx.TextCtrl(self, wx.ID_ANY, "KiKit Command", wx.DefaultPosition, wx.DefaultSize, wx.TE_MULTILINE | wx.TE_READONLY) self.kikitCmdWidget.SetSizeHints( wx.Size(self.maxDialogSize.width, self.maxDialogSize.height // 2), wx.Size(self.maxDialogSize.width, -1)) cmdFont = self.kikitCmdWidget.GetFont() cmdFont.SetFamily(wx.FONTFAMILY_TELETYPE) self.kikitCmdWidget.SetFont(cmdFont) internalSizer.Add(self.kikitCmdWidget, 0, wx.EXPAND | wx.ALL, 2) jsonLabel = wx.StaticText( self, label="KiKit JSON preset (contains only changed keys):", size=wx.DefaultSize, style=wx.ALIGN_LEFT) internalSizer.Add(jsonLabel, 0, wx.EXPAND | wx.ALL, 2) self.kikitJsonWidget = wx.TextCtrl(self, wx.ID_ANY, "KiKit JSON", wx.DefaultPosition, wx.DefaultSize, wx.TE_MULTILINE | wx.TE_READONLY) self.kikitJsonWidget.SetSizeHints( wx.Size(self.maxDialogSize.width, self.maxDialogSize.height // 2), wx.Size(self.maxDialogSize.width, -1)) cmdFont = self.kikitJsonWidget.GetFont() cmdFont.SetFamily(wx.FONTFAMILY_TELETYPE) self.kikitJsonWidget.SetFont(cmdFont) internalSizer.Add(self.kikitJsonWidget, 0, wx.EXPAND | wx.ALL, 2) ieButtonsSizer = wx.BoxSizer(wx.HORIZONTAL) ieButtonsSizer.Add((0, 0), 1, wx.EXPAND, 5) self.importButton = wx.Button(self, wx.ID_ANY, u"Import JSON configuration", wx.DefaultPosition, wx.DefaultSize, 0) try: self.importButton.SetBitmap( wx.BitmapBundle(wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN))) except: self.importButton.SetBitmap( wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN)) ieButtonsSizer.Add(self.importButton, 0, wx.ALL, 5) self.importButton.Bind(wx.EVT_BUTTON, self.onImport) self.exportButton = wx.Button(self, wx.ID_ANY, u"Export JSON configuration", wx.DefaultPosition, wx.DefaultSize, 0) try: self.exportButton.SetBitmap( wx.BitmapBundle(wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE))) except: self.exportButton.SetBitmap( wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE)) ieButtonsSizer.Add(self.exportButton, 0, wx.ALL, 5) self.exportButton.Bind(wx.EVT_BUTTON, self.onExport) internalSizer.Add(ieButtonsSizer, 1, wx.EXPAND, 5) sizer.Add(internalSizer, 0, wx.EXPAND | wx.ALL, 2)
def test_BitmapBundleCtor1(self): b1 = wx.BitmapBundle() self.assertTrue(not b1.IsOk())
def test_taskbar1(self): icon = wx.adv.TaskBarIcon(wx.adv.TBI_DOCK) icon.SetIcon(wx.BitmapBundle(wx.Icon(icoFile)), "The tip string") self.assertTrue(icon.IsOk()) icon.Destroy() self.myYield()