Exemplo n.º 1
0
    class EditorWithCustomWidget(ToolkitSpecificEditor):  # noqa: F811
        def init(self, parent):
            self.control = TraitsUIPanel(parent, -1)

            sizer = wx.BoxSizer(wx.HORIZONTAL)
            self._dummy = DummyObject()
            self._ui = self._dummy.edit_traits(
                parent=self.control,
                kind="subpanel",
                view=View(
                    Item(
                        "number",
                        editor=BasicEditorFactory(klass=DummyButtonEditor),
                    ), ),
            )
            sizer.Add(self._ui.control, 1, wx.EXPAND)
            self.control.SetSizerAndFit(sizer)

        def update_editor(self):
            pass

        def dispose(self):
            super().dispose()

        def dispose_inner_ui(self):
            if self._ui is not None:
                self._ui.dispose()
                self._ui = None
Exemplo n.º 2
0
        def init(self, parent):
            self.control = TraitsUIPanel(parent, -1)

            sizer = wx.BoxSizer(wx.HORIZONTAL)
            self._dummy = DummyObject()
            self._ui = self._dummy.edit_traits(
                parent=self.control,
                kind="subpanel",
                view=View(
                    Item(
                        "number",
                        editor=BasicEditorFactory(klass=DummyButtonEditor),
                    ), ),
            )
            sizer.Add(self._ui.control, 1, wx.EXPAND)
            self.control.SetSizerAndFit(sizer)
Exemplo n.º 3
0
def wx_editor_factory(parent, editor, use_dir=False, *args):
    import wx
    from traitsui.wx.helper import TraitsUIPanel

    editor.control = panel = TraitsUIPanel(parent, -1)
    sizer = wx.BoxSizer(wx.HORIZONTAL)

    editor.use_dir = use_dir

    pad = 8

    bmp = wx.ArtProvider.GetBitmap(wx.ART_FOLDER_OPEN, size=(15, 15))
    button = wx.BitmapButton(panel, -1, bitmap=bmp)

    editor.text_control = text_control = wx.TextCtrl(panel,
                                                     -1,
                                                     '',
                                                     style=wx.TE_PROCESS_ENTER)

    _do_update_obj = lambda ev: update_file_obj(editor)

    wx.EVT_TEXT_ENTER(panel, text_control.GetId(), _do_update_obj)
    wx.EVT_KILL_FOCUS(text_control, _do_update_obj)

    sizer.Add(text_control, 1, wx.EXPAND | wx.ALIGN_CENTER)
    sizer.Add(button, 0, wx.RIGHT | wx.ALIGN_CENTER, pad)

    wx.EVT_BUTTON(panel, button.GetId(), lambda ev: button_click(editor))
    panel.SetSizerAndFit(sizer)

    return panel
Exemplo n.º 4
0
    def init(self, parent):
        """ Finishes initializing the editor by creating the underlying toolkit
            widget.
        """
        factory = self.factory
        if not factory.low_name:
            self.low = factory.low
            self.min = self.low

        if not factory.high_name:
            self.high = factory.high
            self.max = self.high

        self.max = factory.max
        self.min = factory.min

        self.format = factory.format

        self.evaluate = factory.evaluate
        self.sync_value(factory.evaluate_name, "evaluate", "from")

        self.sync_value(factory.low_name, "low", "both")
        self.sync_value(factory.high_name, "high", "both")

        self.control = panel = TraitsUIPanel(parent, -1)
        sizer = wx.FlexGridSizer(2, 3, 0, 0)

        # low text box
        self._label_lo = wx.TextCtrl(
            panel,
            -1,
            self.format % self.low,
            size=wx.Size(56, 20),
            style=wx.TE_PROCESS_ENTER,
        )
        sizer.Add(self._label_lo, 0, wx.ALIGN_CENTER)
        wx.EVT_TEXT_ENTER(
            panel, self._label_lo.GetId(), self.update_low_on_enter
        )
        wx.EVT_KILL_FOCUS(self._label_lo, self.update_low_on_enter)

        # low slider
        self.control.lslider = Slider(
            panel,
            -1,
            0,
            0,
            10000,
            size=wx.Size(100, 20),
            style=wx.SL_HORIZONTAL | wx.SL_AUTOTICKS,
        )
        self.control.lslider.SetValue(self._convert_to_slider(self.low))
        self.control.lslider.SetTickFreq(1000, 1)
        self.control.lslider.SetPageSize(1000)
        self.control.lslider.SetLineSize(100)
        wx.EVT_SCROLL(self.control.lslider, self.update_object_on_scroll)
        sizer.Add(self.control.lslider, 1, wx.EXPAND)
        sizer.AddStretchSpacer(0)

        # high slider
        sizer.AddStretchSpacer(0)
        self.control.rslider = Slider(
            panel,
            -1,
            self._convert_to_slider(self.high),
            0,
            10000,
            size=wx.Size(100, 20),
            style=wx.SL_HORIZONTAL | wx.SL_AUTOTICKS,
        )
        self.control.rslider.SetTickFreq(1000, 1)
        self.control.rslider.SetPageSize(1000)
        self.control.rslider.SetLineSize(100)
        wx.EVT_SCROLL(self.control.rslider, self.update_object_on_scroll)
        sizer.Add(self.control.rslider, 1, wx.EXPAND)

        # high text box
        self._label_hi = wx.TextCtrl(
            panel,
            -1,
            self.format % self.high,
            size=wx.Size(56, 20),
            style=wx.TE_PROCESS_ENTER,
        )
        sizer.Add(self._label_hi, 0, wx.ALIGN_CENTER)
        wx.EVT_TEXT_ENTER(
            panel, self._label_hi.GetId(), self.update_high_on_enter
        )
        wx.EVT_KILL_FOCUS(self._label_hi, self.update_high_on_enter)

        self.set_tooltip(self.control.lslider)
        self.set_tooltip(self.control.rslider)
        self.set_tooltip(self._label_lo)
        self.set_tooltip(self._label_hi)

        # Set-up the layout:
        panel.SetSizerAndFit(sizer)