Esempio n. 1
0
    def create_fold_for_item(self, notebook, item):
        """ Adds a single group or item to a vertical notebook.
        """
        # Create a new notebook page:
        page = notebook.create_page()

        # Create the page contents:
        if isinstance(item, Group):
            panel, resizable, contents = fill_panel_for_group(
                page.parent,
                item,
                self.ui,
                suppress_label=True,
                create_panel=True)
        else:
            panel = TraitsUIPanel(page.parent, -1)
            sizer = wx.BoxSizer(wx.VERTICAL)
            panel.SetSizer(sizer)
            self.add_items([item], panel, sizer)

        # Set the page name and control:
        page.name = item.get_label(self.ui)
        page.control = panel

        # Return the new notebook page:
        return page
Esempio n. 2
0
    def add_dock_window_splitter_item(self, window, item, group):
        """ Adds a single group or item to a DockWindow.
        """
        if isinstance(item, Group):
            sizer, resizable, contents = fill_panel_for_group(
                window,
                item,
                self.ui,
                suppress_label=True,
                is_dock_window=True)
            self.resizable |= resizable

            return contents

        orientation = wx.VERTICAL
        if self.is_horizontal:
            orientation = wx.HORIZONTAL
        sizer = wx.BoxSizer(orientation)

        panel = TraitsUIPanel(window, -1)
        panel.SetSizer(sizer)

        self.add_items([item], panel, sizer)

        return DockRegion(contents=[
            DockControl(name=item.get_label(self.ui),
                        image=item.image,
                        id=item.get_id(),
                        style=item.dock,
                        dockable=DockableViewElement(ui=self.ui, element=item),
                        export=item.export,
                        control=panel)
        ])
Esempio n. 3
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

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

        self.format = factory.format

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

        size = wx.DefaultSize
        if factory.label_width > 0:
            size = wx.Size(factory.label_width, 20)

        self.sync_value(factory.low_name, 'low', 'from')
        self.sync_value(factory.high_name, 'high', 'from')
        self.control = panel = TraitsUIPanel(parent, -1)
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        fvalue = self.value

        if not (self.low <= fvalue <= self.high):
            fvalue_text = ''
            fvalue = self.low
        else:
            try:
                fvalue_text = self.format % fvalue
            except (ValueError, TypeError), e:
                fvalue_text = ''
Esempio n. 4
0
    def init(self, parent):
        """
        Finishes initializing the editor by creating the underlying widget.
        """
        self.control = self._panel = parent = TraitsUIPanel(parent, -1)
        sizer = wx.BoxSizer(wx.HORIZONTAL)

        # 'text_control' is the text display of the color.
        text_control = wx.TextCtrl(parent,
                                   -1,
                                   self.str_value,
                                   style=wx.TE_PROCESS_ENTER)
        wx.EVT_KILL_FOCUS(text_control, self.update_object)
        wx.EVT_TEXT_ENTER(parent, text_control.GetId(), self.update_object)

        # 'button_control' shows the 'Edit' button.
        button_control = wx.Button(parent, label='Edit', style=wx.BU_EXACTFIT)
        wx.EVT_BUTTON(button_control, button_control.GetId(),
                      self.open_color_dialog)

        sizer.Add(text_control, wx.ALIGN_LEFT)
        sizer.AddSpacer(8)
        sizer.Add(button_control, wx.ALIGN_RIGHT)
        self.control.SetSizer(sizer)

        self._text_control = text_control
        self._button_control = button_control

        self.set_tooltip()

        return
Esempio n. 5
0
    def _create_image_grid(self, parent):
        """ Populates a specified window with a grid of image buttons.
        """
        # Create the panel to hold the ImageControl buttons:
        self.control = panel = TraitsUIPanel(parent, -1)

        # Create the main sizer:
        if self.factory.cols > 1:
            sizer = wx.GridSizer(0, self.factory.cols, 0, 0)
        else:
            sizer = wx.BoxSizer(wx.VERTICAL)

        # Add the set of all possible choices:
        factory = self.factory
        mapping = factory._mapping
        cur_value = self.value
        for name in self.factory._names:
            value = mapping[name]
            control = ImageControl(
                panel,
                bitmap_cache('%s%s%s' % (factory.prefix, name, factory.suffix),
                             False, factory._image_path), value == cur_value,
                self.update_object)
            control.value = value
            sizer.Add(control, 0, wx.ALL, 2)
            self.set_tooltip(control)

        # Finish setting up the control layout:
        panel.SetSizerAndFit(sizer)
