Ejemplo n.º 1
0
    def initContactAddRemoveButtons(self):
        # New item button
        newItem = Button('+')
        newItem.addCallback(onNew, ClickEvent, self)
        self._bottomLeftCorner.addComponent(newItem)

        # Remove item button
        self._contactRemovalButton = Button('-')
        self._contactRemovalButton.addCallback(onRemove, ClickEvent, self)
        self._contactRemovalButton.setVisible(False)
        self._bottomLeftCorner.addComponent(self._contactRemovalButton)
Ejemplo n.º 2
0
    def initContactAddRemoveButtons(self):
        # New item button
        newItem = Button('+')
        newItem.addCallback(onNew, ClickEvent, self)
        self._bottomLeftCorner.addComponent(newItem)

        # Remove item button
        self._contactRemovalButton = Button('-')
        self._contactRemovalButton.addCallback(onRemove, ClickEvent, self)
        self._contactRemovalButton.setVisible(False)
        self._bottomLeftCorner.addComponent(self._contactRemovalButton)
Ejemplo n.º 3
0
    def add_button ( self, action, bbox, method=None, enabled=True,
                     name=None, default=False ):
        """ Creates a button.
        """
        ui = self.ui
        if ((action.defined_when != '') and
            (not ui.eval_when( action.defined_when ))):
            return None

        if name is None:
            name = action.name
        id     = action.id
        button = Button( str(name) )
        bbox.addComponent(button)

        bbox.setComponentAlignment(button, Alignment.MIDDLE_RIGHT)

        if default:
            button.focus()
        button.setEnabled(enabled)
        if (method is None) or (action.enabled_when != '') or (id != ''):
            editor = ButtonEditor( ui      = ui,
                                   action  = action,
                                   control = button )
            if id != '':
                ui.info.bind( id, editor )
            if action.visible_when != '':
                ui.add_visible( action.visible_when, editor )
            if action.enabled_when != '':
                ui.add_enabled( action.enabled_when, editor )
            if method is None:
                method = editor.perform

        if method is not None:
            button.addCallback(method, ClickEvent)

        if action.tooltip != '':
            button.setDescription(action.tooltip)

        return button
