Пример #1
0
    def __init__ (self, cls=None, searchColumns=None, editorClass=None,
                  filename=None, store=None, **kwargs):
        from fvl.cimarron.skin import Notebook, VBox, Button

        self.editors = []
        super(CRUDController, self).__init__(**kwargs)
        self.note = Notebook(parent=self.window)
        # why this fails so miserably?
        # self._innerWidget = self.note._innerWidget
        if not '_concreteWidget' in self.__dict__:
            self._concreteWidget = self.window

        # first tab
        self.firstTab = VBox(label='Search')
        self.firstTab.parent = self.note

        self.new = Button(parent=self.firstTab, label='New', expand=False)
        self.cls = cls
        self.store = store

        if searchColumns:
            # add the Search thing
            self.search = Search(parent=self.firstTab, columns=searchColumns,
                                 onAction=self.changeModel)

        # second tab
        if editorClass is not None:
            if filename is not None:
                modelEditor = editorClass.fromXmlFile(filename)
            else:
                # let's hope the editorClass knows what to do
                modelEditor = editorClass()
            modelEditor.parent = self.note
            self.editors.append(modelEditor)
            self.mainWidget = modelEditor
Пример #2
0
    def __init__(self,
                 cls=None,
                 searchColumns=None,
                 editorClass=None,
                 filename=None,
                 store=None,
                 **kwargs):
        from fvl.cimarron.skin import Notebook, VBox, Button

        self.editors = []
        super(CRUDController, self).__init__(**kwargs)
        self.note = Notebook(parent=self.window)
        # why this fails so miserably?
        # self._innerWidget = self.note._innerWidget
        if not '_concreteWidget' in self.__dict__:
            self._concreteWidget = self.window

        # first tab
        self.firstTab = VBox(label='Search')
        self.firstTab.parent = self.note

        self.new = Button(parent=self.firstTab, label='New', expand=False)
        self.cls = cls
        if searchColumns is not None:
            # add the Search thing
            self.search = Search(parent=self.firstTab,
                                 columns=searchColumns,
                                 onAction=self.changeModel)

        if store is not None:
            self.store = store

        # second tab
        if editorClass is not None:
            if filename is not None:
                modelEditor = editorClass.fromXmlFile(filename)
            else:
                # let's hope the editorClass knows what to do
                modelEditor = editorClass()
            modelEditor.parent = self.note
            self.editors.append(modelEditor)
            self.mainWidget = modelEditor
Пример #3
0
class CRUDController (WindowController):
    """
    CRUD ('ABM' in spanish) Controller .
    see: http://c2.com/cgi/wiki?CrudScreen
    """
    def attributesToConnect (cls):
        """
        See L{XmlMixin.attributesToConnect
        <fvl.cimarron.skins.common.XmlMixin.attributesToConnect>}
        """
        attrs = super(CRUDController, cls).attributesToConnect()
        return attrs+['cls']
    attributesToConnect = classmethod(attributesToConnect)
    
    def __init__ (self, cls=None, searchColumns=None, editorClass=None,
                  filename=None, store=None, **kwargs):
        from fvl.cimarron.skin import Notebook, VBox, Button

        self.editors = []
        super(CRUDController, self).__init__(**kwargs)
        self.note = Notebook(parent=self.window)
        # why this fails so miserably?
        # self._innerWidget = self.note._innerWidget
        if not '_concreteWidget' in self.__dict__:
            self._concreteWidget = self.window

        # first tab
        self.firstTab = VBox(label='Search')
        self.firstTab.parent = self.note

        self.new = Button(parent=self.firstTab, label='New', expand=False)
        self.cls = cls
        if searchColumns is not None:
            # add the Search thing
            self.search = Search(parent=self.firstTab, columns=searchColumns,
                                 onAction=self.changeModel)

        if store is not None:
            self.store = store

        # second tab
        if editorClass is not None:
            if filename is not None:
                modelEditor = editorClass.fromXmlFile(filename)
            else:
                # let's hope the editorClass knows what to do
                modelEditor = editorClass()
            modelEditor.parent = self.note
            self.editors.append(modelEditor)
            self.mainWidget = modelEditor

        # more tabs?
        # FIXME: complete!

    def _set_value(self, value):
        self.__value = value
        for editor in self.editors:
            editor.newTarget(self.__value)
    def _get_value(self):
        return self.__value
    value = property(_get_value, _set_value)

    def _set_cls (self, cls):
        if cls is not None:
            def onAction(control, *ignore):
                return self.newModel(control, cls, *ignore)
            self.new.onAction = onAction
        self._cls = cls
    def _get_cls (self):
        return self._cls
    cls = property(_get_cls, _set_cls, None, """
        The CRUD's 'class'. This is, the callable used to create
        a new object of the type the CRUD is editing.""")

    def _set_store(self, store):
        self.__store = store
        self.search.searcher = store
        for editor in self.editors:
            editor.store = store
    def _get_store(self):
        return self.__store
    store = property(_get_store, _set_store, None, """""")
        
    def newModel(self, control, cls, *ignore):
        """
        Create a new object and point the CRUD at it.
        """
        value = cls()
        self.store.track(value)
        self.changeModel(control, value)

    def changeModel(self, control, model=None):
        """
        Updates the CRUD's currently-in-edition object.
        """
        if model is None:
            value = self.search.value
        else:
            value = model
        logger.debug(`value`)
        self.commitValue(value)

        if value is not None:
            self.note.activate(1)
            # and this?
            # self.editor.focus ()

    def save (self, *ignore):
        self.store.save()
        # FIXME: really?
        self.onAction()

    def discard(self):
        self.store.discard()

    def fromXmlObj (cls, xmlObj):
        """
        See L{XmlMixin.fromXmlObj
        <fvl.cimarron.skins.common.XmlMixin.fromXmlObj>}
        """
        self = cls()
        root = xmlObj
        attrs = {self: cls.attributesToConnect()}
        idDict = {}

        xmlObj = xmlObj.children
        first = True
        second = False
        while xmlObj:
            (obj, attrsInChild, idDictInChild) = \
                  self.childFromXmlObj(xmlObj)
            if obj is not None:
                if first:
                    obj.parent = self.firstTab
                    self.search = obj
                    first = False
                    second = True
                else:
                    obj.parent = self.note
                    self.editors.append(obj)
                    if second:
                        self.mainWidget = obj
                        obj.onAction = self.save
                        second = False

                attrs.update(attrsInChild)
            idDict.update(idDictInChild)
            xmlObj = xmlObj.next

        # at this time, so it has time to do the <import>s
        self.fromXmlObjProps(root.properties)
        try:
            idDict[self.id] = self
        except AttributeError:
            # have no id, ignore
            pass
        
        return (self, attrs, idDict)
    fromXmlObj = classmethod(fromXmlObj)