Esempio n. 6
0
    def init(self, parent):
        """ Finishes initializing the editor by creating the underlying toolkit
            widget.
        """
        factory = self.factory
        if factory.name != '':
            self._object, self._name, self._value = \
                self.parse_extended_name(factory.name)
            self.values_changed()
            self._object.on_trait_change(self._values_changed,
                                         self._name, dispatch='ui')
        else:
            factory.on_trait_change(self.update_editor, 'values_modified',
                                    dispatch='ui')

        self.control = panel = TraitsUIPanel(parent, -1)
        hsizer = wx.BoxSizer(wx.HORIZONTAL)
        vsizer = wx.BoxSizer(wx.VERTICAL)

        self._unused = self._create_listbox(
            panel,
            hsizer,
            self._on_unused,
            self._on_use,
            factory.left_column_title)

        self._use_all = self._unuse_all = self._up = self._down = None
        if factory.can_move_all:
            self._use_all = self._create_button('>>', panel, vsizer, 15,
                                                self._on_use_all)

        self._use = self._create_button('>', panel, vsizer, 15,
                                        self._on_use)
        self._unuse = self._create_button('<', panel, vsizer, 0,
                                          self._on_unuse)
        if factory.can_move_all:
            self._unuse_all = self._create_button('<<', panel, vsizer, 15,
                                                  self._on_unuse_all)

        if factory.ordered:
            self._up = self._create_button('Move Up', panel, vsizer, 30,
                                           self._on_up)
            self._down = self._create_button('Move Down', panel, vsizer, 0,
                                             self._on_down)

        hsizer.Add(vsizer, 0, wx.LEFT | wx.RIGHT, 8)
        self._used = self._create_listbox(
            panel,
            hsizer,
            self._on_value,
            self._on_unuse,
            factory.right_column_title)

        panel.SetSizer(hsizer)

        self.context_object.on_trait_change(
            self.update_editor,
            self.extended_name + '_items?',
            dispatch='ui')
        self.set_tooltip()
Esempio n. 7
0
    def init(self, parent):
        """ Finishes initializing the editor by creating the underlying toolkit
            widget.
        """
        super(RadioEditor, self).init(parent)

        # Create a panel to hold all of the radio buttons:
        self.control = TraitsUIPanel(parent, -1)
        self.rebuild_editor()
Esempio n. 8
0
    def init(self, parent):
        """ Finishes initializing the editor by creating the underlying toolkit
            widget.
        """
        self.control = panel = TraitsUIPanel(parent, -1)
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        factory = self.factory

        if factory.entries > 0:
            from history_control import HistoryControl

            self.history = HistoryControl(entries=factory.entries,
                                          auto_set=factory.auto_set)
            control = self.history.create_control(panel)
            pad = 3
            button = wx.Button(panel, -1, '...',
                               size=wx.Size(28, -1))
        else:
            if factory.enter_set:
                control = wx.TextCtrl(panel, -1, '',
                                      style=wx.TE_PROCESS_ENTER)
                wx.EVT_TEXT_ENTER(panel, control.GetId(), self.update_object)
            else:
                control = wx.TextCtrl(panel, -1, '')

            wx.EVT_KILL_FOCUS(control, self.update_object)

            if factory.auto_set:
                wx.EVT_TEXT(panel, control.GetId(), self.update_object)

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

            pad = 8

        self._file_name = control
        sizer.Add(control, 1, wx.EXPAND | wx.ALIGN_CENTER)
        sizer.Add(button, 0, wx.LEFT | wx.ALIGN_CENTER, pad)
        wx.EVT_BUTTON(panel, button.GetId(), self.show_file_dialog)
        panel.SetDropTarget(FileDropTarget(self))
        panel.SetSizerAndFit(sizer)
        self._button = button

        self.set_tooltip(control)
