Exemplo n.º 1
0
class ThemedButtonEditor(BasicEditorFactory):

    # The editor class to be created:
    klass = _ThemedButtonEditor

    # The button label:
    label = Str

    # The basic theme for the button (i.e. the 'up' state):
    theme = ATheme('@std:BG5')

    # The optional 'down' state theme for the button:
    down_theme = ATheme('@std:BE5')

    # The optional 'hover' state theme for the button:
    hover_theme = ATheme('@std:BG6')

    # The optional 'disabled' state theme for the button:
    disabled_theme = ATheme('@std:GG3')

    # The optional image to display in the button:
    image = Image

    # The position of the image relative to the text:
    position = Position

    # The amount of space between the image and the text:
    spacing = Spacing

    # The optional view to display when the button is clicked:
    view = AView
Exemplo n.º 2
0
class TestAdapter ( ListCanvasAdapter ):

    Person_theme_active        = Person_theme_active
    Person_theme_inactive      = Person_theme_inactive
    Person_theme_hover         = Person_theme_inactive
    ObjectTrait_theme_active   = ATheme( Theme( '@std:J08', content = 3 ) )
    ObjectTrait_theme_inactive = ATheme( Theme( '@std:J07', content = 3 ) )
    ObjectTrait_theme_hover    = ATheme( Theme( '@std:J0A', content = 3 ) )

    CanvasItems_size    = Tuple( ( 180, 250 ) )
    CanvasSnoop_size    = Tuple( ( 250, 250 ) )

    Person_tooltip      = Property
    Person_can_drag     = Bool( True )
    Person_can_clone    = Bool( True )
    Person_can_delete   = Bool( True )
    # fixme: Why can't we use 'Constant' for this?...
    Person_monitor      = Any( PersonMonitor )
    Person_can_close    = Any( Modified )
    Person_title        = Property
    ListCanvas_can_receive_Person   = Bool( True )
    ListCanvas_can_receive_NoneType = Bool( True )
    File_view = Any( View( Item( 'path' ) ) )

    def _get_Person_title ( self ):
        return (self.item.name or '<undefined>')

    def _get_Person_tooltip ( self ):
        return ('A person named %s' % self.item.name)
Exemplo n.º 3
0
class ImageBrowserAdapter(ListCanvasAdapter):

    # Disable minimizing all items (to save screen real estate):
    can_minimize = False

    ImageItem_theme_active = ATheme(
        Theme('photo_frame_active',
              label=(0, 0, -3, 2),
              content=0,
              border=(1, 7, 1, 7),
              alignment='center'))
    ImageItem_theme_inactive = ATheme(
        Theme('photo_frame_inactive',
              label=(0, 0, -3, 2),
              content=0,
              border=(1, 7, 1, 7),
              alignment='center'))
    ImageItem_theme_hover = ATheme(
        Theme('photo_frame_hover',
              label=(0, 0, -3, 2),
              content=0,
              border=(1, 7, 1, 7),
              alignment='center'))
    ImageItem_title = Property
    ImageItem_tooltip = Property

    def _get_ImageItem_title(self):
        return self.item.name

    def _get_ImageItem_tooltip(self):
        return self.item.name
