Ejemplo n.º 1
0
def input_text(prompt, width, initial=None, **kwds):
    box = Dialog(**kwds)
    d = box.margin

    def ok():
        box.dismiss(True)

    def cancel():
        box.dismiss(False)

    lb = Label(prompt)
    lb.topleft = (d, d)
    tf = TextField(width)
    if initial:
        tf.set_text(initial)
    tf.enter_action = ok
    tf.escape_action = cancel
    tf.top = lb.top
    tf.left = lb.right + 5
    box.add(lb)
    box.add(tf)
    tf.focus()
    box.shrink_wrap()
    if box.present():
        return tf.get_text()
    else:
        return None
Ejemplo n.º 2
0
def CheckBoxLabel(title, *args, **kw):
    tooltipText = kw.pop('tooltipText', None)

    cb = CheckBox(*args, **kw)
    lab = Label(title, fg_color=cb.fg_color)
    lab.mouse_down = cb.mouse_down

    if tooltipText:
        cb.tooltipText = tooltipText
        lab.tooltipText = tooltipText

    class CBRow(Row):
        margin = 0

        @property
        def value(self):
            return self.checkbox.value

        @value.setter
        def value(self, val):
            self.checkbox.value = val

    row = CBRow((lab, cb))
    row.checkbox = cb
    return row
Ejemplo n.º 3
0
class DialogHeader(Frame):
    def __init__(self, parent, text):
        Frame.__init__(self, parent)
        color = GetSysColor(2|0x40000000)
        r = color &0xff
        g = (color >> 8) &0xff
        b = (color >> 16) &0xff
        color = (r,g,b)
        self.label = Label(self, text, 
                           font=Font(size=8, 
                                     bold=True, 
                                     color=color 
                                     # XXX: Use system prefs instead of hardcoded blue
                                    )
                          )
        self.hline = HLine(self)
        sizer = VBox()
        sizer.add(Spacer(2,4))
        sizer.add(self.label, border=(4,0,0,0))
        sizer.add(Spacer(2,4))
        sizer.add(self.hline)
        self.sizer = sizer
        
    def set_text(self, text):
        self.label.set_text(text)
        
    def get_text(self):
        return self.label.get_text()
Ejemplo n.º 4
0
 def set_information(self, points, person, players):
     up_information = "Black :" + str(points[-1]) + "; White : " +\
                      str(points[1]) + "."
     self.up_information = Label(up_information,
                                 int(self.FIELD_START_WIDTH/10),
                                 (self.FIELD_START_WIDTH,
                                  self.FIELD_START_HEIGHT/5))
     down_information = ""
     if players[-1] != Player.man or players[1] != Player.man:
         down_information = "You " + \
                            ("black. " if players[-1] == Player.man else
                             "white. ")
     down_information += "Turn " + \
                         ("black. " if person == -1 else
                          "white. ")
     self.down_information = Label(down_information,
                                   int(self.FIELD_START_WIDTH/10),
                                   (self.FIELD_START_WIDTH,
                                    self.FIELD_START_HEIGHT/5*45))
Ejemplo n.º 5
0
class DialogHeader(Frame):
    def __init__(self, parent, text):
        Frame.__init__(self, parent)
        self.label = Label(self, text, 
                           font=Font(size=8, 
                                     bold=True, 
                                     color=(0,0,255) 
                                     # XXX: Use system prefs instead of hardcoded blue
                                    )
                          )
        self.hline = HLine(self)
        sizer = VBox()
        sizer.add(Spacer(2,4))
        sizer.add(self.label, border=(4,0,0,0))
        sizer.add(Spacer(2,4))
        sizer.add(self.hline)
        self.sizer = sizer
        
    def set_text(self, text):
        self.label.set_text(text)
        
    def get_text(self):
        return self.label.get_text()