Esempio n. 9
0
    def create_control(self, parent):
        """ Creates the underlying wxPython window used for the notebook.
        """
        # Create the correct type of window based on whether or not it should
        # be scrollable:
        if self.scrollable:
            self.control = control = TraitsUIScrolledPanel(parent)
            control.SetScrollRate(6, 6)
            control.SetSize(wx.Size(0, 0))
        else:
            self.control = control = TraitsUIPanel(parent, -1)

        control._image_slice = getattr(parent, '_image_slice', None)
        control.SetSizer(ThemedVerticalNotebookSizer(self))

        # Set up the painting event handlers:
        wx.EVT_ERASE_BACKGROUND(control, self._erase_background)
        wx.EVT_PAINT(control, self._paint)

        return control
Esempio n. 10
0
    def init(self, parent):
        """ Finishes initializing the editor by creating the underlying toolkit
            widget.
        """
        # Create a panel to hold all of the buttons:
        self.control = panel = TraitsUIPanel(parent, -1)
        sizer = wx.BoxSizer(wx.VERTICAL)

        # Add all of the font choice controls:
        sizer2 = wx.BoxSizer(wx.HORIZONTAL)
        facenames = self.factory.all_facenames()
        control = self._facename = wx.Choice(panel, -1, wx.Point(0, 0),
                                             wx.Size(-1, -1), facenames)

        sizer2.Add(control, 4, wx.EXPAND)
        wx.EVT_CHOICE(panel, control.GetId(), self.update_object_parts)

        control = self._point_size = wx.Choice(panel, -1, wx.Point(0, 0),
                                               wx.Size(-1, -1), PointSizes)
        sizer2.Add(control, 1, wx.EXPAND | wx.LEFT, 3)
        wx.EVT_CHOICE(panel, control.GetId(), self.update_object_parts)

        if self.factory.show_style:
            self._style = wx.Choice(panel, -1, wx.Point(0, 0), wx.Size(-1, -1),
                                    Styles)
            sizer2.Add(self._style, 1, wx.EXPAND | wx.LEFT, 3)
            wx.EVT_CHOICE(panel, self._style.GetId(), self.update_object_parts)

        if self.factory.show_weight:
            self._weight = wx.Choice(panel, -1, wx.Point(0, 0),
                                     wx.Size(-1, -1), Weights)
            sizer2.Add(self._weight, 1, wx.EXPAND | wx.LEFT, 3)
            wx.EVT_CHOICE(panel, self._weight.GetId(),
                          self.update_object_parts)

        sizer.Add(sizer2, 0, wx.EXPAND)

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

        self.set_tooltip()
Esempio n. 11
0
def panel(ui, parent):
    """ Creates a panel-based wxPython user interface for a specified UI object.

        This function does not modify the UI object passed to it
    """
    # Bind the context values to the 'info' object:
    ui.info.bind_context()

    # Get the content that will be displayed in the user interface:
    content = ui._groups

    # If there is 0 or 1 Groups in the content, create a single panel for it:
    if len(content) <= 1:
        panel = TraitsUIPanel(parent, -1)
        if len(content) == 1:
            # Fill the panel with the Group's content:
            sg_sizer, resizable, contents = fill_panel_for_group(
                panel, content[0], ui)
            sizer = panel.GetSizer()
            if sizer is not sg_sizer:
                sizer.Add(sg_sizer, 1, wx.EXPAND)

            # Make sure the panel and its contents have been laid out properly:
            sizer.Fit(panel)

        # Return the panel that was created:
        return panel

    # Create a notebook which will contain a page for each group in the
    # content:
    nb = create_notebook_for_items(content, ui, parent, None)
    nb.ui = ui

    # Notice when the notebook page changes (to display correct help)
    ###wx.EVT_NOTEBOOK_PAGE_CHANGED( parent, nb.GetId(), _page_changed )

    # Return the notebook as the result:
    return nb
