Ejemplo n.º 1
0
 def __init__(self, msg, options, callback, emergency=0, **dargs):
     root = Root.instance
     itemsize = (80, 20)
     margin = 5
     self.emergency = emergency
     size = ((itemsize[0] + margin) * len(options) + margin, 200 + 3 * margin + itemsize[1])
     super(OptionDialog, self).__init__(
         root,
         size=size,
         pos=((root.size[0] - size[0]) / 2, (root.size[1] - size[1]) / 2),
         bgcolor=(0x9F, 0xAF, 0xFF, 0xFF),
         level=Root.DIALOG_LEVEL,
         **dargs
     )
     TextBox(
         self,
         text=msg,
         pos=(margin, margin),
         size=(size[0] - 2 * margin, 200),
         bgcolor=(0, 0, 0, 0x88),
         color=(0xFF, 0xFF, 0xFF),
         fontsize=14,
     )
     self.callback = callback
     for i, opt in enumerate(options):
         btn = Button(self, pos=(margin + i * (itemsize[0] + margin), 200 + 2 * margin), caption=opt, size=itemsize)
         btn.bind_command(lambda i=i: self.choose(i))
Ejemplo n.º 2
0
    def __init__(self, msg, callbackOnConfrim, emergency=0, default="", **dargs):
        """
        msg: the prompt message
        default: the default input text
        callbackOnConfrim: shoud be a function with the inputed string as the argument
        """
        self.emergency = emergency
        root = Root.instance
        size = 400, 260
        super(Dialog, self).__init__(
            root,
            size=size,
            pos=((root.size[0] - size[0]) / 2, (root.size[1] - size[1]) / 2),
            bgcolor=(0x9F, 0xAF, 0xFF, 0xFF),
            level=Root.DIALOG_LEVEL,
            **dargs
        )
        self.msgbox = TextBox(
            self, text=msg, pos=(5, 5), size=(390, 200), bgcolor=(0, 0, 0, 0x88), color=(0xFF, 0xFF, 0xFF), fontsize=14
        )
        self.input = InputBox(self, text=default, pos=(5, 210), size=(390, 20))
        btn_confirm = Button(self, pos=(5, 235), caption="confirm", size=(100, 20))
        btn_cancel = Button(self, pos=(295, 235), caption="cancel", size=(100, 20))

        self.callbackOnConfrim = callbackOnConfrim
        btn_confirm.bind_command(self.confirm)
        btn_cancel.bind_command(self.cancel)
        self.bind_key(K_ESCAPE, self.cancel)

        self.input.set_as_focus()
Ejemplo n.º 3
0
 def add_item(self, name, callback):
     wi, hi = self.itemsize
     margin = self.margin
     if not self.vertical:
         y = margin
         x = (self.itemsize[0])* len(self.items)
     else:
         x = margin
         y = (self.itemsize[1]) * len(self.items)
     item = Button(self, caption=name, size=self.itemsize, pos=(x, y), 
             color=self.color, bgcolor=self.bgcolor,
             align=Button.ALIGN_CENTER)
     item.bind_command(callback)
     # item.bind(EV_CLICK, self.hide, BLK_PRE_BLOCK)
     self.items.append(item)
     self.resize(self.cal_size())
     self.mark_redraw()