示例#1
0
    def MakeButton(self):

        if self.cpStyle & wx.CP_GTK_EXPANDER:
            return None

        selection = self.btnRB.GetSelection()

        if selection == 0:  # standard wx.Button
            btn = wx.Button(self.cp, -1, self.label1)
        elif selection == 1:  # buttons.GenButton
            btn = buttons.GenButton(self.cp, -1, self.label1)
        elif selection == 2:  # buttons.GenBitmapButton
            bmp = images.Smiles.GetBitmap()
            btn = buttons.GenBitmapButton(self.cp, -1, bmp)
        elif selection == 3:  # buttons.GenBitmapTextButton
            bmp = images.Mondrian.GetBitmap()
            btn = buttons.GenBitmapTextButton(self.cp, -1, bmp, self.label1)
        elif selection == 4:  # buttons.ThemedGenButton
            btn = buttons.ThemedGenButton(self.cp, -1, self.label1)
        elif selection == 5:  # buttons.ThemedGenBitmapTextButton
            bmp = images.Mondrian.GetBitmap()
            btn = buttons.ThemedGenBitmapTextButton(self.cp, -1, bmp,
                                                    self.label1)

        return btn
示例#2
0
    def test_lib_buttons2(self):
        
        btn = buttons.ThemedGenButton(self.frame, label='label')
        btn = buttons.ThemedGenButton(self.frame, -1, 'label', (10,10), (100,-1), wx.BU_LEFT)
        
        bmp = wx.Bitmap(pngFile)
        btn = buttons.ThemedGenBitmapButton(self.frame, bitmap=bmp)
        btn = buttons.ThemedGenBitmapTextButton(self.frame, label='label', bitmap=bmp)
        
        btn.SetBitmapFocus(bmp)
        btn.SetBitmapDisabled(bmp)
        btn.SetBitmapSelected(bmp)

        btn = buttons.ThemedGenBitmapToggleButton(self.frame, bitmap=bmp)
        btn.SetToggle(True)

        self.assertTrue(btn.GetValue())
        self.assertEqual(btn.GetBitmapLabel(), bmp)
示例#3
0
 def get_control(self, parent, locals=None, text=None):
     if text is None:
         text = self.default
     self.control = wx.BoxSizer(wx.HORIZONTAL)
     self.text = wx.TextCtrl(parent, -1, text, size=wx.Size(200, 24))
     browseID = wx.NewId()
     if wx.Platform == '__WXMAC__' and hasattr(buttons, 'ThemedGenButton'):
         browse = buttons.ThemedGenButton(parent,
                                          browseID,
                                          "...",
                                          size=wx.Size(24, 24))
     else:
         browse = wx.Button(parent, browseID, "...", size=wx.Size(24, 24))
     wx.EVT_BUTTON(browse, browseID, self.OnBrowse)
     self.control.Add(self.text, 1, wx.EXPAND)
     self.control.Add((4, 4), 0)
     self.control.Add(browse, 0)
     return self