Ejemplo n.º 6
0
def input_text_buttons(prompt, width, initial=None, allowed_chars=None, **kwds):
    box = Dialog(**kwds)
    d = box.margin

    def ok():
        box.dismiss(True)

    def cancel():
        box.dismiss(False)

    buts = [Button("OK", action=ok), Button("Cancel", action=cancel)]

    brow = Row(buts, spacing=d)

    lb = Label(prompt)
    lb.topleft = (d, d)
    tf = TextFieldWrapped(width,allowed_chars=allowed_chars)
    if initial:
        tf.set_text(initial)
    tf.enter_action = ok
    tf.escape_action = cancel
    tf.top = lb.top
    tf.left = lb.right + 5

    trow = Row([lb, tf], spacing=d)

    col = Column([trow, brow], spacing=d, align='c')

    col.topleft = (d, d)

    box.add(col)
    tf.focus()
    box.shrink_wrap()
    if box.present():
        return tf.get_text()
    else:
        return None
Ejemplo n.º 7
0
def CheckBoxLabel(title, *args, **kw):
    tooltipText = kw.pop('tooltipText', None)

    l_kw = {'margin': 0}
    b_kw = {'margin': 0}
    expand = kw.pop('expand', 'none')
    r_kw = {}
    if expand != 'none':
        r_kw['expand'] = expand

    align = kw.pop('align', None)
    if align:
        r_kw['align'] = align

    cb = CheckBox(*args, **kw)
    lab = Label(title, fg_color=cb.fg_color)
    lab.mouse_down = cb.mouse_down

    if tooltipText:
        cb.tooltipText = tooltipText
        lab.tooltipText = tooltipText

    class CBRow(Row):
        margin = 0

        @property
        def value(self):
            return self.checkbox.value

        @value.setter
        def value(self, val):
            self.checkbox.value = val

    row = CBRow((Column((lab,), **l_kw), Column((cb,), **b_kw)), **r_kw)
    row.checkbox = cb
    return row
Ejemplo n.º 8
0
class DialogHeader(Frame):
    def __init__(self, parent, text):
        Frame.__init__(self, parent)
        self.label = Label(
            self,
            text,
            font=Font(size=8,
                      bold=True,
                      color=(0, 0, 255)
                      # XXX: Use system prefs instead of hardcoded blue
                      ))
        self.hline = HLine(self)
        sizer = VBox()
        sizer.add(Spacer(2, 4))
        sizer.add(self.label, border=(4, 0, 0, 0))
        sizer.add(Spacer(2, 4))
        sizer.add(self.hline)
        self.sizer = sizer

    def set_text(self, text):
        self.label.set_text(text)

    def get_text(self):
        return self.label.get_text()
Ejemplo n.º 9
0
 def __init__(self, parent, text):
     Frame.__init__(self, parent)
     self.label = Label(self, text, 
                        font=Font(size=8, 
                                  bold=True, 
                                  color=(0,0,255) 
                                  # XXX: Use system prefs instead of hardcoded blue
                                 )
                       )
     self.hline = HLine(self)
     sizer = VBox()
     sizer.add(Spacer(2,4))
     sizer.add(self.label, border=(4,0,0,0))
     sizer.add(Spacer(2,4))
     sizer.add(self.hline)
     self.sizer = sizer
Ejemplo n.º 10
0
    def __init__(self, parent=None, title="PocketPyGui", action=None, menu=None, tab_traversal=True, visible=True, enabled=True, has_sip=True, has_toolbar=False):
        '''\
        Arguments :
            - parent: the parent window of this CeFrame.
            - title: the title as appearing in the title bar.
            - action : a tuple ('Label', callback) .
            - menu : the title of the right menu as a string
                     if not None, the menu can be filled via the cb_menu attribute
                     after CeFrame initialization.
        '''
        Frame.__init__(self, parent, title, tab_traversal=tab_traversal, visible=visible, enabled=enabled, pos=(-1,-1,240, 320))
        self.title_label = Label(self, title=title)

