当前位置: 首页>>代码示例>>Python>>正文


Python BasicDialog.set_confirm_widget方法代码示例

本文整理汇总了Python中stoqlib.gui.base.dialogs.BasicDialog.set_confirm_widget方法的典型用法代码示例。如果您正苦于以下问题:Python BasicDialog.set_confirm_widget方法的具体用法?Python BasicDialog.set_confirm_widget怎么用?Python BasicDialog.set_confirm_widget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在stoqlib.gui.base.dialogs.BasicDialog的用法示例。


在下文中一共展示了BasicDialog.set_confirm_widget方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: BaseEditor

# 需要导入模块: from stoqlib.gui.base.dialogs import BasicDialog [as 别名]
# 或者: from stoqlib.gui.base.dialogs.BasicDialog import set_confirm_widget [as 别名]
class BaseEditor(BaseEditorSlave, RunnableView):
    """ Base class for editor dialogs. It offers methods of
    BaseEditorSlave, a windows title and OK/Cancel buttons.
    """

    #: the model type name of the model we are editing.
    #: This value will be showed in the title of the editor and can not
    #: be merely the attribute __name__ of the object for usability reasons.
    #: Call sites will decide what could be the best name applicable in each
    #: situation.
    model_name = None
    header = ''
    size = ()
    title = None
    hide_footer = False
    #: a list of widget names that when activated will confirm the dialog
    confirm_widgets = ()
    help_section = None
    form_holder_name = 'toplevel'

    def __init__(self, store, model=None, visual_mode=False):
        if store is not None and isinstance(store, StoqlibStore):
            store.needs_retval = True
        self._confirm_disabled = False

        # FIXME:
        # BasicEditor should inheirt from BasicDialog and instantiate
        # the slave inside here, but it requires some major surgery
        BaseEditorSlave.__init__(self, store, model,
                                 visual_mode=visual_mode)

        self.main_dialog = BasicDialog(title=self.get_title(self.model),
                                       header_text=self.header,
                                       help_section=self.help_section,
                                       size=self.size)
        # Do not close the dialog if re return False on self.confirm
        self.main_dialog.enable_confirm_validation = True
        self.main_dialog.attach_slave("main", self)
        self.main_dialog.connect('confirm', self._on_main_dialog__confirm)
        self.main_dialog.connect('cancel', self._on_main_dialog__cancel)

        # This helps kiwis ui test, set the name of ourselves to
        # the classname of the slave, which is much more helpful than
        # just "BasicDialog"
        self.main_dialog.get_toplevel().set_name(self.__class__.__name__)

        if self.hide_footer or self.visual_mode:
            self.main_dialog.hide_footer()

        for name in self.confirm_widgets:
            self.set_confirm_widget(getattr(self, name))

        self.register_validate_function(self._validation_function)
        self.force_validation()

    def _get_title_format(self):
        if self.visual_mode:
            return _(u"Details of %s")
        if self.edit_mode:
            return _(u'Edit Details of "%s"')
        return _(u"Add %s")

    def get_title(self, model):
        if self.title:
            return self.title
        if not model:
            raise ValueError("A model should be defined at this point")

        title_format = self._get_title_format()
        if self.model_name:
            model_name = self.model_name
        else:
            # Fallback to the name of the class
            model_name = type(self.model).__name__

        return title_format % model_name

    def enable_window_controls(self):
        """Enables the window controls
        See :class:`kiwi.ui.views.BaseView.enable_window_controls`.
        """
        self.main_dialog.enable_window_controls()

    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
        status """
        if self._confirm_disabled:
            return
        self.main_dialog.ok_button.set_sensitive(validation_value)

    def add_button(self, label=None, stock=None):
        """
        Adds a button to editor. The added button is returned which you
#.........这里部分代码省略.........
开发者ID:romaia,项目名称:stoq,代码行数:103,代码来源:baseeditor.py

示例2: BaseEditor

# 需要导入模块: from stoqlib.gui.base.dialogs import BasicDialog [as 别名]
# 或者: from stoqlib.gui.base.dialogs.BasicDialog import set_confirm_widget [as 别名]
class BaseEditor(BaseEditorSlave, RunnableView):
    """ Base class for editor dialogs. It offers methods of
    BaseEditorSlave, a windows title and OK/Cancel buttons.
    """

    #: the model type name of the model we are editing.
    #: This value will be showed in the title of the editor and can not
    #: be merely the attribute __name__ of the object for usability reasons.
    #: Call sites will decide what could be the best name applicable in each
    #: situation.
    model_name = None
    header = ''
    size = ()
    title = None
    hide_footer = False

    #: if we need to ask the user if he really wants to cancel the dialog if
    #: there are any changes done that would be lost otherwise
    need_cancel_confirmation = False

    #: a list of widget names that when activated will confirm the dialog
    confirm_widgets = ()
    help_section = None
    form_holder_name = 'toplevel'

    def __init__(self, store, model=None, visual_mode=False):
        self._confirm_disabled = False

        # FIXME:
        # BasicEditor should inheirt from BasicDialog and instantiate
        # the slave inside here, but it requires some major surgery
        BaseEditorSlave.__init__(self, store, model,
                                 visual_mode=visual_mode)

        self.main_dialog = BasicDialog(title=self.get_title(self.model),
                                       header_text=self.header,
                                       help_section=self.help_section,
                                       size=self.size)
        # Do not close the dialog if re return False on self.confirm
        self.main_dialog.enable_confirm_validation = True
        self.main_dialog.attach_slave("main", self)
        self.main_dialog.connect('confirm', self._on_main_dialog__confirm)
        self.main_dialog.connect('cancel', self._on_main_dialog__cancel)

        dialog_toplevel = self.main_dialog.get_toplevel()
        dialog_toplevel.connect('response', self._on_toplevel__response)
        dialog_toplevel.connect('delete-event', self._on_toplevel__delete_event)

        # This helps kiwis ui test, set the name of ourselves to
        # the classname of the slave, which is much more helpful than
        # just "BasicDialog"
        self.main_dialog.get_toplevel().set_name(self.__class__.__name__)

        if self.hide_footer or self.visual_mode:
            self.main_dialog.hide_footer()

        for name in self.confirm_widgets:
            self.set_confirm_widget(getattr(self, name))

        self.register_validate_function(self._validation_function)
        self.force_validation()
        # We need to use self.model instead of model, since BaseEditorSlave
        # will create one if its None
        EditorCreateEvent.emit(self, self.model, store, visual_mode)

        if store is not None:
            # This needs to be the last thing done on __init__ since we don't want
            # to consider things like self.create_model as a change
            self._store_pending_count = store.get_pending_count()

    #
    #  Private
    #

    def _get_title_format(self):
        if self.visual_mode:
            return _(u"Details of %s")
        if self.edit_mode:
            return _(u'Edit Details of "%s"')
        return _(u"Add %s")

    def _need_cancel_confirmation(self):
        return self.need_cancel_confirmation and self.has_changes()

    #
    #  Public
    #

    def has_changes(self):
        """Check if there are changes on this editor

        By default we will check if there're any pending changes on
        :obj:`.store` and that information will be used by
        :attr:`.need_cancel_confirmation`
        """
        if self.store is None:
            return False
        return self.store.get_pending_count() > self._store_pending_count

    def get_title(self, model):
#.........这里部分代码省略.........
开发者ID:Guillon88,项目名称:stoq,代码行数:103,代码来源:baseeditor.py


注:本文中的stoqlib.gui.base.dialogs.BasicDialog.set_confirm_widget方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。