Exemplo 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 facets.ui.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 )
Exemplo n.º 2
0
 def _get_image ( self ):
     path, name = split( self.file_name )
     if splitext( name )[ 1 ] in ( '.png', '.gif', '.jpg', '.jpeg' ):
         image = ImageResource( name, search_path = [ path ] )
     else:
         image = ImageResource( 'unknown' )
     self._cur_image = image.create_image()
     return image
Exemplo n.º 3
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 facets.ui.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)

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

        # 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 facet changes on the action (so that we can update its
        # enabled/disabled/checked state etc):
        action.on_facet_set(self._on_action_enabled_modified, "enabled")
        action.on_facet_set(self._on_action_visible_modified, "visible")
        action.on_facet_set(self._on_action_checked_modified, "checked")

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