Esempio n. 12
0
    def init(self, parent):
        """ Finishes initializing the editor by creating the underlying toolkit
            widget.
        """
        # Create a panel to hold all of the component trait editors:
        self.control = panel = TraitsUIPanel(parent, -1)
        sizer = wx.BoxSizer(wx.VERTICAL)

        # Add all of the component trait editors:
        self._editors = editors = []
        for factory in self.factory.editors:
            editor = getattr(factory,
                             self.kind)(self.ui, self.object, self.name,
                                        self.description, panel)
            editor.prepare(panel)
            sizer.Add(editor.control, 1,
                      wx.TOP | wx.BOTTOM | editor.layout_style, 3)
            editors.append(editor)

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

        self.set_tooltip()
Esempio n. 13
0
    def __init__(self, panel, group, ui, suppress_label, is_dock_window,
                 create_panel):
        """ Initializes the object.
        """
        # Get the contents of the group:
        content = group.get_content()

        # Create a group editor object if one is needed:
        self.control = self.sizer = editor = None
        self.ui = ui
        self.group = group
        self.is_horizontal = (group.orientation == 'horizontal')
        layout = group.layout
        is_scrolled_panel = group.scrollable
        is_splitter = (layout == 'split')
        is_tabbed = (layout == 'tabbed')
        id = group.id

        # Assume our contents are not resizable:
        self.resizable = False

        if is_dock_window and (is_splitter or is_tabbed):
            if is_splitter:
                self.dock_contents = self.add_dock_window_splitter_items(
                    panel, content, group)
            else:
                self.resizable = group.springy
                self.dock_contents = create_notebook_for_items(
                    content, ui, panel, group, self.add_notebook_item, True)
            return

        if (is_dock_window or create_panel or is_scrolled_panel or (id != '')
                or (group.visible_when != '') or (group.enabled_when != '')):
            if is_scrolled_panel:
                new_panel = TraitsUIScrolledPanel(panel)
                new_panel.SetMinSize(panel.GetMinSize())
                self.resizable = True
            else:
                new_panel = TraitsUIPanel(panel, -1)

            sizer = panel.GetSizer()
            if sizer is None:
                sizer = wx.BoxSizer(wx.VERTICAL)
                panel.SetSizer(sizer)
            self.control = panel = new_panel
            if is_splitter or is_tabbed:
                editor = DockWindowGroupEditor(control=panel, ui=ui)
            else:
                editor = GroupEditor(control=panel)
            if id != '':
                ui.info.bind(group.id, editor)
            if group.visible_when != '':
                ui.add_visible(group.visible_when, editor)
            if group.enabled_when != '':
                ui.add_enabled(group.enabled_when, editor)

        self.panel = panel
        self.dock_contents = None

        # Determine the horizontal/vertical orientation of the group:
        if self.is_horizontal:
            orientation = wx.HORIZONTAL
        else:
            orientation = wx.VERTICAL

        # Set up a group with or without a border around its contents:
        label = ''
        if not suppress_label:
            label = group.label

        if group.show_border:
            box = wx.StaticBox(panel, -1, label)
            self._set_owner(box, group)
            self.sizer = wx.StaticBoxSizer(box, orientation)
        else:
            if layout == 'flow':
                self.sizer = FlowSizer(orientation)
            else:
                self.sizer = wx.BoxSizer(orientation)
            if label != '':
                self.sizer.Add(
                    heading_text(panel, text=label).control, 0,
                    wx.EXPAND | wx.LEFT | wx.TOP | wx.RIGHT, 4)

        # If no sizer has been specified for the panel yet, make the new sizer
        # the layout sizer for the panel:
        if panel.GetSizer() is None:
            panel.SetSizer(self.sizer)

        # Set up scrolling now that the sizer has been set:
        if is_scrolled_panel:
            if self.is_horizontal:
                panel.SetupScrolling(scroll_y=False)
            else:
                panel.SetupScrolling(scroll_x=False)

        if is_splitter:
            dw = DockWindow(panel,
                            handler=ui.handler,
                            handler_args=(ui.info, ),
                            id=ui.id,
                            theme=group.dock_theme).control
            if editor is not None:
                editor.dock_window = dw

            dw.SetSizer(
                DockSizer(contents=self.add_dock_window_splitter_items(
                    dw, content, group)))
            self.sizer.Add(dw, 1, wx.EXPAND)
        elif len(content) > 0:
            if is_tabbed:
                self.resizable = group.springy
                dw = create_notebook_for_items(content, ui, panel, group,
                                               self.add_notebook_item)
                if editor is not None:
                    editor.dock_window = dw

                self.sizer.Add(dw, self.resizable, wx.EXPAND)
            # Check if content is all Group objects:
            elif layout == 'fold':
                self.resizable = True
                self.sizer.Add(self.create_fold_for_items(panel, content), 1,
                               wx.EXPAND)
            elif isinstance(content[0], Group):
                # If so, add them to the panel and exit:
                self.add_groups(content, panel)
            else:
                self.add_items(content, panel, self.sizer)

        # If the caller is a DockWindow, we need to define the content we are
        # adding to it:
        if is_dock_window:
            self.dock_contents = DockRegion(contents=[
                DockControl(name=group.get_label(self.ui),
                            image=group.image,
                            id=group.get_id(),
                            style=group.dock,
                            dockable=DockableViewElement(ui=ui, element=group),
                            export=group.export,
                            control=panel)
            ])