Ejemplo n.º 4
0
class SimpleAddressBook(Application):

    _fields = [
        'First Name', 'Last Name', 'Company', 'Mobile Phone', 'Work Phone',
        'Home Phone', 'Work Email', 'Home Email', 'Street', 'Zip', 'City',
        'State', 'Country'
    ]

    _visibleCols = ['Last Name', 'First Name', 'Company']

    def __init__(self):
        super(SimpleAddressBook, self).__init__()

        self._contactList = Table()
        self._contactEditor = Form()
        self._bottomLeftCorner = HorizontalLayout()
        self._contactRemovalButton = None
        self._addressBookData = self.createDummyData()

    def init(self):
        self.initLayout()
        self.initContactAddRemoveButtons()
        self.initAddressList()
        self.initFilteringControls()

    def initLayout(self):
        splitPanel = HorizontalSplitPanel()
        self.setMainWindow(Window('Address Book', splitPanel))
        left = VerticalLayout()
        left.setSizeFull()
        left.addComponent(self._contactList)
        self._contactList.setSizeFull()
        left.setExpandRatio(self._contactList, 1)
        splitPanel.addComponent(left)
        splitPanel.addComponent(self._contactEditor)
        self._contactEditor.setSizeFull()
        self._contactEditor.getLayout().setMargin(True)
        self._contactEditor.setImmediate(True)
        self._bottomLeftCorner.setWidth('100%')
        left.addComponent(self._bottomLeftCorner)

    def initContactAddRemoveButtons(self):
        # New item button
        newItem = Button('+')
        newItem.addCallback(onNew, ClickEvent, self)
        self._bottomLeftCorner.addComponent(newItem)

        # Remove item button
        self._contactRemovalButton = Button('-')
        self._contactRemovalButton.addCallback(onRemove, ClickEvent, self)
        self._contactRemovalButton.setVisible(False)
        self._bottomLeftCorner.addComponent(self._contactRemovalButton)

    def initAddressList(self):
        self._contactList.setContainerDataSource(self._addressBookData)
        self._contactList.setVisibleColumns(self._visibleCols)
        self._contactList.setSelectable(True)
        self._contactList.setImmediate(True)
        self._contactList.addCallback(onContactChange, field.ValueChangeEvent,
                                      self)
        return self._visibleCols

    def initFilteringControls(self):
        for pn in self._visibleCols:
            sf = TextField()
            self._bottomLeftCorner.addComponent(sf)
            sf.setWidth("100%")
            sf.setValue(pn)
            sf.setImmediate(True)
            self._bottomLeftCorner.setExpandRatio(sf, 1)
            sf.addCallback(onFilterChange, property.ValueChangeEvent, pn, sf,
                           self)

    @classmethod
    def createDummyData(cls):
        fnames = [
            'Peter', 'Alice', 'Joshua', 'Mike', 'Olivia', 'Nina', 'Alex',
            'Rita', 'Dan', 'Umberto', 'Henrik', 'Rene', 'Lisa', 'Marge'
        ]
        lnames = [
            'Smith', 'Gordon', 'Simpson', 'Brown', 'Clavel', 'Simons', 'Verne',
            'Scott', 'Allison', 'Gates', 'Rowling', 'Barks', 'Ross',
            'Schneider', 'Tate'
        ]

        ic = IndexedContainer()

        for p in cls._fields:
            ic.addContainerProperty(p, str, '')

        for _ in range(1000):
            idd = ic.addItem()
            fname = fnames[int(len(fnames) * random())]
            ic.getContainerProperty(idd, 'First Name').setValue(fname)
            lname = lnames[int(len(lnames) * random())]
            ic.getContainerProperty(idd, 'Last Name').setValue(lname)

        return ic
Ejemplo n.º 5
0
class SimpleAddressBook(Application):

    _fields = ['First Name', 'Last Name', 'Company', 'Mobile Phone',
            'Work Phone', 'Home Phone', 'Work Email', 'Home Email',
            'Street', 'Zip', 'City', 'State', 'Country']

    _visibleCols = ['Last Name', 'First Name', 'Company']

    def __init__(self):
        super(SimpleAddressBook, self).__init__()

        self._contactList = Table()
        self._contactEditor = Form()
        self._bottomLeftCorner = HorizontalLayout()
        self._contactRemovalButton = None
        self._addressBookData = self.createDummyData()


    def init(self):
        self.initLayout()
        self.initContactAddRemoveButtons()
        self.initAddressList()
        self.initFilteringControls()


    def initLayout(self):
        splitPanel = HorizontalSplitPanel()
        self.setMainWindow(Window('Address Book', splitPanel))
        left = VerticalLayout()
        left.setSizeFull()
        left.addComponent(self._contactList)
        self._contactList.setSizeFull()
        left.setExpandRatio(self._contactList, 1)
        splitPanel.addComponent(left)
        splitPanel.addComponent(self._contactEditor)
        self._contactEditor.setSizeFull()
        self._contactEditor.getLayout().setMargin(True)
        self._contactEditor.setImmediate(True)
        self._bottomLeftCorner.setWidth('100%')
        left.addComponent(self._bottomLeftCorner)


    def initContactAddRemoveButtons(self):
        # New item button
        newItem = Button('+')
        newItem.addCallback(onNew, ClickEvent, self)
        self._bottomLeftCorner.addComponent(newItem)

        # Remove item button
        self._contactRemovalButton = Button('-')
        self._contactRemovalButton.addCallback(onRemove, ClickEvent, self)
        self._contactRemovalButton.setVisible(False)
        self._bottomLeftCorner.addComponent(self._contactRemovalButton)


    def initAddressList(self):
        self._contactList.setContainerDataSource(self._addressBookData)
        self._contactList.setVisibleColumns(self._visibleCols)
        self._contactList.setSelectable(True)
        self._contactList.setImmediate(True)
        self._contactList.addCallback(onContactChange, field.ValueChangeEvent,
                self)
        return self._visibleCols


    def initFilteringControls(self):
        for pn in self._visibleCols:
            sf = TextField()
            self._bottomLeftCorner.addComponent(sf)
            sf.setWidth("100%")
            sf.setValue(pn)
            sf.setImmediate(True)
            self._bottomLeftCorner.setExpandRatio(sf, 1)
            sf.addCallback(onFilterChange, property.ValueChangeEvent,
                    pn, sf, self)


    @classmethod
    def createDummyData(cls):
        fnames = ['Peter', 'Alice', 'Joshua', 'Mike', 'Olivia', 'Nina', 'Alex',
                'Rita', 'Dan', 'Umberto', 'Henrik', 'Rene', 'Lisa', 'Marge']
        lnames = ['Smith', 'Gordon', 'Simpson', 'Brown', 'Clavel', 'Simons',
                'Verne', 'Scott', 'Allison', 'Gates', 'Rowling', 'Barks',
                'Ross', 'Schneider', 'Tate']

        ic = IndexedContainer()

        for p in cls._fields:
            ic.addContainerProperty(p, str, '')

        for _ in range(1000):
            idd = ic.addItem()
            fname = fnames[int( len(fnames) * random() )]
            ic.getContainerProperty(idd, 'First Name').setValue(fname)
            lname = lnames[int( len(lnames) * random() )]
            ic.getContainerProperty(idd, 'Last Name').setValue(lname)

        return ic