##        if has_ok:
##            self.top_right_button = gui.Button(self, 'Ok', action=lambda ev: self.onok())
##        else:
        self._create_tr_button()

        if action is None:
            self.cb_action = Spacer(0, 0)#Button(self)
        else:
            name, callback = action
            self.cb_action = CommandBarAction(self, name, action=callback)

        self.cb_menu = PopupMenu()
        if menu is None:
            self._cb_menu = Spacer(0, 0)
        else:
            self._cb_menu = CommandBarMenuWrapper(self, menu, self.cb_menu)

        hbox = HBox()
        hbox.add(self.title_label, 1)
        hbox.add(self.top_right_button)

        hbox2 = HBox()
        hbox2.add(self.cb_action, 1)
        hbox2.add(self._cb_menu, 1)
        
        vbox = VBox()
        vbox.add(hbox)
        vbox.add(Spacer())
        vbox.add(hbox2)
        

        self._sizer = vbox
        self.layout()
        InvalidateRect(self._w32_hWnd, 0, 0)
Ejemplo n.º 11
0
    def buildWidgets(self):
        keysColumn = self.keysColumn
        buttonsColumn = self.buttonsColumn
        items = self.items
        item_spacing = self.item_spacing

        if keysColumn is None or True:
            keysColumn = []
        if buttonsColumn is None or True:
            buttonsColumn = []
        labels = []

        for w in self.subwidgets:
            for _w in w.subwidgets:
                w.remove(_w)
            self.remove(w)

        for i, t in enumerate(items):
            if type(self.translateButtons) is bool:
                trn = not self.translateButtons
            elif type(self.translateButtons) in (list, tuple):
                trn = not i in self.translateButtons
            if len(t) == 3:
                (hotkey, title, action) = t
                tooltipText = None
            else:
                (hotkey, title, action, tooltipText) = t
            if isinstance(title, (str, unicode)):
                button = Button(title, action=action, doNotTranslate=trn)
            else:
                button = ValueButton(ref=title,
                                     action=action,
                                     width=200,
                                     doNotTranslate=trn)
            button.anchor = self.anchor

            label = Label(hotkey, width=100, margin=button.margin)
            label.anchor = "wh"

            label.height = button.height

            labels.append(label)

            if tooltipText:
                button.tooltipText = tooltipText

            keysColumn.append(label)
            buttonsColumn.append(button)

        self.buttons = list(buttonsColumn)

        #.#
        if item_spacing == None:
            buttonsColumn = Column(buttonsColumn)
        else:
            buttonsColumn = Column(buttonsColumn, spacing=item_spacing)
        #.#
        buttonsColumn.anchor = self.anchor
        #.#
        if item_spacing == None:
            keysColumn = Column(keysColumn)
        else:
            keysColumn = Column(keysColumn, spacing=item_spacing)

        commandRow = Row((keysColumn, buttonsColumn))
        self.labels = labels
        self.add(commandRow)
        self.shrink_wrap()
        self.invalidate()
Ejemplo n.º 12
0
def BasicTextInputRow(title, *args, **kw):
    return Row(
        (Label(title,
               tooltipText=kw.get('tooltipText')), TextField(*args, **kw)))
Ejemplo n.º 13
0
def FloatInputRow(title, *args, **kw):
    return Row(
        (Label(title,
               tooltipText=kw.get('tooltipText')), FloatField(*args, **kw)))
Ejemplo n.º 14
0
def wrapped_label(text, wrap_width, **kwds):
    paras = text.split("\n")
    text = "\n".join([textwrap.fill(para, wrap_width) for para in paras])
    return Label(text, **kwds)
