Ejemplo n.º 1
0
    def __init__(self, parent, tool_bar, image_cache, item, controller,
                 show_labels):
        """ Creates a new tool bar tool for an action item. """

        self.item = item
        self.tool_bar = tool_bar

        # Create an appropriate tool depending on the style of the action.
        action  = self.item.action

        # If the action has an image then convert it to a bitmap (as required
        # by the toolbar).
        if action.image is not None:
            image = action.image.create_image()
            path = action.image.absolute_path
            bmp  = image_cache.get_bitmap(path)

        else:
            from pyface.api import ImageResource
            image = ImageResource('foo')
            bmp  = image.create_bitmap()

        self.control_id = 1
        self.control = None
        if controller is not None:
            self.controller = controller
            controller.add_to_toolbar(self)

        return
Ejemplo n.º 2
0
    def __init__(self, parent, tool_bar, image_cache, item, controller,
                 show_labels):
        """ Creates a new tool bar tool for an action item. """

        self.item = item
        self.tool_bar = tool_bar

        # Create an appropriate tool depending on the style of the action.
        action = self.item.action

        # If the action has an image then convert it to a bitmap (as required
        # by the toolbar).
        if action.image is not None:
            image = action.image.create_image()
            path = action.image.absolute_path
            bmp = image_cache.get_bitmap(path)

        else:
            from pyface.api import ImageResource

            image = ImageResource("foo")
            bmp = image.create_bitmap()

        self.control_id = 1
        self.control = None
        if controller is not None:
            self.controller = controller
            controller.add_to_toolbar(self)
Ejemplo n.º 3
0
 def show_minibuffer(self, minibuffer, **kwargs):
     # minibuffer_pane_info is stored in the TaskWindow instance because all
     # tasks use the same minibuffer pane in the AUI manager
     try:
         info = self.window.minibuffer_pane_info
     except AttributeError:
         panel = wx.Panel(self.window.control, style=wx.NO_BORDER)
         sizer = wx.BoxSizer(wx.HORIZONTAL)
         close_image = ImageResource('cancel')
         bmp = close_image.create_bitmap()
         close = wx.BitmapButton(panel, -1, bmp, size=(bmp.GetWidth()+10, bmp.GetHeight()+10), style=wx.NO_BORDER)
         close.Bind(wx.EVT_BUTTON, self.on_hide_minibuffer_or_cancel)
         sizer.Add(close, 0, wx.EXPAND)
         panel.SetSizer(sizer)
         info = self.create_minibuffer_info()
         self.window._aui_manager.AddPane(panel, info)
         # info.window is set to panel in the AUI code
         self.window.minibuffer_pane_info = info
     repeat = False
     if info.minibuffer is not None:
         if info.minibuffer.is_repeat(minibuffer):
             log.debug("Reusing old minibuffer control: %s" % info.minibuffer.control)
             repeat = True
         else:
             log.debug("Removing old minibuffer control: %s" % info.minibuffer.control)
             info.window.GetSizer().Hide(0)
             info.window.GetSizer().Remove(0)
             info.minibuffer.destroy_control()
             log.debug("Children: %s" % info.window.GetSizer().Children)
     if not repeat:
         minibuffer.create_control(info.window)
         info.window.GetSizer().Insert(0, minibuffer.control, 1, wx.EXPAND)
         info.window.GetSizer().Layout()
         minibuffer.focus()
         info.minibuffer = minibuffer
         log.debug("Window: %s, info: %s" % (self.window, info))
     else:
         info.minibuffer.focus()
         info.minibuffer.repeat(minibuffer)  # Include new minibuffer
     if not info.IsShown():
         info.Show()
         self.window._aui_manager.Update()
Ejemplo n.º 4
0
 def __init__(self,
              parent,
              id,
              icon_name,
              pressed=False,
              tooltip_prefix="Toggle",
              *args,
              **kwargs):
     buttons.GenBitmapToggleButton.__init__(self,
                                            parent,
                                            -1,
                                            None,
                                            style=wx.BORDER_NONE)
     self.SetValue(pressed)
     self.tooltip_prefix = tooltip_prefix
     img = ImageResource(icon_name)
     bmp = img.create_bitmap()
     self.SetBitmapLabel(bmp)
     self.SetInitialSize()
     self.set_tooltip()
