Пример #1
0
    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
Пример #2
0
    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
Пример #3
0
    def _add_button(self, cls, img_prefix, tooltip=None):
        bmp = img.data.catalog[img_prefix].GetBitmap()
        bmpa = img.data.catalog[img_prefix + "_a"].GetBitmap()
        bmph = img.data.catalog[img_prefix + "_h"].GetBitmap()

        dimg = img.data.catalog[img_prefix].GetImage()
        darken_image(dimg, 0.3)
        bmpd = dimg.ConvertToBitmap()

        btn = cls(self.btn_panel, bitmap=bmp, size=(24, 24))
        btn.SetBitmapSelected(bmpa)
        btn.SetBitmapHover(bmph)
        btn.SetBitmapDisabled(bmpd)

        if tooltip:
            btn.SetToolTipString(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
Пример #4
0
    def _add_button(self, cls, img_prefix, tooltip=None):
        bmp = img.data.catalog[img_prefix].GetBitmap()
        bmpa = img.data.catalog[img_prefix + "_a"].GetBitmap()
        bmph = img.data.catalog[img_prefix + "_h"].GetBitmap()

        dimg = img.data.catalog[img_prefix].GetImage()
        darken_image(dimg, 0.3)
        bmpd = dimg.ConvertToBitmap()

        btn = cls(self.btn_panel, bitmap=bmp, size=(24, 24))
        btn.SetBitmapSelected(bmpa)
        btn.SetBitmapHover(bmph)
        btn.SetBitmapDisabled(bmpd)

        if tooltip:
            btn.SetToolTipString(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
Пример #5
0
    def __init__(self, *args, **kwargs):

        labels = kwargs.pop('labels', [])
        choices = kwargs.pop('choices', [])

        wx.combo.OwnerDrawnComboBox.__init__(self, *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)
        # Even those this colour sets the right
        self.SetBackgroundColour(self.Parent.GetBackgroundColour())

        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.getBitmap("button/btn_def_16.png"), (16, 16),
                                              self.GetBackgroundColour())
        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_iamge = bmpLabel.ConvertToImage()
        darken_image(dis_iamge, 0.8)

        self.SetButtonBitmaps(bmpLabel,
                              bmpHover=hover_image.ConvertToBitmap(),
                              bmpDisabled=dis_iamge.ConvertToBitmap(),
                              pushButtonBg=False)

        # self.Bind(wx.EVT_KEY_DOWN, self.on_key)
        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)
Пример #6
0
    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
Пример #7
0
    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)
Пример #8
0
    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)