示例#4
0
    def __init__(self, parent, log):
        wx.Panel.__init__(self, parent, -1)
        self.log = log
        ##self.SetBackgroundColour("sky blue")

        sizer = wx.FlexGridSizer(1, 3, 20, 20)

        # A regular button, selected as the default button
        b = wx.Button(self, -1, "A real button")
        b.SetDefault()
        self.Bind(wx.EVT_BUTTON, self.OnButton, b)
        sizer.Add(b)

        # Same thing, but NOT set as the default button
        b = wx.Button(self, -1, "non-default")
        self.Bind(wx.EVT_BUTTON, self.OnButton, b)
        sizer.Add(b)
        sizer.Add((10, 10))

        # Plain old text button based off GenButton()
        b = buttons.GenButton(self, -1, 'Hello')
        self.Bind(wx.EVT_BUTTON, self.OnButton, b)
        sizer.Add(b)

        # Plain old text button, disabled.
        b = buttons.GenButton(self, -1, 'disabled')
        self.Bind(wx.EVT_BUTTON, self.OnButton, b)
        b.Enable(False)
        sizer.Add(b)

        # This time, we let the botton be as big as it can be.
        # Also, this one is fancier, with custom colors and bezel size.
        b = buttons.GenButton(self, -1, 'bigger')
        self.Bind(wx.EVT_BUTTON, self.OnBiggerButton, b)
        b.SetFont(wx.Font(20, wx.SWISS, wx.NORMAL, wx.BOLD, False))
        b.SetBezelWidth(5)
        b.SetMinSize(wx.DefaultSize)
        b.SetBackgroundColour("Navy")
        b.SetForegroundColour(wx.WHITE)
        b.SetToolTipString("This is a BIG button...")
        # let the sizer set best size
        sizer.Add(b, flag=wx.ADJUST_MINSIZE)

        # An image button
        bmp = images.Test2.GetBitmap()
        b = buttons.GenBitmapButton(self, -1, bmp)
        self.Bind(wx.EVT_BUTTON, self.OnButton, b)
        sizer.Add(b)

        # An image button, disabled.
        bmp = images.Test2.GetBitmap()
        b = buttons.GenBitmapButton(self, -1, bmp)
        self.Bind(wx.EVT_BUTTON, self.OnButton, b)
        sizer.Add(b)
        b.Enable(False)

        # An image button, using a mask to get rid of the
        # undesireable part of the image
        b = buttons.GenBitmapButton(self, -1, None)
        self.Bind(wx.EVT_BUTTON, self.OnButton, b)
        bmp = images.Bulb1.GetBitmap()
        mask = wx.Mask(bmp, wx.BLUE)
        bmp.SetMask(mask)
        b.SetBitmapLabel(bmp)
        bmp = images.Bulb2.GetBitmap()
        mask = wx.Mask(bmp, wx.BLUE)
        bmp.SetMask(mask)
        b.SetBitmapSelected(bmp)
        b.SetInitialSize()
        sizer.Add(b)

        # A toggle button
        b = buttons.GenToggleButton(self, -1, "Toggle Button")
        self.Bind(wx.EVT_BUTTON, self.OnToggleButton, b)
        sizer.Add(b)

        # An image toggle button
        b = buttons.GenBitmapToggleButton(self, -1, None)
        self.Bind(wx.EVT_BUTTON, self.OnToggleButton, b)
        bmp = images.Bulb1.GetBitmap()
        mask = wx.Mask(bmp, wx.BLUE)
        bmp.SetMask(mask)
        b.SetBitmapLabel(bmp)
        bmp = images.Bulb2.GetBitmap()
        mask = wx.Mask(bmp, wx.BLUE)
        bmp.SetMask(mask)
        b.SetBitmapSelected(bmp)
        b.SetToggle(True)
        b.SetInitialSize()
        sizer.Add(b)

        # A bitmap button with text.
        b = buttons.GenBitmapTextButton(self,
                                        -1,
                                        None,
                                        "Bitmapped Text",
                                        size=(200, 45))
        self.Bind(wx.EVT_BUTTON, self.OnButton, b)
        bmp = images.Bulb1.GetBitmap()
        mask = wx.Mask(bmp, wx.BLUE)
        bmp.SetMask(mask)
        b.SetBitmapLabel(bmp)
        bmp = images.Bulb2.GetBitmap()
        mask = wx.Mask(bmp, wx.BLUE)
        bmp.SetMask(mask)
        b.SetBitmapSelected(bmp)
        b.SetUseFocusIndicator(False)
        b.SetInitialSize()
        sizer.Add(b)

        # a flat text button
        b = buttons.GenButton(self,
                              -1,
                              'Flat buttons too!',
                              style=wx.BORDER_NONE)
        self.Bind(wx.EVT_BUTTON, self.OnButton, b)
        sizer.Add(b, flag=wx.ALIGN_CENTER_VERTICAL)

        # A flat image button
        bmp = images.Test2.GetBitmap()
        bmp.SetMaskColour("blue")
        b = buttons.GenBitmapButton(self, -1, bmp, style=wx.BORDER_NONE)
        self.Bind(wx.EVT_BUTTON, self.OnButton, b)
        sizer.Add(b)
        ##b.SetBackgroundColour("sky blue")
        ##b.SetBackgroundColour("pink")

        b = buttons.ThemedGenButton(self, -1, 'Drawn with native renderer')
        self.Bind(wx.EVT_BUTTON, self.OnButton, b)
        sizer.Add(b)

        border = wx.BoxSizer(wx.VERTICAL)
        border.Add(sizer, 0, wx.ALL, 25)
        self.SetSizer(border)
