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


Python Label.resize方法代码示例

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


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

示例1: InputBox

# 需要导入模块: from label import Label [as 别名]
# 或者: from label.Label import resize [as 别名]

#.........这里部分代码省略.........
            cb()
        self.mark_redraw()
        self._confirmed = True

    def bind_on_confirm(self, cb):
        self.confirmCallBacks.append(cb)

    def bind_on_change(self, cb):
        self.changeCallBacks.append(cb)

    def clear_callbacks(self):
        del self.changeCallBacks[:]
        del self.confirmCallBacks[:]

    def on_change(self):
        self._confirmed = False
        for cb in self.changeCallBacks:
            cb()

    def input(self, event):
        if event.key in (pg.K_BACKSPACE, pg.K_DELETE, pg.K_LEFT):
            self.text = self.text[:-1]
            self.on_change()
        elif event.key == pg.K_v and (event.mod & pg.KMOD_CTRL):
            self.paste_from_X()
            self.on_change()
        elif event.key == pg.K_c and (event.mod & pg.KMOD_CTRL):
            self.copy_to_X()
        elif event.key == K_RETURN:
            self.on_confirm()
            if config.SWITCH_ON_CONFIRM:
                focus.set_focus(focus.next_focus())
        elif event.unicode in self.chars:
            self.text = self.text + str(event.unicode)
            self.on_change()
        self.txtLabel.text = self.text
        self.mark_redraw()

    def animate(self, dt):
        bg = self.bgLabel
        blinker = self.blinker
        if self._editing:
            bg.bgcolor = blinker.get()
            bg.redraw()
            if blinker.is_end():
                if self._blinkState == 0:
                    self.blinker = ColorAnimate(self.blinkcolor, self.bgcolor)
                    self._blinkState = 1
                else:
                    # self.start_blink()
                    self.blinker = ColorAnimate(self.bgcolor, self.blinkcolor)
                    self._blinkState = 0
        elif not color_eq(blinker.get(), self.bgcolor):
            bg.bgcolor = blinker.get()
            bg.redraw()

    def resize(self, s):
        super(InputBox, self).resize(s)
        try:
            self.hoverButton.resize(s)
            self.bgLabel.resize(s)
            self.txtLabel.resize(s)
        except AttributeError:
            pass

    def bind_setter(self, obj, attr, eval_):
        def setter(obj=obj):
            try:
                v = eval_(self.text)
                setattr(obj, attr, v)
                obj.mark_redraw()
            except Exception as v:
                warn(str(v))
                v = getattr(obj, attr)
                self.text = str(v)
        self.bind_on_confirm(setter)

    def redraw(self):
        # w0, h0 = self.size
        # tw, th = self.txtLabel.Font.size(self.text)
        # w1 = max(self.minWidth, tw)
        # h1 = max(self.minHeight, th)
        # if w1 != w0 or h1 != h0:
        #     self.pos = (self.pos[0] - (w1 - w0)/2, self.pos[1] - (h1 - h0)/2)
        #     self.resize((w1, h1))
        charW = self.txtLabel.Font.size('a')[0]
        w = self.size[0]
        maxc = w / charW
        if maxc >= len(self.text):
            self.txtLabel.text = self.text
        else:
            self.txtLabel.text = '..' + self.text[-(maxc-2):]

    def copy_to_X(self):
        copy_to_X(self.text)

    def paste_from_X(self):
        self.text = paste_from_X()
        self.txtLabel.text = self.text
        self.mark_redraw()
开发者ID:ZhanruiLiang,项目名称:servoflash,代码行数:104,代码来源:inputbox.py


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