Esempio n. 14
0
 def create_editor(self, parent, sizer):
     """ Creates the editor control.
     """
     self._panel = TraitsUIPanel(parent, -1)
     sizer.Add(self._panel, 1, wx.EXPAND)
Esempio n. 15
0
    def init(self, parent):
        """ Finishes initializing the editor by creating the underlying toolkit
            widget.
        """
        factory = self.factory
        if factory.name != '':
            self._object, self._name, self._value = \
                self.parse_extended_name(factory.name)

        # Create a panel to hold the object trait's view:
        if factory.editable:
            self.control = self._panel = parent = TraitsUIPanel(parent, -1)

        # Build the instance selector if needed:
        selectable = factory.selectable
        droppable = factory.droppable
        items = self.items
        for item in items:
            droppable |= item.is_droppable()
            selectable |= item.is_selectable()

        if selectable:
            self._object_cache = {}
            item = self.item_for(self.value)
            if item is not None:
                self._object_cache[id(item)] = self.value

            self._choice = choice = wx.Choice(parent, -1, wx.Point(0, 0),
                                              wx.Size(-1, -1), [])
            wx.EVT_CHOICE(choice, choice.GetId(), self.update_object)
            if droppable:
                self._choice.SetBackgroundColour(self.ok_color)

            self.set_tooltip(self._choice)

            if factory.name != '':
                self._object.on_trait_change(self.rebuild_items,
                                             self._name,
                                             dispatch='ui')
                self._object.on_trait_change(self.rebuild_items,
                                             self._name + '_items',
                                             dispatch='ui')

            factory.on_trait_change(self.rebuild_items,
                                    'values',
                                    dispatch='ui')
            factory.on_trait_change(self.rebuild_items,
                                    'values_items',
                                    dispatch='ui')

            self.rebuild_items()

        elif droppable:
            self._choice = wx.TextCtrl(parent, -1, '', style=wx.TE_READONLY)
            self._choice.SetBackgroundColour(self.ok_color)
            self.set_tooltip(self._choice)

        if droppable:
            self._choice.SetDropTarget(PythonDropTarget(self))

        orientation = OrientationMap[factory.orientation]
        if orientation is None:
            orientation = self.orientation

        if (selectable or droppable) and factory.editable:
            sizer = wx.BoxSizer(orientation)
            sizer.Add(self._choice, self.extra, wx.EXPAND)
            if orientation == wx.VERTICAL:
                sizer.Add(wx.StaticLine(parent, -1, style=wx.LI_HORIZONTAL), 0,
                          wx.EXPAND | wx.TOP | wx.BOTTOM, 5)
            self.create_editor(parent, sizer)
            parent.SetSizer(sizer)
        elif self.control is None:
            if self._choice is None:
                self._choice = choice = wx.Choice(parent, -1, wx.Point(0, 0),
                                                  wx.Size(-1, -1), [])
                wx.EVT_CHOICE(choice, choice.GetId(), self.update_object)
            self.control = self._choice
        else:
            sizer = wx.BoxSizer(orientation)
            self.create_editor(parent, sizer)
            parent.SetSizer(sizer)

        # Synchronize the 'view' to use:
        # fixme: A normal assignment can cause a crash (for unknown reasons) in
        # some cases, so we make sure that no notifications are generated:
        self.trait_setq(view=factory.view)
        self.sync_value(factory.view_name, 'view', 'from')