Ejemplo n.º 15
0
class Interface:
    def __init__(self, size, img_dict, options):
        self.size = size
        self.img_dict = img_dict
        self.step = img_dict[Img.block_b].get_rect().h
        self.FIELD_START_WIDTH = int(options[Opt.width]/5 +
                                     (options[Opt.width]/5*4 -
                                      self.step*size)/2)
        self.FIELD_START_HEIGHT = int(options[Opt.height]/10)
        self.animation = []
        self.up_information = None
        self.down_information = None

    def set_information(self, points, person, players):
        up_information = "Black :" + str(points[-1]) + "; White : " +\
                         str(points[1]) + "."
        self.up_information = Label(up_information,
                                    int(self.FIELD_START_WIDTH/10),
                                    (self.FIELD_START_WIDTH,
                                     self.FIELD_START_HEIGHT/5))
        down_information = ""
        if players[-1] != Player.man or players[1] != Player.man:
            down_information = "You " + \
                               ("black. " if players[-1] == Player.man else
                                "white. ")
        down_information += "Turn " + \
                            ("black. " if person == -1 else
                             "white. ")
        self.down_information = Label(down_information,
                                      int(self.FIELD_START_WIDTH/10),
                                      (self.FIELD_START_WIDTH,
                                       self.FIELD_START_HEIGHT/5*45))

    def draw(self, display, field, path={}):
        iRow = iColumn = 0
        for row in field:
            for column in row:
                block_name = Img.block_w if (iColumn + iRow % 2) % 2 == 0 else\
                    Img.block_b
                display.blit(self.img_dict[block_name],
                             (self.FIELD_START_WIDTH+iColumn*self.step,
                              self.FIELD_START_HEIGHT+iRow*self.step))
                if column in (-1, 1, 2):
                    if column == 1:
                        block_name = Img.point_w
                    elif column == -1:
                        block_name = Img.point_b
                    elif column == 2:
                        block_name = Img.black_hall
                    display.blit(self.img_dict[block_name],
                                 (self.FIELD_START_WIDTH+iColumn*self.step,
                                  self.FIELD_START_HEIGHT+iRow*self.step))
                iColumn += 1
            iColumn = 0
            iRow += 1

        for (keyX, keyY) in path:
            display.blit(self.img_dict[Img.point],
                         (self.FIELD_START_WIDTH+keyY*self.step,
                          self.FIELD_START_HEIGHT+keyX*self.step))

        self.up_information.draw(display)
        self.down_information.draw(display)

    def event(self):
        mouse = pygame.mouse.get_pos()
        mouse = (mouse[0] - self.FIELD_START_WIDTH,
                 mouse[1] - self.FIELD_START_HEIGHT)
        if mouse_in(mouse, (0, 0), (self.step * self.size,
                                    self.step * self.size)):
            return mouse[1]//self.step, mouse[0]//self.step
        else:
            return -1, -1
Ejemplo n.º 16
0
    def buildWidgets(self):
        keysColumn = self.keysColumn
        buttonsColumn = self.buttonsColumn
        items = self.items
        item_spacing = self.item_spacing

        if keysColumn is None or True:
            keysColumn = []
        if buttonsColumn is None or True:
            buttonsColumn = []
        labels = []

        for w in self.subwidgets:
            for _w in w.subwidgets:
                w.remove(_w)
            self.remove(w)

        for t in items:
            if len(t) == 3:
                (hotkey, title, action) = t
                tooltipText = None
            else:
                (hotkey, title, action, tooltipText) = t
            if isinstance(title, (str, unicode)):
                button = Button(title, action=action)
            else:
                button = ValueButton(ref=title, action=action, width=200)
            button.anchor = self.anchor

            label = Label(hotkey, width=100, margin=button.margin)
            label.anchor = "wh"

            label.height = button.height

            labels.append(label)

            if tooltipText:
                button.tooltipText = tooltipText

            keysColumn.append(label)
            buttonsColumn.append(button)

        self.buttons = list(buttonsColumn)

        #.#
        if item_spacing == None:
            buttonsColumn = Column(buttonsColumn)
        else:
            buttonsColumn = Column(buttonsColumn, spacing=item_spacing)
        #.#
        buttonsColumn.anchor = self.anchor
        #.#
        if item_spacing == None:
            keysColumn = Column(keysColumn)
        else:
            keysColumn = Column(keysColumn, spacing=item_spacing)

        commandRow = Row((keysColumn, buttonsColumn))
        self.labels = labels
        self.add(commandRow)
        self.shrink_wrap()
        self.invalidate()