Ejemplo n.º 5
0
    def __init__(self, parent, tool_bar, image_cache, item, controller,
                 show_labels):
        """ Creates a new tool bar tool for an action item. """

        self.item = item
        self.tool_bar = tool_bar

        # Create an appropriate tool depending on the style of the action.
        action = self.item.action
        label = action.name

        # Tool bar tools never have '...' at the end!
        if label.endswith('...'):
            label = label[:-3]

        # And they never contain shortcuts.
        label = label.replace('&', '')

        # If the action has an image then convert it to a bitmap (as required
        # by the toolbar).
        if action.image is not None:
            image = action.image.create_image(
                self.tool_bar.GetToolBitmapSize())
            path = action.image.absolute_path
            bmp = image_cache.get_bitmap(path)

        else:
            from pyface.api import ImageResource
            image = ImageResource('foo')
            bmp = image.create_bitmap()

        kind = _STYLE_TO_KIND_MAP[action.style]
        tooltip = action.tooltip
        longtip = action.description

        if not show_labels:
            label = ''

        else:
            self.tool_bar.SetSize((-1, 50))

        self.control_id = wx.NewId()
        self.control = tool_bar.AddLabelTool(self.control_id, label, bmp,
                                             wx.NullBitmap, kind, tooltip,
                                             longtip, None)

        # Set the initial checked state.
        tool_bar.ToggleTool(self.control_id, action.checked)

        if hasattr(tool_bar, 'ShowTool'):
            # Set the initial enabled/disabled state of the action.
            tool_bar.EnableTool(self.control_id, action.enabled)

            # Set the initial visibility
            tool_bar.ShowTool(self.control_id, action.visible)
        else:
            # Set the initial enabled/disabled state of the action.
            tool_bar.EnableTool(self.control_id, action.enabled
                                and action.visible)

        # Wire it up.
        wx.EVT_TOOL(parent, self.control_id, self._on_tool)

        # Listen for trait changes on the action (so that we can update its
        # enabled/disabled/checked state etc).
        action.on_trait_change(self._on_action_enabled_changed, 'enabled')
        action.on_trait_change(self._on_action_visible_changed, 'visible')
        action.on_trait_change(self._on_action_checked_changed, 'checked')

        if controller is not None:
            self.controller = controller
            controller.add_to_toolbar(self)
Ejemplo n.º 6
0
    def __init__(self, parent, tool_bar, image_cache, item, controller,
                 show_labels):
        """ Creates a new tool bar tool for an action item. """

        self.item = item
        self.tool_bar = tool_bar

        # Create an appropriate tool depending on the style of the action.
        action  = self.item.action
        label   = action.name

        # Tool bar tools never have '...' at the end!
        if label.endswith('...'):
            label = label[:-3]

        # And they never contain shortcuts.
        label = label.replace('&', '')

        # If the action has an image then convert it to a bitmap (as required
        # by the toolbar).
        if action.image is not None:
            image = action.image.create_image(
                self.tool_bar.GetToolBitmapSize()
            )
            path = action.image.absolute_path
            bmp  = image_cache.get_bitmap(path)

        else:
            from pyface.api import ImageResource
            image = ImageResource('foo')
            bmp  = image.create_bitmap()

        kind    = _STYLE_TO_KIND_MAP[action.style]
        tooltip = action.tooltip
        longtip = action.description

        if not show_labels:
            label = ''

        else:
            self.tool_bar.SetSize((-1, 50))

        self.control_id = wx.NewId()
        self.control = tool_bar.AddLabelTool(
            self.control_id, label, bmp, wx.NullBitmap, kind, tooltip, longtip, None
        )

        # Set the initial checked state.
        tool_bar.ToggleTool(self.control_id, action.checked)

        if hasattr(tool_bar, 'ShowTool'):
            # Set the initial enabled/disabled state of the action.
            tool_bar.EnableTool(self.control_id, action.enabled)

            # Set the initial visibility
            tool_bar.ShowTool(self.control_id, action.visible)
        else:
            # Set the initial enabled/disabled state of the action.
            tool_bar.EnableTool(
                self.control_id, action.enabled and action.visible)

        # Wire it up.
        wx.EVT_TOOL(parent, self.control_id, self._on_tool)

        # Listen for trait changes on the action (so that we can update its
        # enabled/disabled/checked state etc).
        action.on_trait_change(self._on_action_enabled_changed, 'enabled')
        action.on_trait_change(self._on_action_visible_changed, 'visible')
        action.on_trait_change(self._on_action_checked_changed, 'checked')

        if controller is not None:
            self.controller = controller
            controller.add_to_toolbar(self)