Esempio n. 16
0
 def create_control(self, parent):
     """ Creates the initial editor control.
     """
     # Create a panel to hold all of the check boxes
     self.control = panel = TraitsUIPanel(parent, -1)
Esempio n. 17
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

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

        self.format = factory.format

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

        size = wx.DefaultSize
        if factory.label_width > 0:
            size = wx.Size(factory.label_width, 20)

        self.sync_value(factory.low_name, 'low', 'from')
        self.sync_value(factory.high_name, 'high', 'from')
        self.control = panel = TraitsUIPanel(parent, -1)
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        fvalue = self.value

        if not (self.low <= fvalue <= self.high):
            fvalue_text = ''
            fvalue = self.low
        else:
            try:
                fvalue_text = self.format % fvalue
            except (ValueError, TypeError) as e:
                fvalue_text = ''

        ivalue = self._convert_to_slider(fvalue)

        self._label_lo = wx.StaticText(
            panel, -1, '999999', size=size, style=wx.ALIGN_RIGHT | wx.ST_NO_AUTORESIZE)
        sizer.Add(self._label_lo, 0, wx.ALIGN_CENTER)
        panel.slider = slider = Slider(panel, -1, ivalue, 0, 10000,
                                       size=wx.Size(80, 20),
                                       style=wx.SL_HORIZONTAL | wx.SL_AUTOTICKS)
        slider.SetTickFreq(1000, 1)
        slider.SetPageSize(1000)
        slider.SetLineSize(100)
        wx.EVT_SCROLL(slider, self.update_object_on_scroll)
        sizer.Add(slider, 1, wx.EXPAND)
        self._label_hi = wx.StaticText(panel, -1, '999999', size=size)
        sizer.Add(self._label_hi, 0, wx.ALIGN_CENTER)

        panel.text = text = wx.TextCtrl(panel, -1, fvalue_text,
                                        size=wx.Size(56, 20),
                                        style=wx.TE_PROCESS_ENTER)
        wx.EVT_TEXT_ENTER(panel, text.GetId(), self.update_object_on_enter)
        wx.EVT_KILL_FOCUS(text, self.update_object_on_enter)

        sizer.Add(text, 0, wx.LEFT | wx.EXPAND, 4)

        low_label = factory.low_label
        if factory.low_name != '':
            low_label = self.format % self.low

        high_label = factory.high_label
        if factory.high_name != '':
            high_label = self.format % self.high

        self._label_lo.SetLabel(low_label)
        self._label_hi.SetLabel(high_label)
        self.set_tooltip(slider)
        self.set_tooltip(self._label_lo)
        self.set_tooltip(self._label_hi)
        self.set_tooltip(text)

        # Set-up the layout:
        panel.SetSizerAndFit(sizer)