class ThemedVerticalNotebook(HasPrivateTraits):
    """ Defines a ThemedVerticalNotebook class for displaying a series of pages
        organized vertically, as opposed to horizontally like a standard
        notebook.
    """

    #-- Public Traits ----------------------------------------------------------

    # The theme to use for 'closed' notebook pages:
    closed_theme = ATheme(Theme('@std:notebook_close', content=0))

    # The theme to use for 'open' notebook pages:
    open_theme = ATheme(Theme('@std:notebook_open', content=0))

    # Allow multiple open pages at once?
    multiple_open = Bool(False)

    # Should the notebook be scrollable?
    scrollable = Bool(False)

    # Use double clicks (True) or single clicks (False) to open/close pages:
    double_click = Bool(False)

    # The pages contained in the notebook:
    pages = List(ThemedPage)

    # The traits UI editor this notebook is associated with (if any):
    editor = Instance(Editor)

    #-- Private Traits ---------------------------------------------------------

    # The wxPython control used to represent the notebook:
    control = Instance(wx.Window)

    #-- Public Methods ---------------------------------------------------------

    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:
        control.Bind(wx.EVT_ERASE_BACKGROUND, self._erase_background)
        control.Bind(wx.EVT_PAINT, self._paint)

        return control

    def create_page(self):
        """ Creates a new **ThemedPage** object representing a notebook page and
            returns it as the result.
        """
        return ThemedPage(notebook=self).set(closed_theme=self.closed_theme,
                                             open_theme=self.open_theme)

    def open(self, page):
        """ Handles opening a specified **ThemedPage** notebook page.
        """
        if (page is not None) and (not page.is_open):
            if not self.multiple_open:
                for a_page in self.pages:
                    a_page.is_open = False

            page.is_open = True

            self._refresh()

    def close(self, page):
        """ Handles closing a specified **ThemedPage** notebook page.
        """
        if (page is not None) and page.is_open:
            page.is_open = False
            self._refresh()

    #-- Trait Event Handlers ---------------------------------------------------

    def _pages_changed(self, old, new):
        """ Handles the notebook's pages being changed.
        """
        for page in old:
            page.close()

        self._refresh()

    def _pages_items_changed(self, event):
        """ Handles some of the notebook's pages being changed.
        """
        for page in event.removed:
            page.close()

        self._refresh()

    def _multiple_open_changed(self, multiple_open):
        """ Handles the 'multiple_open' flag being changed.
        """
        if not multiple_open:
            first = True
            for page in self.pages:
                if first and page.is_open:
                    first = False
                else:
                    page.is_open = False

        self._refresh()

    #-- wx.Python Event Handlers -----------------------------------------------

    def _erase_background(self, event):
        """ Do not erase the background here (do it in the 'on_paint' handler).
        """
        pass

    def _paint(self, event):
        """ Paint the background using the associated ImageSlice object.
        """
        paint_parent(wx.PaintDC(self.control), self.control)

    #-- Private Methods --------------------------------------------------------

    def _refresh(self):
        """ Refresh the layout and contents of the notebook.
        """
        control = self.control
        if control is not None:
            # Set the virtual size of the canvas (so scroll bars work right):
            sizer = control.GetSizer()
            if control.GetSize().Get()[0] == 0:
                control.SetSize(sizer.CalcInit())
            control.SetVirtualSize(sizer.CalcMin())
            control.Layout()
            control.Refresh()
class TItem(Item):
    editor = ScrubberEditor()
    item_theme = ATheme('@std:LG')
Exemplo n.º 6
0
class PersonMonitor ( ListCanvasItemMonitor ):

    @on_trait_change( 'item:object:name' )
    def _name_modified ( self, name ):
        self.item.title = name

    @on_trait_change( 'item:moved' )
    def _position_modified ( self ):
        position = self.item.position
        self.adapter.status = '%s moved to (%s,%s) [%s]' % (
               self.item.title, position[0], position[1],
               ', '.join( [ item.title for item in self.item.neighbors ] ) )

#-- The main demo ListCanvas adapter class -------------------------------------

Person_theme_active = ATheme( Theme( '@std:GL5TB', label  = ( 14, 14, 25, 3 ),
                                                   border = ( 6, 6, 6, 6 ) ) )

# Fixme: This image was originally @GL5T but we could not find it, so GL5 is
# being used in its place
Person_theme_inactive = ATheme( Theme( '@std:GL5', label  = ( 14, 14, 25, 3 ),
                                                    border = ( 6, 6, 6, 6 ) ) )

class TestAdapter ( ListCanvasAdapter ):

    Person_theme_active        = Person_theme_active
    Person_theme_inactive      = Person_theme_inactive
    Person_theme_hover         = Person_theme_inactive
    ObjectTrait_theme_active   = ATheme( Theme( '@std:J08', content = 3 ) )
    ObjectTrait_theme_inactive = ATheme( Theme( '@std:J07', content = 3 ) )
    ObjectTrait_theme_hover    = ATheme( Theme( '@std:J0A', content = 3 ) )