Ejemplo n.º 7
0
    def show_minibuffer(self, minibuffer, **kwargs):
        # minibuffer_pane_info is stored in the TaskWindow instance because all
        # tasks use the same minibuffer pane in the AUI manager
        try:
            info = self.window.minibuffer_pane_info
            log.debug("minibuffer pane exists: %s" % info)
        except AttributeError:
            panel = wx.Panel(self.window.control,
                             name="minibuffer_parent",
                             style=wx.NO_BORDER)
            sizer = wx.BoxSizer(wx.HORIZONTAL)
            close_image = ImageResource('cancel')
            bmp = close_image.create_bitmap()
            close = wx.BitmapButton(panel,
                                    -1,
                                    bmp,
                                    size=(bmp.GetWidth() + 10,
                                          bmp.GetHeight() + 10),
                                    style=wx.NO_BORDER)
            close.Bind(wx.EVT_BUTTON, self.on_hide_minibuffer_or_cancel)
            sizer.Add(close, 0, wx.EXPAND)
            panel.SetSizer(sizer)
            info = self.create_minibuffer_info()
            self.window._aui_manager.AddPane(panel, info)
            # info.window is set to panel in the AUI code
            self.window.minibuffer_pane_info = info
            info.close_button = close
            log.debug("created minibuffer pane: %s" % info)
        repeat = False
        if info.minibuffer is not None:
            if info.minibuffer.is_repeat(minibuffer):
                log.debug("Reusing old minibuffer control: %s" %
                          info.minibuffer.control)
                repeat = True
            else:
                log.debug("Removing old minibuffer control: %s" %
                          info.minibuffer.control)
                info.window.GetSizer().Hide(0)
                info.window.GetSizer().Remove(0)
                info.minibuffer.destroy_control()
                log.debug("Children: %s" % info.window.GetSizer().Children)
        force_update = False
        if not repeat:
            minibuffer.create_control(info.window)
            info.close_button.Show(minibuffer.show_close_button)
            info.window.GetSizer().Insert(0, minibuffer.control, 1, wx.EXPAND)

            # force minibuffer parent panel to take min size of contents of
            # minibuffer. Apparently this doesn't happen automatically.
            #
            # FIXME: or maybe it does. Removing all the min size stuff now
            # seems to work. Maybe because prior I had been setting the min
            # size after the Fit?
            min_size = minibuffer.control.GetMinSize()
            #            info.window.SetMinSize(min_size)
            #            info.BestSize(min_size)  # Force minibuffer height, just in case

            info.window.Fit()  # Fit instead of Layout to prefer control size
            minibuffer.focus()
            info.minibuffer = minibuffer
            log.debug("Window: %s, info: %s, size: %s" %
                      (self.window, info, info.best_size))
            force_update = True
        else:
            log.debug("Repeat: %s, info: %s" % (self.window, info))
            info.minibuffer.focus()
            info.minibuffer.repeat(minibuffer)  # Include new minibuffer
        if not info.IsShown():
            info.Show()
            force_update = True
        if force_update:
            self.window._aui_manager.Update()
        log.debug("size after update: %s best=%s min=%s" %
                  (info.window.GetSize(), info.best_size, info.min_size))