Пример #4
0
class CRUDController(WindowController):
    """
    CRUD ('ABM' in spanish) Controller .
    see: http://c2.com/cgi/wiki?CrudScreen
    """
    def attributesToConnect(cls):
        """
        See L{XmlMixin.attributesToConnect
        <fvl.cimarron.skins.common.XmlMixin.attributesToConnect>}
        """
        attrs = super(CRUDController, cls).attributesToConnect()
        return attrs + ['cls']

    attributesToConnect = classmethod(attributesToConnect)

    def __init__(self,
                 cls=None,
                 searchColumns=None,
                 editorClass=None,
                 filename=None,
                 store=None,
                 **kwargs):
        from fvl.cimarron.skin import Notebook, VBox, Button

        self.editors = []
        super(CRUDController, self).__init__(**kwargs)
        self.note = Notebook(parent=self.window)
        # why this fails so miserably?
        # self._innerWidget = self.note._innerWidget
        if not '_concreteWidget' in self.__dict__:
            self._concreteWidget = self.window

        # first tab
        self.firstTab = VBox(label='Search')
        self.firstTab.parent = self.note

        self.new = Button(parent=self.firstTab, label='New', expand=False)
        self.cls = cls
        if searchColumns is not None:
            # add the Search thing
            self.search = Search(parent=self.firstTab,
                                 columns=searchColumns,
                                 onAction=self.changeModel)

        if store is not None:
            self.store = store

        # second tab
        if editorClass is not None:
            if filename is not None:
                modelEditor = editorClass.fromXmlFile(filename)
            else:
                # let's hope the editorClass knows what to do
                modelEditor = editorClass()
            modelEditor.parent = self.note
            self.editors.append(modelEditor)
            self.mainWidget = modelEditor

        # more tabs?
        # FIXME: complete!

    def _set_value(self, value):
        self.__value = value
        for editor in self.editors:
            editor.newTarget(self.__value)

    def _get_value(self):
        return self.__value

    value = property(_get_value, _set_value)

    def _set_cls(self, cls):
        if cls is not None:

            def onAction(control, *ignore):
                return self.newModel(control, cls, *ignore)

            self.new.onAction = onAction
        self._cls = cls

    def _get_cls(self):
        return self._cls

    cls = property(
        _get_cls, _set_cls, None, """
        The CRUD's 'class'. This is, the callable used to create
        a new object of the type the CRUD is editing.""")

    def _set_store(self, store):
        self.__store = store
        self.search.searcher = store
        for editor in self.editors:
            editor.store = store

    def _get_store(self):
        return self.__store

    store = property(_get_store, _set_store, None, """""")

    def newModel(self, control, cls, *ignore):
        """
        Create a new object and point the CRUD at it.
        """
        value = cls()
        self.store.track(value)
        self.changeModel(control, value)

    def changeModel(self, control, model=None):
        """
        Updates the CRUD's currently-in-edition object.
        """
        if model is None:
            value = self.search.value
        else:
            value = model
        logger.debug( ` value `)
        self.commitValue(value)

        if value is not None:
            self.note.activate(1)
            # and this?
            # self.editor.focus ()

    def save(self, *ignore):
        self.store.save()
        # FIXME: really?
        self.onAction()

    def discard(self):
        self.store.discard()

    def fromXmlObj(cls, xmlObj):
        """
        See L{XmlMixin.fromXmlObj
        <fvl.cimarron.skins.common.XmlMixin.fromXmlObj>}
        """
        self = cls()
        root = xmlObj
        attrs = {self: cls.attributesToConnect()}
        idDict = {}

        xmlObj = xmlObj.children
        first = True
        second = False
        while xmlObj:
            (obj, attrsInChild, idDictInChild) = \
                  self.childFromXmlObj(xmlObj)
            if obj is not None:
                if first:
                    obj.parent = self.firstTab
                    self.search = obj
                    first = False
                    second = True
                else:
                    obj.parent = self.note
                    self.editors.append(obj)
                    if second:
                        self.mainWidget = obj
                        obj.onAction = self.save
                        second = False

                attrs.update(attrsInChild)
            idDict.update(idDictInChild)
            xmlObj = xmlObj.next

        # at this time, so it has time to do the <import>s
        self.fromXmlObjProps(root.properties)
        try:
            idDict[self.id] = self
        except AttributeError:
            # have no id, ignore
            pass

        return (self, attrs, idDict)

    fromXmlObj = classmethod(fromXmlObj)