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


Python Entry.set_text方法代码示例

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


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

示例1: SpinBox

# 需要导入模块: from entry import Entry [as 别名]
# 或者: from entry.Entry import set_text [as 别名]

#.........这里部分代码省略.........
        for timeout_id in [self.increase_value_id, self.decrease_value_id]:
            remove_timeout_id(timeout_id)

    def increase_value(self):
        '''
        Internal function to increase value.
        '''
        new_value = self.current_value + self.step_value
        if new_value > self.upper_value:
            new_value = self.upper_value
        if new_value != self.current_value:
            self.update_and_emit(new_value)

        return True

    def decrease_value(self):
        '''
        Internal function to decrease value.
        '''
        new_value = self.current_value - self.step_value
        if new_value < self.lower_value:
            new_value = self.lower_value
        if new_value != self.current_value:
            self.update_and_emit(new_value)

        return True

    def adjust_value(self, value):
        '''
        Internal function to adjust value.
        '''
        if not isinstance(value, int):
            return self.current_value
        else:
            if value < self.lower_value:
                return self.lower_value
            elif value > self.upper_value:
                return self.upper_value
            else:
                return value

    def update(self, new_value):
        '''
        Internal function to update value, just use when need avoid emit signal recursively.
        '''
        self.current_value = new_value
        self.value_entry.set_text(str(self.current_value))

    def update_and_emit(self, new_value):
        '''
        Internal function to update new value and emit `value-changed` signal.
        '''
        self.current_value = new_value
        self.value_entry.set_text(str(self.current_value))
        self.emit("value-changed", self.current_value)

    def expose_spin_bg(self, widget, event):
        '''
        Internal callback for `expose-event` signal.
        '''
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation
        x, y, w, h = rect.x, rect.y, rect.width, rect.height

        # Draw frame.
        with cairo_disable_antialias(cr):
            cr.set_line_width(1)
            if widget.state == gtk.STATE_INSENSITIVE:
                cr.set_source_rgb(*color_hex_to_cairo(ui_theme.get_color("disable_frame").get_color()))
            else:
                cr.set_source_rgb(*color_hex_to_cairo(ui_theme.get_color("combo_entry_frame").get_color()))
            cr.rectangle(rect.x, rect.y, rect.width, rect.height)
            cr.stroke()

            if widget.state == gtk.STATE_INSENSITIVE:
                cr.set_source_rgba(*alpha_color_hex_to_cairo((ui_theme.get_color("disable_background").get_color(), 0.9)))
            else:
                cr.set_source_rgba(*alpha_color_hex_to_cairo((ui_theme.get_color("combo_entry_background").get_color(), 0.9)))
            cr.rectangle(rect.x, rect.y, rect.width - 1, rect.height - 1)
            cr.fill()

        propagate_expose(widget, event)

        return False

    def create_simple_button(self, name, callback=None):
        '''
        Internal function to create simple button.
        '''
        button = DisableButton(
            (ui_theme.get_pixbuf("spin/spin_arrow_%s_normal.png" % name),
             ui_theme.get_pixbuf("spin/spin_arrow_%s_hover.png" % name),
             ui_theme.get_pixbuf("spin/spin_arrow_%s_press.png" % name),
             ui_theme.get_pixbuf("spin/spin_arrow_%s_disable.png" % name)),
            )
        if callback:
            button.connect("button-press-event", callback)
            button.connect("button-release-event", self.handle_key_release)
        return button
开发者ID:chenzhiwei,项目名称:deepin-ui,代码行数:104,代码来源:spin.py

示例2: SpinBox

# 需要导入模块: from entry import Entry [as 别名]
# 或者: from entry.Entry import set_text [as 别名]

#.........这里部分代码省略.........
        self.stop_update_value()

        self.decrease_value()

        self.decrease_value_id = gtk.timeout_add(self.update_delay, self.decrease_value)

    def handle_key_release(self, widget, event):
        """Handle key release."""
        self.stop_update_value()

        self.emit("key-release", self.current_value)

    def stop_update_value(self):
        """Stop update value."""
        for timeout_id in [self.increase_value_id, self.decrease_value_id]:
            remove_timeout_id(timeout_id)

    def increase_value(self):
        new_value = self.current_value + self.step_value
        if new_value > self.upper_value:
            new_value = self.upper_value
        if new_value != self.current_value:
            self.update_and_emit(new_value)

        return True

    def decrease_value(self):
        new_value = self.current_value - self.step_value
        if new_value < self.lower_value:
            new_value = self.lower_value
        if new_value != self.current_value:
            self.update_and_emit(new_value)

        return True

    def adjust_value(self, value):
        if not isinstance(value, int):
            return self.current_value
        else:
            if value < self.lower_value:
                return self.lower_value
            elif value > self.upper_value:
                return self.upper_value
            else:
                return value

    def update(self, new_value):
        """Update value, just use when need avoid emit signal recursively."""
        self.current_value = new_value
        self.value_entry.set_text(str(self.current_value))

    def update_and_emit(self, new_value):
        self.current_value = new_value
        self.value_entry.set_text(str(self.current_value))
        self.emit("value-changed", self.current_value)

    def expose_spin_bg(self, widget, event):
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation
        x, y, w, h = rect.x, rect.y, rect.width, rect.height

        # Draw frame.
        with cairo_disable_antialias(cr):
            cr.set_line_width(1)
            if widget.state == gtk.STATE_INSENSITIVE:
                cr.set_source_rgb(*color_hex_to_cairo(ui_theme.get_color("disable_frame").get_color()))
            else:
                cr.set_source_rgb(*color_hex_to_cairo(ui_theme.get_color("combo_entry_frame").get_color()))
            cr.rectangle(rect.x, rect.y, rect.width, rect.height)
            cr.stroke()

            if widget.state == gtk.STATE_INSENSITIVE:
                cr.set_source_rgba(
                    *alpha_color_hex_to_cairo((ui_theme.get_color("disable_background").get_color(), 0.9))
                )
            else:
                cr.set_source_rgba(
                    *alpha_color_hex_to_cairo((ui_theme.get_color("combo_entry_background").get_color(), 0.9))
                )
            cr.rectangle(rect.x, rect.y, rect.width - 1, rect.height - 1)
            cr.fill()

        propagate_expose(widget, event)

        return False

    def create_simple_button(self, name, callback=None):
        button = DisableButton(
            (
                ui_theme.get_pixbuf("spin/spin_arrow_%s_normal.png" % name),
                ui_theme.get_pixbuf("spin/spin_arrow_%s_hover.png" % name),
                ui_theme.get_pixbuf("spin/spin_arrow_%s_press.png" % name),
                ui_theme.get_pixbuf("spin/spin_arrow_%s_disable.png" % name),
            )
        )
        if callback:
            button.connect("button-press-event", callback)
            button.connect("button-release-event", self.handle_key_release)
        return button
开发者ID:netphi,项目名称:deepin-ui,代码行数:104,代码来源:spin.py


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