Esempio n. 18
0
    def init(self, parent):
        """ Finishes initializing the editor by creating the underlying toolkit
            widget.
        """
        factory = self.factory

        # Initialize using the factory range defaults:
        self.low = factory.low
        self.high = factory.high
        self.evaluate = factory.evaluate

        # Hook up the traits to listen to the object.
        self.sync_value(factory.low_name, 'low', 'from')
        self.sync_value(factory.high_name, 'high', 'from')
        self.sync_value(factory.evaluate_name, 'evaluate', 'from')

        self.init_range()
        low = self.cur_low
        high = self.cur_high

        self._set_format()
        self.control = panel = TraitsUIPanel(parent, -1)
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        fvalue = self.value
        try:
            fvalue_text = self._format % fvalue
            1 / (low <= fvalue <= high)
        except:
            fvalue_text = ''
            fvalue = low

        if high > low:
            ivalue = int((float(fvalue - low) / (high - low)) * 10000)
        else:
            ivalue = low

        # Lower limit label:
        label_lo = wx.StaticText(panel, -1, '999999')
        panel.label_lo = label_lo
        sizer.Add(label_lo, 2, wx.ALIGN_CENTER)

        # Lower limit button:
        bmp = wx.ArtProvider.GetBitmap(wx.ART_GO_BACK, size=(15, 15))
        button_lo = wx.BitmapButton(panel,
                                    -1,
                                    bitmap=bmp,
                                    size=(-1, 20),
                                    style=wx.BU_EXACTFIT | wx.NO_BORDER)
        panel.button_lo = button_lo
        button_lo.Bind(wx.EVT_BUTTON, self.reduce_range, button_lo)
        sizer.Add(button_lo, 1, wx.ALIGN_CENTER)

        # Slider:
        panel.slider = slider = Slider(panel,
                                       -1,
                                       ivalue,
                                       0,
                                       10000,
                                       size=wx.Size(80, 20),
                                       style=wx.SL_HORIZONTAL
                                       | wx.SL_AUTOTICKS)
        slider.SetTickFreq(1000, 1)
        slider.SetPageSize(1000)
        slider.SetLineSize(100)
        wx.EVT_SCROLL(slider, self.update_object_on_scroll)
        sizer.Add(slider, 6, wx.EXPAND)

        # Upper limit button:
        bmp = wx.ArtProvider.GetBitmap(wx.ART_GO_FORWARD, size=(15, 15))
        button_hi = wx.BitmapButton(panel,
                                    -1,
                                    bitmap=bmp,
                                    size=(-1, 20),
                                    style=wx.BU_EXACTFIT | wx.NO_BORDER)
        panel.button_hi = button_hi
        button_hi.Bind(wx.EVT_BUTTON, self.increase_range, button_hi)
        sizer.Add(button_hi, 1, wx.ALIGN_CENTER)

        # Upper limit label:
        label_hi = wx.StaticText(panel, -1, '999999')
        panel.label_hi = label_hi
        sizer.Add(label_hi, 2, wx.ALIGN_CENTER)

        # Text entry:
        panel.text = text = wx.TextCtrl(panel,
                                        -1,
                                        fvalue_text,
                                        size=wx.Size(56, 20),
                                        style=wx.TE_PROCESS_ENTER)
        wx.EVT_TEXT_ENTER(panel, text.GetId(), self.update_object_on_enter)
        wx.EVT_KILL_FOCUS(text, self.update_object_on_enter)

        sizer.Add(text, 0, wx.LEFT | wx.EXPAND, 4)

        # Set-up the layout:
        panel.SetSizerAndFit(sizer)
        label_lo.SetLabel(str(low))
        label_hi.SetLabel(str(high))
        self.set_tooltip(slider)
        self.set_tooltip(label_lo)
        self.set_tooltip(label_hi)
        self.set_tooltip(text)

        # Update the ranges and button just in case.
        self.update_range_ui()
