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
def wrapped_label(text, wrap_width, **kwds): # paras = text.split("\n") text = _(text) kwds['doNotTranslate'] = True paras = text.split("\n\n") text = "\n".join([textwrap.fill(para, wrap_width) for para in paras]) return Label(text, **kwds)
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
def __init__(self, items, keysColumn=None, buttonsColumn=None, item_spacing=None): if keysColumn is None: keysColumn = [] if buttonsColumn is None: buttonsColumn = [] Widget.__init__(self) 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=75, margin=button.margin) label.anchor = "wh" label.height = button.height 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.add(commandRow) self.shrink_wrap()
def __init__(self, text, position, dimensions): self._hovered = False self._mouse_downed = False self._label = Label(position, dimensions, text, font_size=dimensions[1], padding=(constants.BUTTON_TEXT_PADDING, constants.BUTTON_TEXT_PADDING)) self._hit_box = Rect(position, dimensions) self._position = position self._dimensions = dimensions super().__init__()
def __init__(self, orientation, position, dimensions, dialog_tree, speaker_image): self._current_node = dialog_tree self._orientation = orientation self._position = position self._dimensions = dimensions self._speaker = pygame.image.load(utilities.relative_path(speaker_image, __file__)) background_file = utilities.relative_path('control_assets/dialogBox.png', __file__) self._background = pygame.image.load(background_file) padded_position = (position[0] + constants.DIALOG_BOX_TEXT_PADDING, position[1] + constants.DIALOG_BOX_TEXT_PADDING) self._text_box = Label(padded_position, (constants.DIALOG_BOX_DIMENSIONS[0] * .75 - (2 * constants.DIALOG_BOX_TEXT_PADDING), constants.DIALOG_BOX_DIMENSIONS[1] * .75 - (2 * constants.DIALOG_BOX_TEXT_PADDING)), self._current_node.get_text(), font_size=35, multiline=True)
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)
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 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
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 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
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()
def BasicTextInputRow(title, *args, **kw): return Row( (Label(title, tooltipText=kw.get('tooltipText')), TextField(*args, **kw)))
def FloatInputRow(title, *args, **kw): return Row( (Label(title, tooltipText=kw.get('tooltipText')), FloatField(*args, **kw)))
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)