def __init__(self, type_string, types=map_types_item, ok_action=None): self.type_string = type_string self.ok_action = ok_action title = Label("Choose default data") self.t, widget, self.v = types[type_string] self.n = u"" w_name = TextFieldWrapped(ref=AttrRef(self, 'n')) self.w_value = self.get_widget(widget) col = Column([ Column([ title, ]), Label(_("Item Type: %s") % type_string, doNotTranslate=True), Row([Label("Name"), w_name], margin=0), Row([Label("Value"), self.w_value], margin=0), Row([ Button("OK", action=ok_action or self.dismiss_ok), Button("Cancel", action=self.dismiss) ], margin=0) ], margin=0, spacing=2) Dialog.__init__(self, client=col)
def __init__(self, title, responses, default=None, ok_action=None): self.response = responses[0] self.ok_action = ok_action title = Label(title) self.w_type = ChoiceButton(responses) col = Column([ title, self.w_type, Row([ Button("OK", action=ok_action or self.dismiss_ok), Button("Cancel", action=ok_action or self.dismiss) ], margin=0) ], margin=0, spacing=2) Dialog.__init__(self, client=col)
def ask(mess, responses=["OK", "Cancel"], default=0, cancel=-1, wrap_width=60, **kwds): box = Dialog(**kwds) d = box.margin lb = wrapped_label(mess, wrap_width) lb.topleft = (d, d) buts = [] for caption in responses: but = Button(caption, action=lambda x=caption: box.dismiss(x)) buts.append(but) brow = Row(buts, spacing=d) lb.width = max(lb.width, brow.width) col = Column([lb, brow], spacing=d, align='r') col.topleft = (d, d) if default is not None: box.enter_response = responses[default] buts[default].is_default = True else: box.enter_response = None if cancel is not None: box.cancel_response = responses[cancel] else: box.cancel_response = None box.add(col) box.shrink_wrap() def dispatchKeyForAsk(name, evt): if name == "key_down": if box.root.getKey(evt) == "Return": if default is not None: box.dismiss(responses[default]) box.dispatch_key = dispatchKeyForAsk return box.present()
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 build_calendar_ui(self): ''' Builds the actual Calendar UI after making the RESTful request. ''' if not self.device_auth.authorized: self._error('Need to authorize first.') if not self.calendar: self.calendar = Calendar(self.device_auth) events = self.calendar.events() date_today = DateTime.today() sync_at = date_today.formatted() sync_at_message = 'Last updated at %s' % (sync_at) if len(events) <= 0: messages = [sync_at_message] self._notify('No events.', messages=messages) else: root = Column(layout_width=self.width, layout_height=self.height, padding=10) header = Row(parent=root, layout_height=40, wrap_content=False) f_date_today = date_today.formatted(include_day=True, include_time=False) header.add_text_content('Today - %s' % (f_date_today), text_size=4) header.add_image(CALENDAR_40_40, 40, 40, align=ALIGN_RIGHT) content_root = Row(parent=root, layout_height=480, wrap_content=False, outline=True) content = Column(parent=content_root, wrap_content=False) content.add_spacer(10, outline=True) content.add_spacer(20) for event in events: summary = event.summary duration_info = None if event.start_at: include_day = not event.start_at.is_today() duration_info = 'At %s' % (event.start_at.formatted( include_day=include_day)) elif event.end_at: duration_info = 'Ends at %s' % (event.end_at.formatted( include_day=True, include_time=False)) content.add_text_content(summary) if duration_info: content.add_text_content(duration_info) content.add_spacer(height=15) content_root.add_node(content) status = Row(parent=root, layout_height=40, wrap_content=False, outline=True) status.add_text_content(sync_at_message, align=ALIGN_RIGHT) root.add_node(header) root.add_node(content_root) root.add_node(status) self._draw(root)
def ask(mess, responses=("OK", "Cancel"), default=0, cancel=-1, wrap_width=60, **kwds): # If height is specified as a keyword, the Dialog object will have this haight, and the inner massage will # be displayed in a scrolling widget # If 'responses_tooltips' it present in kwds, it must be dict with 'responses' as keys and the tooltips as values. # If 'tie_widget_to' is in kwds keys and the value is True, the global 'ask_tied_to' will be set up to the 'box'. # When called again with 'tie_widget_to', if 'ask_tied_to' is not None, the function returns a dummy answer. global ask_tied_to responses_tooltips = kwds.pop('responses_tooltips', {}) tie_widget_to = kwds.pop('tie_widget_to', None) # Return a dummy answer if tie_windget_to is True and the global 'ask_tied_to' is not None if tie_widget_to and ask_tied_to: return "_OK" colLbl = kwds.pop('colLabel', "") box = Dialog(**kwds) d = box.margin lb = wrapped_label(mess, wrap_width) buts = [] for caption in responses: but = Button(caption, action=lambda x=caption: box.dismiss(x)) if caption in responses_tooltips.keys(): but.tooltipText = responses_tooltips[caption] buts.append(but) brow = Row(buts, spacing=d) lb.width = max(lb.width, brow.width) height = kwds.get('height', None) if height and lb.height > height - ( 2 * brow.height) - ScrollPanel.column_margin - box.margin: lines = mess.split('\n') # ScrolledPanel refuses to render properly for now, so Tableview is used instead. w = TableView().font.size(_(colLbl))[0] lb = TableView( columns=[ TableColumn(colLbl, max(lb.width, w)), ], nrows=(height - (2 * brow.height) - box.margin - box.font.get_linesize()) / box.font.get_linesize(), height=height - (2 * brow.height) - (box.font.get_linesize() * 2) - box.margin) #, width=w) def num_rows(): return len(lines) lb.num_rows = num_rows lb.row_data = lambda x: (lines[x], ) lb.topleft = (d, d) lb.width = max(lb.width, brow.width) col = Column([lb, brow], spacing=d, align='r') col.topleft = (d, d) if default is not None: box.enter_response = responses[default] buts[default].is_default = True else: box.enter_response = None if cancel is not None: box.cancel_response = responses[cancel] else: box.cancel_response = None box.add(col) box.shrink_wrap() def dispatchKeyForAsk(name, evt): if name == "key_down" and box.root.getKey( evt) == "Return" and default is not None: box.dismiss(responses[default]) else: Dialog.dispatch_key(box, name, evt) box.dispatch_key = dispatchKeyForAsk if tie_widget_to: ask_tied_to = box ask_tied_tos.append(box) return box.present()
def _build_calendar(self): self.root = Column(layout_width=self.width, layout_height=self.height, padding=20) header = Row(parent=self.root, layout_height=40, wrap_content=False) header.add_text_content('Calendar', text_size=4) header.add_image(CALENDAR_40_40, 40, 40, align=ALIGN_RIGHT) content_root = Row(parent=self.root, layout_height=440, wrap_content=False, outline=True) content = Column(parent=content_root, wrap_content=False) content.add_spacer(10, outline=True) content_root.add_node(content) status = Row(parent=self.root, layout_height=40, wrap_content=False, outline=True) status.add_text_content('Last updated at <>', align=ALIGN_RIGHT) self.root.add_node(header) self.root.add_node(content_root) self.root.add_node(status)