Python wx.ToggleButton() Examples
The following are 9
code examples of wx.ToggleButton().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
wx
, or try the search function
.
Example #1
Source File: backend_wx.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def add_toolitem( self, name, group, position, image_file, description, toggle): before, group = self._add_to_group(group, name, position) idx = self.GetToolPos(before.Id) if image_file: bmp = _load_bitmap(image_file) kind = wx.ITEM_NORMAL if not toggle else wx.ITEM_CHECK tool = self.InsertTool(idx, -1, name, bmp, wx.NullBitmap, kind, description or "") else: size = (self.GetTextExtent(name)[0]+10, -1) if toggle: control = wx.ToggleButton(self, -1, name, size=size) else: control = wx.Button(self, -1, name, size=size) tool = self.InsertControl(idx, control, label=name) self.Realize() def handler(event): self.trigger_tool(name) if image_file: self.Bind(wx.EVT_TOOL, handler, tool) else: control.Bind(wx.EVT_LEFT_DOWN, handler) self._toolitems.setdefault(name, []) group.insert(position, tool) self._toolitems[name].append((tool, handler))
Example #2
Source File: backend_wx.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def add_toolitem( self, name, group, position, image_file, description, toggle): before, group = self._add_to_group(group, name, position) idx = self.GetToolPos(before.Id) if image_file: bmp = _load_bitmap(image_file) kind = wx.ITEM_NORMAL if not toggle else wx.ITEM_CHECK tool = self.InsertTool(idx, -1, name, bmp, wx.NullBitmap, kind, description or "") else: size = (self.GetTextExtent(name)[0]+10, -1) if toggle: control = wx.ToggleButton(self, -1, name, size=size) else: control = wx.Button(self, -1, name, size=size) tool = self.InsertControl(idx, control, label=name) self.Realize() def handler(event): self.trigger_tool(name) if image_file: self.Bind(wx.EVT_TOOL, handler, tool) else: control.Bind(wx.EVT_LEFT_DOWN, handler) self._last = tool self._toolitems.setdefault(name, []) group.insert(position, tool) self._toolitems[name].append((tool, handler))
Example #3
Source File: backend_wx.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def add_toolitem( self, name, group, position, image_file, description, toggle): before, group = self._add_to_group(group, name, position) idx = self.GetToolPos(before.Id) if image_file: bmp = _load_bitmap(image_file) kind = wx.ITEM_NORMAL if not toggle else wx.ITEM_CHECK tool = self.InsertTool(idx, -1, name, bmp, wx.NullBitmap, kind, description or "") else: size = (self.GetTextExtent(name)[0]+10, -1) if toggle: control = wx.ToggleButton(self, -1, name, size=size) else: control = wx.Button(self, -1, name, size=size) tool = self.InsertControl(idx, control, label=name) self.Realize() def handler(event): self.trigger_tool(name) if image_file: self.Bind(wx.EVT_TOOL, handler, tool) else: control.Bind(wx.EVT_LEFT_DOWN, handler) self._last = tool self._toolitems.setdefault(name, []) group.insert(position, tool) self._toolitems[name].append((tool, handler))
Example #4
Source File: main.py From wxGlade with MIT License | 5 votes |
def __init__(self, parent): wx.Panel.__init__(self, parent) common.palette = self # for building the buttons self.SetBackgroundColour( compat.wx_SystemSettings_GetColour(wx.SYS_COLOUR_BTNFACE) ) # load the available code generators all_widgets = common.init_codegen() if not config.use_gui: return self.all_togglebuttons = [] # used by reset_togglebuttons # for keyboard navigation: self._id_to_coordinate = {} self._ids_by_row = [] self._section_to_row = {} # build the palette for all_widgets sizer = wx.FlexGridSizer(0, 2, 0, 0) maxlen = max([len(all_widgets[sect]) for sect in all_widgets]) # the maximum number of buttons in a section for row, section in enumerate(all_widgets): self._section_to_row[section] = row self._ids_by_row.append([]) if section: label = wx.StaticText(self, -1, "%s:" % section.replace('&', '&&')) sizer.Add( label, 1, wx.ALIGN_CENTER_VERTICAL | wx.LEFT, 2 ) bsizer = wx.BoxSizer() for col, button in enumerate(all_widgets[section]): self._ids_by_row[-1].append(button.Id) self._id_to_coordinate[button.Id] = (row,col) bsizer.Add(button, flag=wx.ALL, border=1) if isinstance(button, wx.ToggleButton): self.all_togglebuttons.append(button) sizer.Add(bsizer) self.SetSizer(sizer) # on platforms other than Windows, we'll set the ToggleButton background colour to indicate the selection if wx.Platform == "__WXMSW__": self._highlight_colour = None else: self._highlight_colour = wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHT) self.Bind(wx.EVT_CHAR_HOOK, self.on_char)
Example #5
Source File: toggle_button.py From wxGlade with MIT License | 5 votes |
def create_widget(self): self.widget = wx.ToggleButton(self.parent_window.widget, self.id, self.label) self.widget.SetValue(self.value) self.widget.Bind(wx.EVT_TOGGLEBUTTON, self.on_set_focus, id=self.id) BitmapMixin._set_preview_bitmaps(self)
Example #6
Source File: backend_wx.py From coffeegrindsize with MIT License | 5 votes |
def add_toolitem( self, name, group, position, image_file, description, toggle): before, group = self._add_to_group(group, name, position) idx = self.GetToolPos(before.Id) if image_file: bmp = _load_bitmap(image_file) kind = wx.ITEM_NORMAL if not toggle else wx.ITEM_CHECK tool = self.InsertTool(idx, -1, name, bmp, wx.NullBitmap, kind, description or "") else: size = (self.GetTextExtent(name)[0]+10, -1) if toggle: control = wx.ToggleButton(self, -1, name, size=size) else: control = wx.Button(self, -1, name, size=size) tool = self.InsertControl(idx, control, label=name) self.Realize() def handler(event): self.trigger_tool(name) if image_file: self.Bind(wx.EVT_TOOL, handler, tool) else: control.Bind(wx.EVT_LEFT_DOWN, handler) self._last = tool self._toolitems.setdefault(name, []) group.insert(position, tool) self._toolitems[name].append((tool, handler))
Example #7
Source File: backend_wx.py From CogAlg with MIT License | 5 votes |
def add_toolitem( self, name, group, position, image_file, description, toggle): before, group = self._add_to_group(group, name, position) idx = self.GetToolPos(before.Id) if image_file: bmp = _load_bitmap(image_file) kind = wx.ITEM_NORMAL if not toggle else wx.ITEM_CHECK tool = self.InsertTool(idx, -1, name, bmp, wx.NullBitmap, kind, description or "") else: size = (self.GetTextExtent(name)[0]+10, -1) if toggle: control = wx.ToggleButton(self, -1, name, size=size) else: control = wx.Button(self, -1, name, size=size) tool = self.InsertControl(idx, control, label=name) self.Realize() def handler(event): self.trigger_tool(name) if image_file: self.Bind(wx.EVT_TOOL, handler, tool) else: control.Bind(wx.EVT_LEFT_DOWN, handler) self._toolitems.setdefault(name, []) group.insert(position, tool) self._toolitems[name].append((tool, handler))
Example #8
Source File: ForceVariableDialog.py From OpenPLC_Editor with GNU General Public License v3.0 | 5 votes |
def InitCtrlBool(self, info_sizer, defaultValue): """Add button to change value of boolean variable""" self.ValueCtrl = wx.ToggleButton(self, label=_("Toggle value")) value = GetTypeValue[self.IEC_Type](defaultValue) if value is not None: self.ValueCtrl.SetValue(value) info_sizer.AddWindow(self.ValueCtrl, border=10, flag=wx.ALIGN_LEFT | wx.GROW | wx.TOP | wx.LEFT | wx.RIGHT | wx.GROW)
Example #9
Source File: common.py From wxGlade with MIT License | 4 votes |
def make_object_button(widget, icon_path, toplevel=False, tip=None): """Creates a button for the widgets toolbar. Function used by the various widget modules to add a button to the widgets toolbar. Icons with a relative path will be loaded from config.icon_path. widget: (name of) the widget the button will add to the app icon_path: Path to the icon_path used for the button toplevel: True if the widget is a toplevel object (frame, dialog) tip: Tool tip to display return: The newly created wxBitmapButton instance""" if not config.use_gui: return None import wx import misc from tree import WidgetTree if not os.path.isabs(icon_path): icon_path = os.path.join(config.icons_path, icon_path) bmp = misc.get_xpm_bitmap(icon_path) label = widget.replace('Edit', '') if compat.version < (3,0): # old wx version: use BitmapButton tmp = wx.BitmapButton(palette, -1, bmp, size=(31,31)) if not toplevel: tmp.Bind(wx.EVT_BUTTON, add_object) else: tmp.Bind(wx.EVT_BUTTON, add_toplevel_object) else: # for more recent versions, we support config options to display icons and/or labels if not toplevel: if not config.preferences.show_palette_labels: # icons only -> set size tmp = wx.ToggleButton(palette, -1, size=(31,31), name=label) else: tmp = wx.ToggleButton(palette, -1, label, name=label ) tmp.Bind(wx.EVT_TOGGLEBUTTON, add_object) else: if not config.preferences.show_palette_labels: tmp = wx.Button(palette, -1, size=(31,31), name=label) else: tmp = wx.Button(palette, -1, label, name=label ) tmp.Bind(wx.EVT_BUTTON, add_toplevel_object) if config.preferences.show_palette_icons: tmp.SetBitmap( bmp ) refs[tmp.GetId()] = widget if not tip: tip = _('Add a %s') % label tmp.SetToolTip(wx.ToolTip(tip)) WidgetTree.images[widget] = icon_path return tmp