[POS-commit] r5441 - in stoqlib/trunk/stoqlib/gui: base editors

Johan Dahlin jdahlin at async.com.br
Mon Dec 4 09:27:24 BRST 2006


Author: jdahlin
Date: Mon Dec  4 09:27:23 2006
New Revision: 5441

Modified:
   stoqlib/trunk/stoqlib/gui/base/editors.py
   stoqlib/trunk/stoqlib/gui/editors/addresseditor.py
   stoqlib/trunk/stoqlib/gui/editors/categoryeditor.py
   stoqlib/trunk/stoqlib/gui/editors/contacteditor.py
   stoqlib/trunk/stoqlib/gui/editors/deliveryeditor.py
   stoqlib/trunk/stoqlib/gui/editors/fiscaleditor.py
   stoqlib/trunk/stoqlib/gui/editors/giftcertificateeditor.py
   stoqlib/trunk/stoqlib/gui/editors/paymentmethodeditor.py
   stoqlib/trunk/stoqlib/gui/editors/personeditor.py
   stoqlib/trunk/stoqlib/gui/editors/profileeditor.py
   stoqlib/trunk/stoqlib/gui/editors/sellableeditor.py
   stoqlib/trunk/stoqlib/gui/editors/serviceeditor.py
   stoqlib/trunk/stoqlib/gui/editors/stationeditor.py
   stoqlib/trunk/stoqlib/gui/templates/persontemplate.py

Log:
Get rid of get_title_model_attribute in favor of a set_description() method

Modified: stoqlib/trunk/stoqlib/gui/base/editors.py
==============================================================================
--- stoqlib/trunk/stoqlib/gui/base/editors.py	(original)
+++ stoqlib/trunk/stoqlib/gui/base/editors.py	Mon Dec  4 09:27:23 2006
@@ -25,7 +25,6 @@
 ##
 """ Base classes for editors """
 
-
 from kiwi.ui.delegates import GladeSlaveDelegate
 from kiwi.ui.widgets.label import ProxyLabel
 
@@ -35,7 +34,6 @@
 
 _ = stoqlib_gettext
 
-
 class BaseEditorSlave(GladeSlaveDelegate):
     """ Base class for editor slaves inheritance. It offers methods for
     setting up focus sequence, required attributes and validated attrs.
@@ -83,8 +81,8 @@
         else:
             raise ValueError("Editors must define a model_type or "
                              "model_iface attributes")
-
         self.model = model
+
         GladeSlaveDelegate.__init__(self, gladefile=self.gladefile)
         if self.visual_mode:
             self._setup_visual_mode()
@@ -159,13 +157,6 @@
                        Callsites will decide what could be the best name
                        applicable in each situation.
 
-    get_title_model_attribute = get a certain model attribute value to
-                                allow creating customized editor titles.
-                                Subclasses will choose the right attribute
-                                acording to the editor features and
-                                with usability in mind.
-                                The editor title has this format:
-                                'Edit "title_model_attr" Details'
     """
 
     model_name = None
@@ -177,13 +168,17 @@
     def __init__(self, conn, model=None, visual_mode=False):
         BaseEditorSlave.__init__(self, conn, model,
                                  visual_mode=visual_mode)
+
         # We can not use self.model for get_title since we will create a new
         # one in BaseEditorSlave if model is None.
         self.main_dialog = BasicWrappingDialog(self,
                                                self.get_title(self.model),
                                                self.header, self.size)
+
+
         if self.hide_footer or self.visual_mode:
             self.main_dialog.hide_footer()
+
         self.register_validate_function(self.refresh_ok)
         self.force_validation()
 
@@ -201,13 +196,21 @@
             raise ValueError("A model should be defined at this point")
 
         title_format = self._get_title_format()
-        if self.model_name and not self.edit_mode:
-            return title_format % self.model_name
-        model_attr = self.get_title_model_attribute(model)
-        return title_format % model_attr
+        if self.model_name:
+            model_name = self.model_name
+        else:
+            # Fallback to the name of the class
+            model_name = type(self.model).__name__
 