Ejemplo n.º 6
0
class SimpleEditor ( CustomEditor ):
    """ Simple style of editor for instances, which displays a button. Clicking
    the button displays a dialog box in which the instance can be edited.
    """

    # Class constants:
    orientation = 'horizontal'
    extra       = 2

    #---------------------------------------------------------------------------
    #  Creates the editor control:
    #---------------------------------------------------------------------------

    def create_editor(self, parent, layout):
        """ Creates the editor control (a button).
        """
        self._button = Button()
        layout.addComponent(self._button)
        self._button.addCallback(self.edit_instance, ClickEvent)

    #---------------------------------------------------------------------------
    #  Edit the contents of the object trait when the user clicks the button:
    #---------------------------------------------------------------------------

    def edit_instance(self, event):
        """ Edit the contents of the object trait when the user clicks the
            button.
        """
        # Create the user interface:
        factory = self.factory
        view    = self.ui.handler.trait_view_for( self.ui.info, factory.view,
                                                  self.value, self.object_name,
                                                  self.name )
        ui = self.value.edit_traits( view, kind=factory.kind, id=factory.id )

        # Make sure the editor is properly disposed
#        QtCore.QObject.connect( self._button, QtCore.SIGNAL( 'destroyed()' ),
#                                lambda: ui.dispose() )

        # Check to see if the view was 'modal', in which case it will already
        # have been closed (i.e. is None) by the time we get control back:
        if ui.control is not None:
            # Position the window on the display:
            position_window( ui.control )

            # Chain our undo history to the new user interface if it does not
            # have its own:
            if ui.history is None:
                ui.history = self.ui.history

    #---------------------------------------------------------------------------
    #  Resynchronizes the contents of the editor when the object trait changes
    #  external to the editor:
    #---------------------------------------------------------------------------

    def resynch_editor ( self ):
        """ Resynchronizes the contents of the editor when the object trait
            changes externally to the editor.
        """
        button = self._button
        if button is not None:
            label = self.factory.label
            if label == '':
                label = user_name_for( self.name )

            button.setCaption( str(label) )
            button.setEnabled(isinstance(self.value, HasTraits))