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


Python Screen.clear方法代码示例

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


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

示例1: Form

# 需要导入模块: from tryton.gui.window.view_form.screen import Screen [as 别名]
# 或者: from tryton.gui.window.view_form.screen.Screen import clear [as 别名]

#.........这里部分代码省略.........
        message_str = ''
        for line in res:
            for (key, val) in fields:
                value = str(line.get(key, False) or '/')
                if line.get(key, False) \
                        and key in ('create_date', 'write_date'):
                    date = timezoned_date(line[key])
                    value = common.datetime_strftime(date, datetime_format)
                message_str += val + ' ' + value + '\n'
        message_str += _('Model:') + ' ' + self.model
        message(message_str)
        return True

    def revision(self, widget=None):
        if not self.modified_save():
            return
        current_id = (self.screen.current_record.id
            if self.screen.current_record else None)
        try:
            revisions = RPCExecute('model', self.model, 'history_revisions',
                [r.id for r in self.screen.selected_records])
        except RPCException:
            return
        revision = self.screen.context.get('_datetime')
        format_ = self.screen.context.get('date_format', '%x')
        format_ += ' %X.%f'
        revision = Revision(revisions, revision, format_).run()
        # Prevent too old revision in form view
        if (self.screen.current_view.view_type == 'form'
                and revision
                and revision < revisions[-1][0]):
                revision = revisions[-1][0]
        if revision != self.screen.context.get('_datetime'):
            self.screen.clear()
            # Update root group context that will be propagated
            self.screen.group._context['_datetime'] = revision
            if self.screen.current_view.view_type != 'form':
                self.screen.search_filter(
                    self.screen.screen_container.get_text())
            else:
                # Test if record exist in revisions
                self.screen.load([current_id])
            self.screen.display(set_cursor=True)
            self.update_revision()

    def update_revision(self):
        revision = self.screen.context.get('_datetime')
        if revision:
            format_ = self.screen.context.get('date_format', '%x')
            format_ += ' %X.%f'
            revision = datetime_strftime(revision, format_)
            self.title.set_label('%s @ %s' % (self.name, revision))
        else:
            self.title.set_label(self.name)
        self.set_buttons_sensitive(revision)

    def set_buttons_sensitive(self, revision=None):
        if not revision:
            access = common.MODELACCESS[self.model]
            self.buttons['new'].props.sensitive = access['create']
            self.buttons['save'].props.sensitive = (
                access['create'] or access['write'])
        else:
            for button in ['new', 'save']:
                self.buttons[button].props.sensitive = False
开发者ID:coopengo,项目名称:tryton,代码行数:69,代码来源:form.py

示例2: Many2ManySelection

# 需要导入模块: from tryton.gui.window.view_form.screen import Screen [as 别名]
# 或者: from tryton.gui.window.view_form.screen.Screen import clear [as 别名]
class Many2ManySelection(Widget, SelectionMixin):
    expand = True

    def __init__(self, view, attrs):
        super(Many2ManySelection, self).__init__(view, attrs)

        self.widget = gtk.VBox(homogeneous=False, spacing=5)

        hbox = gtk.HBox(homogeneous=False, spacing=0)
        hbox.set_border_width(2)

        label = gtk.Label(attrs.get("string", ""))
        label.set_alignment(0.0, 0.5)
        hbox.pack_start(label, expand=True, fill=True)

        frame = gtk.Frame()
        frame.add(hbox)
        frame.set_shadow_type(gtk.SHADOW_OUT)
        self.widget.pack_start(frame, expand=False, fill=True)

        self.screen = Screen(
            attrs["relation"],
            view_ids=attrs.get("view_ids", "").split(","),
            mode=["tree"],
            views_preload=attrs.get("views", {}),
        )
        self.screen.new_group()
        self.treeview = self.screen.current_view.treeview
        self.treeview.get_selection().connect("changed", self.changed)
        self.treeview.connect("focus-out-event", lambda *a: self._focus_out())

        self.treeview.connect("button-press-event", self.button_press_event)
        self.treeview.connect("key-press-event", self.key_press_event)

        self.widget.pack_start(self.screen.widget, expand=True, fill=True)

        self.nullable_widget = False
        self.init_selection()

    @property
    def modified(self):
        if self.record and self.field:
            group = set(r.id for r in self.field.get_client(self.record))
            value = set(self.get_value())
            return value != group
        return False

    def changed(self, selection):
        def focus_out():
            if self.widget.props.window:
                self._focus_out()

        # Must be deferred because it triggers a display of the form
        gobject.idle_add(focus_out)

    def button_press_event(self, treeview, event):
        # grab focus because it doesn't whith CONTROL MASK
        treeview.grab_focus()
        if event.button == 1:
            event.state ^= gtk.gdk.CONTROL_MASK

    def key_press_event(self, treeview, event):
        if event.keyval in MOVEMENT_KEYS:
            event.state ^= gtk.gdk.CONTROL_MASK

    def get_value(self):
        return [r.id for r in self.screen.selected_records]

    def set_value(self, record, field):
        field.set_client(record, self.get_value())

    def display(self, record, field):
        selection = self.treeview.get_selection()
        selection.handler_block_by_func(self.changed)
        try:
            self.update_selection(record, field)
            super(Many2ManySelection, self).display(record, field)
            if field is None:
                self.screen.clear()
                self.screen.current_record = None
                self.screen.parent = None
            else:
                self.screen.parent = record
                current_ids = [r.id for r in self.screen.group]
                new_ids = [s[0] for s in self.selection]
                if current_ids != new_ids:
                    self.screen.clear()
                    self.screen.load(new_ids)
                group = field.get_client(record)
                nodes = [[r.id] for r in group if r not in group.record_removed and r not in group.record_deleted]
                selection.unselect_all()
                self.screen.current_view.select_nodes(nodes)
            self.screen.display()
        finally:
            selection.handler_unblock_by_func(self.changed)
开发者ID:coopengo,项目名称:tryton,代码行数:97,代码来源:many2many_selection.py


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