Esempio n. 19
0
    def __init__(self, ui, parent, allow_buttons):
        """ Initializes the object.
        """
        self.ui = ui
        history = None
        view = ui.view
        title = view.title

        # Reset any existing history listeners:
        history = ui.history
        if history is not None:
            history.on_trait_change(self._on_undoable, 'undoable', remove=True)
            history.on_trait_change(self._on_redoable, 'redoable', remove=True)
            history.on_trait_change(self._on_revertable,
                                    'undoable',
                                    remove=True)

        # Determine if we need any buttons or an 'undo' history:
        buttons = [self.coerce_button(button) for button in view.buttons]
        nbuttons = len(buttons)
        if nbuttons == 0:
            if view.undo:
                self.check_button(buttons, UndoButton)
            if view.revert:
                self.check_button(buttons, RevertButton)
            if view.help:
                self.check_button(buttons, HelpButton)

        if allow_buttons and (history is None):
            for button in buttons:
                if (self.is_button(button, 'Undo')
                        or self.is_button(button, 'Revert')):
                    history = UndoHistory()
                    break
        ui.history = history

        # Create a container panel to put everything in:
        cpanel = getattr(self, 'control', None)
        if cpanel is not None:
            cpanel.SetSizer(None)
            cpanel.DestroyChildren()
        else:
            self.control = cpanel = TraitsUIPanel(parent, -1)

        # Create the actual trait sheet panel and embed it in a scrollable
        # window (if requested):
        sw_sizer = wx.BoxSizer(wx.VERTICAL)
        if ui.scrollable:
            sizer = wx.BoxSizer(wx.VERTICAL)
            sw = TraitsUIScrolledPanel(cpanel)
            sizer.Add(panel(ui, sw), 1, wx.EXPAND)

            sw.SetSizerAndFit(sizer)
            sw.SetScrollRate(16, 16)
        else:
            sw = panel(ui, cpanel)

        if ((title != '') and
            (not isinstance(getattr(parent, 'owner', None), DockWindow))):
            sw_sizer.Add(
                heading_text(cpanel, text=title).control, 0, wx.EXPAND)

        self.add_toolbar(sw_sizer)

        sw_sizer.Add(sw, 1, wx.EXPAND)

        if (allow_buttons
                and ((nbuttons != 1) or (not self.is_button(buttons[0], '')))):
            # Add the special function buttons:
            sw_sizer.Add(wx.StaticLine(cpanel, -1), 0, wx.EXPAND)
            b_sizer = wx.BoxSizer(wx.HORIZONTAL)
            for button in buttons:
                if self.is_button(button, 'Undo'):
                    self.undo = self.add_button(button, b_sizer, self._on_undo,
                                                False)
                    self.redo = self.add_button(button, b_sizer, self._on_redo,
                                                False, 'Redo')
                    history.on_trait_change(self._on_undoable,
                                            'undoable',
                                            dispatch='ui')
                    history.on_trait_change(self._on_redoable,
                                            'redoable',
                                            dispatch='ui')
                elif self.is_button(button, 'Revert'):
                    self.revert = self.add_button(button, b_sizer,
                                                  self._on_revert, False)
                    history.on_trait_change(self._on_revertable,
                                            'undoable',
                                            dispatch='ui')
                elif self.is_button(button, 'Help'):
                    self.add_button(button, b_sizer, self._on_help)
                elif not self.is_button(button, ''):
                    self.add_button(button, b_sizer)

            sw_sizer.Add(b_sizer, 0, wx.ALIGN_RIGHT | wx.ALL, 5)

        cpanel.SetSizerAndFit(sw_sizer)
Esempio n. 20
0
def create_notebook_for_items(content,
                              ui,
                              parent,
                              group,
                              item_handler=None,
                              is_dock_window=False):
    """ Creates a notebook and adds a list of groups or items to it as separate
        pages.
    """
    if is_dock_window:
        nb = parent
    else:
        dw = DockWindow(parent,
                        handler=ui.handler,
                        handler_args=(ui.info, ),
                        id=ui.id)
        if group is not None:
            dw.theme = group.dock_theme
        nb = dw.control
    pages = []
    count = 0

    # Create a notebook page for each group or item in the content:
    active = 0
    for index, item in enumerate(content):
        if isinstance(item, Group):
            # Create the group as a nested DockWindow item:
            if item.selected:
                active = index
            sg_sizer, resizable, contents = \
                fill_panel_for_group(nb, item, ui, suppress_label=True,
                                     is_dock_window=True)

            # If the result is a region (i.e. notebook) with only one page,
            # collapse it down into just the contents of the region:
            if (isinstance(contents, DockRegion)
                    and (len(contents.contents) == 1)):
                contents = contents.contents[0]

            # Add the content to the notebook as a new page:
            pages.append(contents)
        else:
            # Create the new page as a simple DockControl containing the
            # specified set of controls:
            page_name = item.get_label(ui)
            count += 1
            if page_name == '':
                page_name = 'Page %d' % count

            sizer = wx.BoxSizer(wx.VERTICAL)

            panel = TraitsUIPanel(nb, -1)
            panel.SetSizer(sizer)

            pages.append(
                DockControl(name=page_name,
                            image=item.image,
                            id=item.get_id(),
                            style=item.dock,
                            dockable=DockableViewElement(ui=ui, element=item),
                            export=item.export,
                            control=panel))
            item_handler(item, panel, sizer)
            panel.GetSizer().Fit(panel)

    region = DockRegion(contents=pages, active=active)

    # If the caller is a DockWindow, return the region as the result:
    if is_dock_window:
        return region

    nb.SetSizer(DockSizer(contents=DockSection(contents=[region])))

    # Return the notebook as the result:
    return nb