示例#5
0
    def __init__(self, attribute, window, aguidata={}, **kwargs):
        #label
        label = wx.Panel(window, style=0)
        #        if not hasattr(self, 'defaultBackgroundColor'):
        #            defaultBackgroundColor = label.GetBackgroundColour()
        #            r = defaultBackgroundColor[0] - 10
        #            g = defaultBackgroundColor[1] - 10
        #            b = defaultBackgroundColor[2] - 10
        #            if r < 0: r = 0
        #            if g < 0: g = 0
        #            if b < 0: b = 0
        #            defaultBackgroundColor.Set(r,g,b)
        #            self.__class__.defaultBackgroundColor = defaultBackgroundColor
        labelAreaSizer = wx.BoxSizer(orient=wx.VERTICAL)
        textSizer = AguiLabelSizer(parent=label, line=False)
        labelAreaSizer.AddSizer(textSizer, 0, wx.TOP, 1)
        availSizer = AguiLabelSizer(parent=label,
                                    line=True,
                                    label='available:')
        availSizer.textCtrl.SetWindowStyleFlag(wx.TE_RIGHT)
        availSizer.textCtrl.SetForegroundColour('gray')
        labelAreaSizer.AddSizer(availSizer, 1, wx.EXPAND | wx.TOP, 6)
        label.SetSizer(labelAreaSizer)
        label.textCtrl = textSizer.textCtrl

        #control
        control = wx.Panel(window)
        sizer = wx.BoxSizer(orient=wx.VERTICAL)
        self.sizer = sizer
        #edit
        editSizer = wx.BoxSizer(orient=wx.HORIZONTAL)
        sizer.Add(editSizer, flag=wx.EXPAND)
        # list of components on object
        editList = ComponentList(parent=control, size=WX_BUTTON_SIZE)
        editList.SetToolTipString("Components attached to object")
        editList.SetPopupMinWidth(100)
        editSizer.Add(editList, 1)
        self.editList = editList
        # edit
        editButton = buttons.ThemedGenButton(control, label='Edit')
        editButton.SetInitialSize((50, self.editList.Size[1]))
        editButton.SetToolTipString("Edit this component in a new window")
        editButton.Bind(wx.EVT_BUTTON, self.edit_button_click)
        self.editButton = editButton
        editSizer.Add(editButton, 0, wx.EAST, 5)
        #delete
        bmp = wx.ArtProvider.GetBitmap(wx.ART_DELETE, wx.ART_TOOLBAR,
                                       WX_BUTTON_BMP_SIZE)
        removeButton = wx.BitmapButton(control,
                                       size=WX_BUTTON_SIZE,
                                       bitmap=bmp)
        removeButton.SetToolTipString("Remove this component from object")
        removeButton.Bind(wx.EVT_BUTTON, self.remove_button_click)
        editSizer.Add(removeButton, 0)

        #add
        addSizer = wx.BoxSizer(orient=wx.HORIZONTAL)
        sizer.Add(addSizer, flag=wx.EXPAND)
        # tree of available components
        addTree = ComponentAddTree(parent=control)
        addTree.SetPopupMinWidth(150)
        addTree.SetToolTipString("Component to add")
        addSizer.Add(addTree, 1)
        self.addTree = addTree
        # add button
        addButton = buttons.ThemedGenButton(control,
                                            label='Add',
                                            style=wx.BU_EXACTFIT)
        addButton.SetInitialSize(editButton.Size)
        addButton.SetToolTipString("Add selected component")
        addButton.Bind(wx.EVT_BUTTON, self.add_button_click)
        addSizer.Add(addButton, 0, wx.EAST, 5)

        # browse button
        bmp = wx.ArtProvider.GetBitmap(wx.ART_HELP_BOOK, wx.ART_TOOLBAR,
                                       WX_BUTTON_BMP_SIZE)
        browseButton = wx.BitmapButton(control,
                                       size=WX_BUTTON_SIZE,
                                       bitmap=bmp)
        browseButton.SetToolTipString("Browse available components")
        addSizer.Add(browseButton, 0)
        browseButton.Bind(wx.EVT_BUTTON, self.open_browser)
        # won't let me size normally!?

        #growertest
        #        pane = control
        #        button = wx.Button(pane, label='fakeass')
        #        button.Bind(wx.EVT_BUTTON, self.expander_click)
        #        button2 = wx.Button(pane, label='hider')
        #        self.subButton = button2
        #        sizer.AddMany( [(button), (button2)])
        #        self.expanded = True

        control.SetSizer(sizer)
        control.SetMinSize((-1, -1))
        sizer.SetMinSize((-1, -1))
        sizer.Fit(control)
        addTree.SetMinSize((1, self.addTree.Size[1]))
        editList.SetMinSize((1, self.editList.Size[1]))

        kwargs['aguidata'] = aguidata
        kwargs['label_widget'] = label
        kwargs['control_widget'] = control
        Base.__init__(self, attribute, window, **kwargs)

        # keep the pug function around for button pressing
        # don't know if this is the right way to do it
        from pug.syswx.pugframe import PugFrame
        self.pug = PugFrame