-    def get_title_model_attribute(self, model):
-        raise NotImplementedError
+        return title_format % model_name
+
+    def set_description(self, description):
+        """
+        Sets the description of the model object which is used by the editor
+        @param description:
+        """
+        format = self._get_title_format()
+        self.main_dialog.set_title(format % description)
 
     def refresh_ok(self, validation_value):
         """ Refreshes ok button sensitivity according to widget validators

Modified: stoqlib/trunk/stoqlib/gui/editors/addresseditor.py
==============================================================================
--- stoqlib/trunk/stoqlib/gui/editors/addresseditor.py	(original)
+++ stoqlib/trunk/stoqlib/gui/editors/addresseditor.py	Mon Dec  4 09:27:23 2006
@@ -79,6 +79,7 @@
         self.person = person
         self.current_main_address = self.person.get_main_address()
         BaseEditor.__init__(self, conn, model, visual_mode=visual_mode)
+        self.set_description(self.model_name)
 
     #
     # BaseEditor Hooks
@@ -89,9 +90,6 @@
         return Address(connection=self.conn, person=self.person,
                        city_location=ct_location)
 
-    def get_title_model_attribute(self, model):
-        return self.model_name
-
     def setup_slaves(self):
         self.address_slave = AddressSlave(self.conn, self.person, self.model,
                                           False,

Modified: stoqlib/trunk/stoqlib/gui/editors/categoryeditor.py
==============================================================================
--- stoqlib/trunk/stoqlib/gui/editors/categoryeditor.py	(original)
+++ stoqlib/trunk/stoqlib/gui/editors/categoryeditor.py	Mon Dec  4 09:27:23 2006
@@ -43,12 +43,11 @@
     def create_model(self, conn):
         return BaseSellableCategory(description=u"", connection=conn)
 
-    def get_title_model_attribute(self, model):
-        return model.get_description()
-
     def setup_proxies(self):
         self.add_proxy(model=self.model,
                        widgets=BaseSellableCategoryEditor.proxy_widgets)
+        self.set_description(self.model.get_description())
+
 
 class SellableCategoryEditor(BaseEditor):
     gladefile = 'SellableCategoryDataSlave'
@@ -64,9 +63,6 @@
             description=u"", base_category=sysparam(conn).DEFAULT_BASE_CATEGORY,
             connection=conn)
 
-    def get_title_model_attribute(self, model):
-        return model.get_description()
-
     def setup_combo(self):
         base_category_list = BaseSellableCategory.select(connection=self.conn)
         items = [(base_cat.description, base_cat)
@@ -79,3 +75,5 @@
         self.setup_combo()
         self.add_proxy(model=self.model,
                        widgets=SellableCategoryEditor.proxy_widgets)
+        self.set_description(self.model.get_description())
+

Modified: stoqlib/trunk/stoqlib/gui/editors/contacteditor.py
==============================================================================
--- stoqlib/trunk/stoqlib/gui/editors/contacteditor.py	(original)
+++ stoqlib/trunk/stoqlib/gui/editors/contacteditor.py	Mon Dec  4 09:27:23 2006
@@ -42,11 +42,10 @@
     # BaseEditor Hooks
     #
 
-    def get_title_model_attribute(self, model):
-        return model.name
-
     def create_model(self, conn):
         return Liaison(person=None, connection=conn)
 
     def setup_proxies(self):
         self.proxy = self.add_proxy(self.model, ContactEditor.proxy_widgets)
+        self.set_description(self.model.name)
+

Modified: stoqlib/trunk/stoqlib/gui/editors/deliveryeditor.py
==============================================================================
--- stoqlib/trunk/stoqlib/gui/editors/deliveryeditor.py	(original)
+++ stoqlib/trunk/stoqlib/gui/editors/deliveryeditor.py	Mon Dec  4 09:27:23 2006
@@ -66,6 +66,7 @@
         self.additional_info_label.set_color('Red')
         self.register_validate_function(self._validate_widgets)
         self.update_widgets()
+        self.set_description(self.model_name)
 
     def _validate_widgets(self, validation_value):
         if not self.delivery.get_items():
@@ -141,9 +142,6 @@
     # BaseEditor hooks
     #
 
-    def get_title_model_attribute(self, model):
-        return self.model_name
-
     def create_model(self, conn):
         self._check_products()
         self._check_sale()

Modified: stoqlib/trunk/stoqlib/gui/editors/fiscaleditor.py
==============================================================================
--- stoqlib/trunk/stoqlib/gui/editors/fiscaleditor.py	(original)
+++ stoqlib/trunk/stoqlib/gui/editors/fiscaleditor.py	Mon Dec  4 09:27:23 2006
@@ -43,15 +43,13 @@
     # BaseEditor Hooks
     #
 
-    def get_title_model_attribute(self, model):
-        return model.code
-
     def create_model(self, conn):
         return CfopData(code=u"", description=u"",
                         connection=conn)
 
     def setup_proxies(self):
         self.add_proxy(self.model, CfopEditor.proxy_widgets)
+        self.set_description(self.model.code)
 
 
 class FiscalBookEntryEditor(BaseEditor):

Modified: stoqlib/trunk/stoqlib/gui/editors/giftcertificateeditor.py
==============================================================================
--- stoqlib/trunk/stoqlib/gui/editors/giftcertificateeditor.py	(original)
+++ stoqlib/trunk/stoqlib/gui/editors/giftcertificateeditor.py	Mon Dec  4 09:27:23 2006
@@ -61,16 +61,15 @@
         return self.model_type(connection=conn,
                                base_sellable_info=sellable_info)
 
-    def get_title_model_attribute(self, model):
-        return model.base_sellable_info.description
-
     def setup_proxies(self):
         self.add_proxy(self.model, GiftCertificateTypeEditor.proxy_widgets)
+        self.set_description(self.model.base_sellable_info.description)
 
     def setup_slaves(self):
         self.slave = OnSaleInfoSlave(self.conn, self.model.on_sale_info)
         self.attach_slave('on_sale_holder', self.slave)
 
+
     def validate_confirm(self):
         if self.model.base_sellable_info.price <= 0:
             msg = _('Gift Certificate price must be greater than zero.')

Modified: stoqlib/trunk/stoqlib/gui/editors/paymentmethodeditor.py
==============================================================================
--- stoqlib/trunk/stoqlib/gui/editors/paymentmethodeditor.py	(original)
+++ stoqlib/trunk/stoqlib/gui/editors/paymentmethodeditor.py	Mon Dec  4 09:27:23 2006
@@ -48,6 +48,8 @@
         """
         self.model_type = AbstractPaymentMethodAdapter
         BaseEditor.__init__(self, conn, model)
