Пример #1
0
 def setup_slaves(self):
     self.address_slave = AddressSlave(
         self.store, self.model, self.model.get_main_address(),
         visual_mode=self.visual_mode,
         db_form=self.db_form)
     self.attach_slave('address_holder', self.address_slave)
     self.attach_model_slave('note_holder', NoteSlave, self.model)
Пример #2
0
 def setup_slaves(self):
     self.address_slave = AddressSlave(
         self.store, self.model, self.model.get_main_address(),
         visual_mode=self.visual_mode,
         db_form=self.db_form)
     self.attach_slave('address_holder', self.address_slave)
     self.attach_model_slave('note_holder', NoteSlave, self.model)
Пример #3
0
class _PersonEditorTemplate(BaseEditorSlave):
    model_type = Person
    gladefile = 'PersonEditorTemplate'

    proxy_widgets = ('name',
                     'phone_number',
                     'fax_number',
                     'mobile_number',
                     'email')

    def __init__(self, store, model, visual_mode, ui_form_name, parent):
        self._parent = parent
        if ui_form_name:
            self.db_form = DatabaseForm(store, ui_form_name)
        else:
            self.db_form = None

        super(_PersonEditorTemplate, self).__init__(store, model,
                                                    visual_mode=visual_mode)
        self._check_new_person()

    def _check_new_person(self):
        self.is_new_person = False
        # If this person is not in the default store, then it was created
        # inside another transaction that was not commited yet.
        default_store = api.get_default_store()
        if default_store.find(Person, id=self.model.id).is_empty():
            self.is_new_person = True

    #
    # BaseEditorSlave hooks
    #

    def create_model(self, store):
        return Person(name=u"", store=store)

    def setup_proxies(self):
        self._setup_widgets()
        self._setup_form_fields()
        self.proxy = self.add_proxy(self.model,
                                    _PersonEditorTemplate.proxy_widgets)

    def setup_slaves(self):
        self.address_slave = AddressSlave(
            self.store, self.model, self.model.get_main_address(),
            visual_mode=self.visual_mode,
            db_form=self.db_form)
        self.attach_slave('address_holder', self.address_slave)
        self.attach_model_slave('note_holder', NoteSlave, self.model)

    def on_confirm(self):
        main_address = self.address_slave.model
        main_address.person = self.model

    #
    # Public API
    #

    def add_extra_tab(self, tab_label, slave, position=None):
        """Adds an extra tab to the editor

        :param tab_label: the label that will be display on the tab
        :param slave: the slave that will be attached to the new tab
        :param position: the position the tab will be attached
        """
        event_box = gtk.EventBox()
        self.person_notebook.append_page(event_box, gtk.Label(tab_label))
        self.attach_slave(tab_label, slave, event_box)
        event_box.show()

        if position is not None:
            self.person_notebook.reorder_child(event_box, position)
            self.person_notebook.set_current_page(position)

    def attach_role_slave(self, slave):
        self.attach_slave('role_holder', slave)

    def attach_model_slave(self, name, slave_type, slave_model):
        slave = slave_type(self.store, slave_model,
                           visual_mode=self.visual_mode)
        self.attach_slave(name, slave)
        return slave

    #
    # Kiwi handlers
    #

    def on_name__map(self, entry):
        self.name.grab_focus()

    def on_address_button__clicked(self, button):
        main_address = self.model.get_main_address()
        if not main_address.is_valid_model():
            msg = _(u"You must define a valid main address before\n"
                    "adding additional addresses")
            warning(msg)
            return

        result = run_dialog(AddressAdditionDialog, self._parent,
                            self.store, person=self.model,
                            reuse_store=self.is_new_person)
        if not result:
            return

        new_main_address = self.model.get_main_address()
        if new_main_address is not main_address:
            self.address_slave.set_model(new_main_address)

    def on_contact_info_button__clicked(self, button):
        run_dialog(ContactInfoListDialog, self._parent, self.store,
                   person=self.model, reuse_store=self.is_new_person)

    def on_calls_button__clicked(self, button):
        run_dialog(CallsSearch, self._parent, self.store,
                   person=self.model, reuse_store=self.is_new_person)

    def on_credit_check_history_button__clicked(self, button):
        run_dialog(CreditCheckHistorySearch, self._parent, self.store,
                   client=self.model.client, reuse_store=self.is_new_person)

    #
    # Private API
    #

    def _setup_widgets(self):
        individual = self.model.individual
        company = self.model.company
        if not (individual or company):
            raise DatabaseInconsistency('A person must have at least a '
                                        'company or an individual set.')
        tab_child = self.person_data_tab
        if individual and company:
            tab_text = _('Individual/Company Data')
            self.company_frame.set_label(_('Company Data'))
            self.company_frame.show()
            self.individual_frame.set_label(_('Individual Data'))
            self.individual_frame.show()
        elif individual:
            tab_text = _('Individual Data')
            self.company_frame.hide()
            self.individual_frame.set_label('')
            self.individual_frame.show()
        else:
            tab_text = _('Company Data')
            self.individual_frame.hide()
            self.company_frame.set_label('')
            self.company_frame.show()
        self.person_notebook.set_tab_label_text(tab_child, tab_text)
        addresses = self.model.get_total_addresses()
        if addresses == 2:
            self.address_button.set_label(_("1 More Address..."))
        elif addresses > 2:
            self.address_button.set_label(_("%i More Addresses...")
                                          % (addresses - 1))
        if not self.model.client:
            self.credit_check_history_button.hide()

    def _setup_form_fields(self):
        if not self.db_form:
            return
        self.db_form.update_widget(self.name,
                                   other=self.name_lbl)
        self.db_form.update_widget(self.phone_number,
                                   other=self.phone_number_lbl)
        self.db_form.update_widget(self.fax_number, u'fax',
                                   other=self.fax_lbl)
        self.db_form.update_widget(self.email,
                                   other=self.email_lbl)
        self.db_form.update_widget(self.mobile_number,
                                   other=self.mobile_lbl)