示例#6
0
    def _create_layout(self):
        """
        Creates the layout for the panel.

        :returns: wx Sizer for the panel.
        :rtype: wx.Sizer
        """
        if self.mtr_type == 'network_motor':
            pos_name = "{}.position".format(self.remote_record_name)
            pos = mpwx.Value(self,
                             self.server_record,
                             pos_name,
                             function=custom_widgets.network_value_callback,
                             args=(self.scale, self.offset))
            # # setting limits this way currently doesn't work. So making it a static text, not a text entry
            # self.low_limit = wx.StaticText(self, label=self.motor.get_field('negative_limit'))
            # self.high_limit = wx.StaticText(self, label=self.motor.get_field('positive_limit'))
            #
            if self.scale * self.remote_scale.get() > 0:
                nlimit = "{}.raw_negative_limit".format(
                    self.remote_record_name)
                plimit = "{}.raw_positive_limit".format(
                    self.remote_record_name)
            else:
                nlimit = "{}.raw_positive_limit".format(
                    self.remote_record_name)
                plimit = "{}.raw_negative_limit".format(
                    self.remote_record_name)

            self.low_limit = custom_widgets.CustomLimitValueEntry(
                self,
                self.server_record,
                nlimit,
                function=custom_widgets.limit_network_value_callback,
                args=(self.scale, self.offset, self.remote_scale.get(),
                      self.remote_offset.get()),
                validator=utils.CharValidator('float_neg'))

            self.high_limit = custom_widgets.CustomLimitValueEntry(
                self,
                self.server_record,
                plimit,
                function=custom_widgets.limit_network_value_callback,
                args=(self.scale, self.offset, self.remote_scale.get(),
                      self.remote_offset.get()),
                validator=utils.CharValidator('float_neg'))

            mname = wx.StaticText(self, label=self.motor.name)

        elif self.is_epics:
            # pv = self.motor.get_field('epics_record_name')
            # self.sever_record = None #Needed to get around some MP bugs
            # pos = custom_widgets.CustomEpicsValue(self, "{}.RBV".format(pv),
            #     custom_widgets.epics_value_callback, self.scale, self.offset)

            # if self.scale > 0:
            #     nlimit = "{}.LLM".format(pv)
            #     plimit = "{}.HLM".format(pv)
            # else:
            #     nlimit = "{}.HLM".format(pv)
            #     plimit = "{}.LLM".format(pv)

            # self.low_limit = custom_widgets.CustomEpicsValueEntry(self, nlimit,
            #     custom_widgets.epics_value_callback, self.scale, self.offset, size=(-1,self.vert_size))
            # self.high_limit = custom_widgets.CustomEpicsValueEntry(self, plimit,
            #     custom_widgets.epics_value_callback, self.scale, self.offset, size=(-1,self.vert_size))

            pos = custom_epics_widgets.PVTextLabeled(self,
                                                     self.pos_pv,
                                                     scale=self.scale,
                                                     offset=self.offset)
            self.low_limit = custom_epics_widgets.PVTextCtrl2(
                self,
                self.nlimit_pv,
                dirty_timeout=None,
                scale=self.scale,
                offset=self.offset,
                validator=utils.CharValidator('float_neg'))
            self.high_limit = custom_epics_widgets.PVTextCtrl2(
                self,
                self.plimit_pv,
                dirty_timeout=None,
                scale=self.scale,
                offset=self.offset,
                validator=utils.CharValidator('float_neg'))

            mname = wx.StaticText(self,
                                  label='{} ({})'.format(
                                      self.motor.name, self.epics_pv_name))

        status_grid = wx.GridBagSizer(vgap=5, hgap=5)
        status_grid.Add(wx.StaticText(self, label='Motor name:'), (0, 0))
        status_grid.Add(mname, (0, 1), flag=wx.EXPAND)
        status_grid.AddGrowableCol(1)

        status_sizer = wx.StaticBoxSizer(wx.StaticBox(self, label='Info'),
                                         wx.VERTICAL)
        status_sizer.Add(status_grid, 1, flag=wx.EXPAND)

        self.pos_ctrl = wx.TextCtrl(self,
                                    value='',
                                    size=(50, self.vert_size),
                                    validator=utils.CharValidator('float_neg'))
        self.mrel_ctrl = wx.TextCtrl(
            self,
            value='1.0',
            size=(50, self.vert_size),
            validator=utils.CharValidator('float_neg'))

        # move_btn = wx.Button(self, label='Move', size=(50, self.vert_size), style=wx.BU_EXACTFIT)
        move_btn = buttons.ThemedGenButton(self,
                                           label='Move',
                                           size=(-1, self.vert_size),
                                           style=wx.BU_EXACTFIT)
        move_btn.Bind(wx.EVT_BUTTON, self._on_moveto)
        set_btn = buttons.ThemedGenButton(self,
                                          label='Set',
                                          size=(-1, self.vert_size),
                                          style=wx.BU_EXACTFIT)
        set_btn.Bind(wx.EVT_BUTTON, self._on_setto)

        tp_btn = buttons.ThemedGenButton(self,
                                         label='+ >',
                                         size=(-1, self.vert_size),
                                         style=wx.BU_EXACTFIT,
                                         name='rel_move_plus')
        tm_btn = buttons.ThemedGenButton(self,
                                         label='< -',
                                         size=(-1, self.vert_size),
                                         style=wx.BU_EXACTFIT,
                                         name='rel_move_minus')
        tp_btn.Bind(wx.EVT_BUTTON, self._on_mrel)
        tm_btn.Bind(wx.EVT_BUTTON, self._on_mrel)

        stop_btn = buttons.ThemedGenButton(self,
                                           label='Abort',
                                           size=(-1, self.vert_size),
                                           style=wx.BU_EXACTFIT)
        stop_btn.Bind(wx.EVT_BUTTON, self._on_stop)

        # scan_btn = buttons.ThemedGenButton(self, label='Scan', size=(-1, self.vert_size), style=wx.BU_EXACTFIT)
        # scan_btn.Bind(wx.EVT_BUTTON, self._on_scan)

        if self.is_epics:
            more_btn = buttons.ThemedGenButton(self,
                                               label='More',
                                               size=(-1, self.vert_size),
                                               style=wx.BU_EXACTFIT)
            more_btn.Bind(wx.EVT_BUTTON, self._on_more)

        pos_sizer = wx.FlexGridSizer(vgap=2, hgap=2, cols=5, rows=2)
        pos_sizer.Add(wx.StaticText(self, label='Low lim.'),
                      flag=wx.ALIGN_CENTER_VERTICAL)
        pos_sizer.Add((1, 1))
        pos_sizer.Add(wx.StaticText(self,
                                    label='Pos. ({})'.format(
                                        self.motor.get_field('units'))),
                      flag=wx.ALIGN_CENTER_VERTICAL)
        pos_sizer.Add((1, 1))
        pos_sizer.Add(wx.StaticText(self, label='High lim.'),
                      flag=wx.ALIGN_CENTER_VERTICAL)
        pos_sizer.Add(self.low_limit, flag=wx.ALIGN_CENTER_VERTICAL)
        pos_sizer.Add((1, 1))
        pos_sizer.Add(pos, flag=wx.ALIGN_CENTER_VERTICAL)
        pos_sizer.Add((1, 1))
        pos_sizer.Add(self.high_limit, flag=wx.ALIGN_CENTER_VERTICAL)
        pos_sizer.AddGrowableCol(1)
        pos_sizer.AddGrowableCol(3)

        mabs_sizer = wx.BoxSizer(wx.HORIZONTAL)
        mabs_sizer.Add(wx.StaticText(self, label='Position:'),
                       flag=wx.ALIGN_CENTER_VERTICAL)
        mabs_sizer.Add(self.pos_ctrl,
                       1,
                       border=2,
                       flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL)
        mabs_sizer.Add(move_btn,
                       border=2,
                       flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL)
        mabs_sizer.Add(set_btn,
                       border=2,
                       flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL)

        mrel_sizer = wx.BoxSizer(wx.HORIZONTAL)
        mrel_sizer.Add(wx.StaticText(self, label='Rel. Move:'),
                       flag=wx.ALIGN_CENTER_VERTICAL)
        mrel_sizer.Add(tm_btn,
                       border=2,
                       flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL)
        mrel_sizer.Add(self.mrel_ctrl,
                       1,
                       border=2,
                       flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL)
        mrel_sizer.Add(tp_btn,
                       border=2,
                       flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL)

        ctrl_btn_sizer = wx.BoxSizer(wx.HORIZONTAL)
        # ctrl_btn_sizer.Add(scan_btn, flag=wx.ALIGN_LEFT)
        if self.is_epics:
            ctrl_btn_sizer.Add(more_btn, flag=wx.ALIGN_LEFT)
        ctrl_btn_sizer.AddStretchSpacer(1)
        ctrl_btn_sizer.Add(stop_btn, border=5, flag=wx.LEFT | wx.ALIGN_RIGHT)

        control_sizer = wx.StaticBoxSizer(wx.StaticBox(self, label='Controls'),
                                          wx.VERTICAL)
        control_sizer.Add(pos_sizer, border=2, flag=wx.EXPAND | wx.BOTTOM)
        control_sizer.Add(mabs_sizer, border=2, flag=wx.EXPAND | wx.BOTTOM)
        control_sizer.Add(mrel_sizer,
                          border=2,
                          flag=wx.EXPAND | wx.BOTTOM | wx.TOP)
        control_sizer.Add(wx.StaticLine(self),
                          border=10,
                          flag=wx.EXPAND | wx.LEFT | wx.RIGHT)
        control_sizer.Add(ctrl_btn_sizer, border=2, flag=wx.TOP | wx.EXPAND)

        top_sizer = wx.BoxSizer(wx.VERTICAL)
        top_sizer.Add(status_sizer, flag=wx.EXPAND)
        top_sizer.Add(control_sizer, border=2, flag=wx.EXPAND | wx.TOP)

        self.Bind(wx.EVT_RIGHT_DOWN, self._on_rightclick)
        for item in self.GetChildren():
            if ((isinstance(item, wx.StaticText)
                 or isinstance(item, mpwx.Value)
                 or isinstance(item, custom_widgets.CustomEpicsValue)
                 or isinstance(item, wx.StaticBox)) and not (
                     isinstance(item, custom_epics_widgets.PVTextLabeled)
                     or isinstance(item, custom_epics_widgets.PVTextCtrl2))):
                item.Bind(wx.EVT_RIGHT_DOWN, self._on_rightclick)

        return top_sizer