+        self.set_description(model.description)
+
 
     def _setup_widgets(self):
         destinations = PaymentDestination.select(connection=self.conn)
@@ -58,9 +60,6 @@
     # BaseEditor Hooks
     #
 
-    def get_title_model_attribute(self, model):
-        return model.description
-
     def setup_proxies(self):
         self._setup_widgets()
         self.add_proxy(self.model, PaymentMethodEditor.proxy_widgets)

Modified: stoqlib/trunk/stoqlib/gui/editors/personeditor.py
==============================================================================
--- stoqlib/trunk/stoqlib/gui/editors/personeditor.py	(original)
+++ stoqlib/trunk/stoqlib/gui/editors/personeditor.py	Mon Dec  4 09:27:23 2006
@@ -279,13 +279,7 @@
         SimpleEntryEditor.__init__(self, conn, model, attr_name='name',
                                    name_entry_label=_('Role Name:'),
                                    visual_mode=visual_mode)
-
-    #
-    # BaseEditor Hooks
-    #
-
-    def get_title_model_attribute(self, model):
-        return model.name
+        self.set_description(model.name)
 
     #
     # BaseEditorSlave Hooks

Modified: stoqlib/trunk/stoqlib/gui/editors/profileeditor.py
==============================================================================
--- stoqlib/trunk/stoqlib/gui/editors/profileeditor.py	(original)
+++ stoqlib/trunk/stoqlib/gui/editors/profileeditor.py	Mon Dec  4 09:27:23 2006
@@ -49,15 +49,13 @@
     # BaseEditor Hooks
     #
 
-    def get_title_model_attribute(self, model):
-        return model.name
-
     def create_model(self, conn):
         return UserProfile(name='', connection=conn)
 
     def setup_proxies(self):
         self.proxy = self.add_proxy(self.model,
                                     UserProfileEditor.proxy_widgets)
