def initialize_bitmaps(self): """ Initializes the check bitmaps. """ # We keep 4 bitmaps for CustomCheckBox, depending on the # checking state (Checked/UnCkecked) and the control # state (Enabled/Disabled). # FIXME: no such image self._bitmaps = { "CheckedEnable": img.getBitmap("btn_16x16.png"), "UnCheckedEnable": img.getBitmap("btn_16x16.png"), "CheckedDisable": grayOut(img.getImage("btn_16x16.png")), "UnCheckedDisable": grayOut(img.getImage("btn_16x16.png")) }
def _add_button(self, cls, img_prefix, tooltip=None): bmp = img.getBitmap("menu/" + img_prefix + ".png") bmpa = img.getBitmap("menu/" + img_prefix + "_a.png") bmph = img.getBitmap("menu/" + img_prefix + "_h.png") dimg = img.getImage("menu/" + img_prefix + ".png") darken_image(dimg, 0.5) bmpd = dimg.ConvertToBitmap() btn = cls(self.btn_panel, bitmap=bmp, size=(24, 24)) btn.bmpSelected = bmpa btn.bmpHover = bmph btn.bmpDisabled = bmpd if tooltip: btn.SetToolTip(tooltip) if self.orientation == wx.HORIZONTAL: f = wx.LEFT | wx.RIGHT | wx.TOP b = 5 else: f = wx.TOP | wx.BOTTOM | wx.ALIGN_CENTRE_HORIZONTAL b = 5 self.btn_sizer.Add(btn, border=b, flag=f) self.btn_panel.Layout() return btn
def _getBtnImage(self, colour, height, state): """ colour (str) height (int) state (str): "on" or "off" """ if state == "off": fn = "button/btn_%s_%d.png" % (colour, height) else: fn = "button/btn_%s_%d_a.png" % (colour, height) return img.getImage(fn)
def __init__(self, *args, **kwargs): kwargs['bitmap'] = img.getBitmap("overview_add.png") super(PlusImageButton, self).__init__(*args, **kwargs) self.SetForegroundColour(wx.WHITE) self.bmpSelected = img.getBitmap("overview_add_a.png") self.bmpHover = img.getBitmap("overview_add_h.png") btn_img = img.getImage("overview_add.png") darken_image(btn_img, 0.8) self.bmpDisabled = wx.Bitmap(btn_img)
def _add_button(self, tool_id, cls, img_prefix, tooltip=None): bmp = img.getBitmap("menu/" + img_prefix + ".png") bmpa = img.getBitmap("menu/" + img_prefix + "_a.png") bmph = img.getBitmap("menu/" + img_prefix + "_h.png") dimg = img.getImage("menu/" + img_prefix + ".png") darken_image(dimg, 0.5) bmpd = dimg.ConvertToBitmap() btn = cls(self.btn_panel, bitmap=bmp, size=(24, 24)) btn.bmpSelected = bmpa btn.bmpHover = bmph btn.bmpDisabled = bmpd if tooltip: btn.SetToolTip(tooltip) if self.orientation == (wx.VERTICAL | wx.HORIZONTAL): # Ideal position for the known tools pos = { TOOL_RULER: (0, 0), TOOL_LABEL: (1, 0), TOOL_POINT: (0, 1), TOOL_LINE: (1, 1), TOOL_ACT_ZOOM_FIT: (2, 1) }.get(tool_id) # Unknown tool, or position already used => pick the first position available if not pos or self.btn_sizer.FindItemAtPosition(pos): for p in itertools.product( range(8), range(2)): # max 8 (height) x 2 (width) if not self.btn_sizer.FindItemAtPosition(p): pos = p break else: raise ValueError("No more space in toolbar") self.btn_sizer.Add(btn, pos, border=5, flag=wx.LEFT | wx.BOTTOM | wx.ALIGN_CENTRE_HORIZONTAL) elif self.orientation == wx.VERTICAL: self.btn_sizer.Add(btn, border=5, flag=wx.TOP | wx.BOTTOM | wx.ALIGN_CENTRE_HORIZONTAL) else: # wx.HORIZONTAL self.btn_sizer.Add(btn, border=5, flag=wx.LEFT | wx.RIGHT | wx.TOP) self.btn_panel.Layout() return btn
def _add_background(self): self._background_id = glGenTextures(1) glBindTexture(GL_TEXTURE_2D, self._background_id) im = img.getImage("canvasbg.png") w, h = self._bg_size = im.GetSize() glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, im.GetData()) glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
def __init__(self, *args, **kwargs): kwargs['bitmap'] = img.getBitmap("stream_add.png") super(PopupImageButton, self).__init__(*args, **kwargs) self.SetForegroundColour(wx.WHITE) self.bmpSelected = img.getBitmap("stream_add_a.png") self.bmpHover = img.getBitmap("stream_add_h.png") btn_img = img.getImage("stream_add.png") darken_image(btn_img, 0.8) self.bmpDisabled = wx.BitmapFromImage(btn_img) self.choices = {} self.menu = wx.Menu() self.Bind(wx.EVT_BUTTON, self.show_menu) self.Disable()
def __init__(self, *args, **kwargs): kwargs['bitmap'] = img.getBitmap("stream_add.png") super(PopupImageButton, self).__init__(*args, **kwargs) self.SetForegroundColour(wx.WHITE) self.bmpSelected = img.getBitmap("stream_add_a.png") self.bmpHover = img.getBitmap("stream_add_h.png") btn_img = img.getImage("stream_add.png") darken_image(btn_img, 0.8) self.bmpDisabled = wx.Bitmap(btn_img) self.choices = {} self.menu = wx.Menu() self.Bind(wx.EVT_BUTTON, self.show_menu) self.Disable()
def __init__(self, *args, **kwargs): labels = kwargs.pop('labels', []) choices = kwargs.pop('choices', []) super(ComboBox, self).__init__(*args, **kwargs) # SetMargins allow the left margin to be set to 0, but the top # margin won't move and stays at the default -1. self.SetMargins(0, 0) self.SetForegroundColour(odemis.gui.FG_COLOUR_EDIT) # Use the same colour as the parent (by default) # HACK: there seems to be a bug in wxWidgets (v3.0.2), where # OwnerDrawnComboBox.GetBackgroundColour() always returns the same fixed # colour (in init?). So we cannot rely on it. bckcol = self.Parent.GetBackgroundColour() self.SetBackgroundColour(bckcol) icon = img.getBitmap("icon/arr_down_s.png") icon_x = 16 // 2 - icon.GetWidth() // 2 icon_y = 16 // 2 - icon.GetHeight() // 2 - 1 bmpLabel = ImageButton._create_bitmap( img.getImage("button/btn_def_16.png"), (16, 16), bckcol) dc = wx.MemoryDC() dc.SelectObject(bmpLabel) dc.DrawBitmap(icon, icon_x, icon_y) dc.SelectObject(wx.NullBitmap) hover_image = bmpLabel.ConvertToImage() darken_image(hover_image, 1.1) dis_image = bmpLabel.ConvertToImage() darken_image(dis_image, 0.8) orig_image = bmpLabel.ConvertToImage() darken_image(orig_image, 1.0) self.SetButtonBitmaps(orig_image.ConvertToBitmap(), bmpHover=hover_image.ConvertToBitmap(), bmpDisabled=dis_image.ConvertToBitmap(), pushButtonBg=False) # Convert losing the focus into accepting the new value typed in # (generates EVT_TEXT_ENTER). self._prev_text = None self._text_changed = False self.Bind(wx.EVT_TEXT, self._on_text) self.Bind(wx.EVT_COMBOBOX, self._on_text_enter) self.Bind(wx.EVT_TEXT_ENTER, self._on_text_enter) self.Bind(wx.EVT_KILL_FOCUS, self._on_focus) self.Bind(wx.EVT_PAINT, self.on_paint) # If no labels are provided, create them from the choices if not labels and choices: labels = [str(c) for c in choices] for label, choice in zip(labels, choices): self.Append(label, choice) def _eat_event(evt): """ Quick and dirty empty function used to 'eat' mouse wheel events """ # TODO: This solution only makes sure that the control's value # doesn't accidentally get altered when it gets hit by a mouse # wheel event. However, it also stop the event from propagating # so the containing scrolled window will not scroll either. # (If the event is skipped, the control will change value again) # No easy fix found in wxPython 3.0. pass self.Bind(wx.EVT_MOUSEWHEEL, _eat_event)
def __init__(self, *args, **kwargs): labels = kwargs.pop('labels', []) choices = kwargs.pop('choices', []) super(ComboBox, self).__init__(*args, **kwargs) # SetMargins allow the left margin to be set to 0, but the top # margin won't move and stays at the default -1. self.SetMargins(0, 0) self.SetForegroundColour(odemis.gui.FG_COLOUR_EDIT) # Use the same colour as the parent (by default) # HACK: there seems to be a bug in wxWidgets (v3.0.2), where # OwnerDrawnComboBox.GetBackgroundColour() always returns the same fixed # colour (in init?). So we cannot rely on it. bckcol = self.Parent.GetBackgroundColour() self.SetBackgroundColour(bckcol) icon = img.getBitmap("icon/arr_down_s.png") icon_x = 16 // 2 - icon.GetWidth() // 2 icon_y = 16 // 2 - icon.GetHeight() // 2 - 1 bmpLabel = ImageButton._create_bitmap(img.getImage("button/btn_def_16.png"), (16, 16), bckcol) dc = wx.MemoryDC() dc.SelectObject(bmpLabel) dc.DrawBitmap(icon, icon_x, icon_y) dc.SelectObject(wx.NullBitmap) hover_image = bmpLabel.ConvertToImage() darken_image(hover_image, 1.1) dis_image = bmpLabel.ConvertToImage() darken_image(dis_image, 0.8) orig_image = bmpLabel.ConvertToImage() darken_image(orig_image, 1.0) self.SetButtonBitmaps(orig_image.ConvertToBitmap(), bmpHover=hover_image.ConvertToBitmap(), bmpDisabled=dis_image.ConvertToBitmap(), pushButtonBg=False) # Convert losing the focus into accepting the new value typed in # (generates EVT_TEXT_ENTER). self._prev_text = None self._text_changed = False self.Bind(wx.EVT_TEXT, self._on_text) self.Bind(wx.EVT_COMBOBOX, self._on_text_enter) self.Bind(wx.EVT_TEXT_ENTER, self._on_text_enter) self.Bind(wx.EVT_KILL_FOCUS, self._on_focus) self.Bind(wx.EVT_PAINT, self.on_paint) # If no labels are provided, create them from the choices if not labels and choices: labels = [unicode(c) for c in choices] for label, choice in zip(labels, choices): self.Append(label, choice) def _eat_event(evt): """ Quick and dirty empty function used to 'eat' mouse wheel events """ # TODO: This solution only makes sure that the control's value # doesn't accidentally get altered when it gets hit by a mouse # wheel event. However, it also stop the event from propagating # so the containing scrolled window will not scroll either. # (If the event is skipped, the control will change value again) # No easy fix found in wxPython 3.0. pass self.Bind(wx.EVT_MOUSEWHEEL, _eat_event)