Пример #4
0
 def _setup_slaves(self):
     address = self.model.get_main_address()
     self._address_slave = AddressSlave(self.store, self.model, address)
     self.attach_slave("address_holder", self._address_slave)
Пример #5
0
class _PersonEditorTemplate(BaseEditorSlave):
    model_type = Person
    gladefile = 'PersonEditorTemplate'

    proxy_widgets = ('name', 'phone_number', 'fax_number', 'mobile_number',
                     'email')

    def __init__(self, store, model, visual_mode, ui_form_name, parent):
        self._parent = parent
        if ui_form_name:
            self.db_form = DatabaseForm(ui_form_name)
        else:
            self.db_form = None

        super(_PersonEditorTemplate, self).__init__(store,
                                                    model,
                                                    visual_mode=visual_mode)

    #
    # BaseEditorSlave hooks
    #

    def create_model(self, store):
        return Person(name=u"", store=store)

    def setup_proxies(self):
        self._setup_widgets()
        self._setup_form_fields()
        self.proxy = self.add_proxy(self.model,
                                    _PersonEditorTemplate.proxy_widgets)

    def setup_slaves(self):
        self.address_slave = AddressSlave(self.store,
                                          self.model,
                                          self.model.get_main_address(),
                                          visual_mode=self.visual_mode,
                                          db_form=self.db_form)
        self.attach_slave('address_holder', self.address_slave)
        self.attach_model_slave('note_holder', NoteSlave, self.model)

    def on_confirm(self):
        main_address = self.address_slave.model
        main_address.person = self.model

    #
    # Public API
    #

    def add_extra_tab(self, tab_label, slave, position=None):
        """Adds an extra tab to the editor

        :param tab_label: the label that will be display on the tab
        :param slave: the slave that will be attached to the new tab
        :param position: the position the tab will be attached
        """
        event_box = gtk.EventBox()
        self.person_notebook.append_page(event_box, gtk.Label(tab_label))
        self.attach_slave(tab_label, slave, event_box)
        event_box.show()

        if position is not None:
            self.person_notebook.reorder_child(event_box, position)
            self.person_notebook.set_current_page(position)

    def attach_role_slave(self, slave):
        self.attach_slave('role_holder', slave)

    def attach_model_slave(self, name, slave_type, slave_model):
        slave = slave_type(self.store,
                           slave_model,
                           visual_mode=self.visual_mode)
        self.attach_slave(name, slave)
        return slave

    #
    # Kiwi handlers
    #

    def on_name__map(self, entry):
        self.name.grab_focus()

    def on_address_button__clicked(self, button):
        main_address = self.model.get_main_address()
        if not main_address.is_valid_model():
            msg = _(u"You must define a valid main address before\n"
                    "adding additional addresses")
            warning(msg)
            return

        result = run_dialog(AddressAdditionDialog,
                            self._parent,
                            self.store,
                            person=self.model,
                            reuse_store=not self.visual_mode)
        if not result:
            return

        new_main_address = self.model.get_main_address()
        if new_main_address is not main_address:
            self.address_slave.set_model(new_main_address)

    def on_contact_info_button__clicked(self, button):
        run_dialog(ContactInfoListDialog,
                   self._parent,
                   self.store,
                   person=self.model,
                   reuse_store=not self.visual_mode)

    def on_calls_button__clicked(self, button):
        run_dialog(CallsSearch,
                   self._parent,
                   self.store,
                   person=self.model,
                   reuse_store=not self.visual_mode)

    def on_credit_check_history_button__clicked(self, button):
        run_dialog(CreditCheckHistorySearch,
                   self._parent,
                   self.store,
                   client=self.model.client,
                   reuse_store=not self.visual_mode)

    #
    # Private API
    #

    def _setup_widgets(self):
        individual = self.model.individual
        company = self.model.company
        if not (individual or company):
            raise DatabaseInconsistency('A person must have at least a '
                                        'company or an individual set.')
        tab_child = self.person_data_tab
        if individual and company:
            tab_text = _('Individual/Company Data')
            self.company_frame.set_label(_('Company Data'))
            self.company_frame.show()
            self.individual_frame.set_label(_('Individual Data'))
            self.individual_frame.show()
        elif individual:
            tab_text = _('Individual Data')
            self.company_frame.hide()
            label_widget = self.individual_frame.get_label_widget()
            if label_widget is not None:
                label_widget.hide()
            self.individual_frame.show()
        else:
            tab_text = _('Company Data')
            self.individual_frame.hide()
            label_widget = self.company_frame.get_label_widget()
            if label_widget is not None:
                label_widget.hide()
            self.company_frame.show()
        self.person_notebook.set_tab_label_text(tab_child, tab_text)
        addresses = self.model.get_total_addresses()
        if addresses == 2:
            self.address_button.set_label(_("1 More Address..."))
        elif addresses > 2:
            self.address_button.set_label(
                _("%i More Addresses...") % (addresses - 1))
        if not self.model.client:
            self.credit_check_history_button.hide()

    def _setup_form_fields(self):
        if not self.db_form:
            return
        self.db_form.update_widget(self.name, other=self.name_lbl)
        self.db_form.update_widget(self.phone_number,
                                   other=self.phone_number_lbl)
        self.db_form.update_widget(self.fax_number, u'fax', other=self.fax_lbl)
        self.db_form.update_widget(self.email, other=self.email_lbl)
        self.db_form.update_widget(self.mobile_number, other=self.mobile_lbl)
Пример #6
0
 def setup_slaves(self):
     self.address_slave = AddressSlave(self.store, self.person, self.model,
                                       is_main_address=False,
                                       visual_mode=self.visual_mode)
     self.attach_slave('main_holder', self.address_slave)