+        self.set_description(self.model.name)
 
     def setup_slaves(self):
         settings = {}

Modified: stoqlib/trunk/stoqlib/gui/editors/sellableeditor.py
==============================================================================
--- stoqlib/trunk/stoqlib/gui/editors/sellableeditor.py	(original)
+++ stoqlib/trunk/stoqlib/gui/editors/sellableeditor.py	Mon Dec  4 09:27:23 2006
@@ -149,6 +149,8 @@
         self._original_barcode = self._sellable.barcode
         self.setup_widgets()
 
+        self.set_description(ISellable(model).base_sellable_info.description)
+
     def set_widget_formats(self):
         for widget in (self.cost, self.stock_total_lbl, self.price):
             widget.set_data_format('%.02f')
@@ -201,10 +203,6 @@
     # BaseEditor hooks
     #
 
-    def get_title_model_attribute(self, model):
-        sellable = ISellable(model)
-        return sellable.base_sellable_info.description
-
     def setup_combos(self):
         category_list = SellableCategory.select(connection=self.conn)
         items = [(cat.get_full_description(), cat) for cat in category_list]
@@ -287,6 +285,8 @@
             self.quantity.set_range(1, self.model.quantity)
         if not editable_price:
             self.disable_price_fields()
+        self.set_description(model.sellable.base_sellable_info.description)
+
 
     def _get_model_name(self, model_type):
         if not self.model_names.has_key(model_type):
@@ -302,9 +302,6 @@
     # BaseEditor hooks
     #
 
-    def get_title_model_attribute(self, model):
-        return model.sellable.base_sellable_info.description
-
     def setup_proxies(self):
         # We need to setup the widgets format before the proxy fill them
         # with the values.

Modified: stoqlib/trunk/stoqlib/gui/editors/serviceeditor.py
==============================================================================
--- stoqlib/trunk/stoqlib/gui/editors/serviceeditor.py	(original)
+++ stoqlib/trunk/stoqlib/gui/editors/serviceeditor.py	Mon Dec  4 09:27:23 2006
@@ -50,14 +50,11 @@
     def __init__(self, conn, model):
         BaseEditor.__init__(self, conn, model)
         self.service_name_label.set_bold(True)
-
+        self.set_description(model.sellable.base_sellable_info.description)
     #
     # BaseEditor hooks
     #
 
-    def get_title_model_attribute(self, model):
-        return model.sellable.base_sellable_info.description
-
     def setup_proxies(self):
         self.add_proxy(self.model, ServiceItemEditor.proxy_widgets)
 

Modified: stoqlib/trunk/stoqlib/gui/editors/stationeditor.py
==============================================================================
--- stoqlib/trunk/stoqlib/gui/editors/stationeditor.py	(original)
+++ stoqlib/trunk/stoqlib/gui/editors/stationeditor.py	Mon Dec  4 09:27:23 2006
@@ -50,8 +50,7 @@
             self.is_active.set_sensitive(False)
             self.branch.set_sensitive(False)
 
-    def get_title_model_attribute(self, model):
-        return model.name
+        self.set_description(model.name)
 
     def create_model(self, conn):
         return BranchStation(name=u"", branch=None,

Modified: stoqlib/trunk/stoqlib/gui/templates/persontemplate.py
==============================================================================
--- stoqlib/trunk/stoqlib/gui/templates/persontemplate.py	(original)
+++ stoqlib/trunk/stoqlib/gui/templates/persontemplate.py	Mon Dec  4 09:27:23 2006
@@ -261,6 +261,8 @@
         self.role_type = role_type
         self.person = person
         BaseEditor.__init__(self, conn, model, visual_mode=visual_mode)
+        # FIXME: Implement and use IDescribable on the model
+        self.set_description(self.model.person.name)
 
     def get_person_slave(self):
         return self.main_slave.get_person_slave()
@@ -292,10 +294,6 @@
     # BaseEditor hooks
     #
 
-    def get_title_model_attribute(self, model):
-        # FIXME: Implement and use IDescribable on the model
-        return model.person.name
-
 
     def create_model(self, conn):
         # XXX: Waiting fix for bug 2163. We should not need anymore to


More information about the POS-commit mailing list