def get_widgets(): """ create widget-tree """ main = fbgui.Panel("main", settings=fbgui.Settings({'margins': (10,10,10,10)}), toplevel=True) # add VBox vbox = fbgui.VBox("vbox", settings=fbgui.Settings({ 'margins': 5, 'padding': 2, 'bg_color': fbgui.Color.SILVER, 'align': (fbgui.LEFT,fbgui.TOP), }),parent=main) # add three texts txt1 = fbgui.Label("id_txt1","this is", settings=fbgui.Settings({ 'font_size': FONT_SMALL, 'bg_color' : fbgui.Color.RED080, 'align': fbgui.LEFT, }),parent=vbox) txt2 = fbgui.Label("id_txt2","a small", settings=fbgui.Settings({ 'font_size': FONT_MEDIUM, 'bg_color' : fbgui.Color.GREEN080, 'align': fbgui.CENTER, }),parent=vbox) txt3 = fbgui.Label("id_txt1","and long text", settings=fbgui.Settings({ 'font_size': FONT_LARGE, 'align': fbgui.RIGHT, }),parent=vbox) return main
def _create_widgets(self): self._main = fbgui.Panel("main", settings=fbgui.Settings({ }),toplevel=True) fbgui.Image("background",img=self._imgpath,parent=self._main) self._vbox = fbgui.VBox("vbox", settings=fbgui.Settings({ 'align': (fbgui.TOP,fbgui.LEFT), 'width': 1.0, 'height': 1.0, 'padding': 10 }),parent=self._main) self._header = fbgui.Panel("header", settings=fbgui.Settings({ 'width': 1.0, 'padding': 10 }),parent=self._vbox) self._dtlabel = fbgui.Label("datetime","Do 21.11.2019 16:41", settings=fbgui.Settings({ 'align': fbgui.LEFT}), parent=self._header) self._templabel = fbgui.Label("temp","22.5°C", settings=fbgui.Settings({ 'align': fbgui.RIGHT}), parent=self._header) self._wdata = fbgui.Text("wdata","""Wetterbericht für: München leichter Nebel _ - _ - _ - 3..4 °C _ - _ - _ ← 6 km/h _ - _ - _ - 4 km 0.1 mm""", parent=self._vbox)
def _create_widgets(self): self._main = fbgui.VBox("main", settings=fbgui.Settings({ 'padding': 5 }),toplevel=True) fbgui.VGap("gap1", settings=fbgui.Settings({ 'width': 10, 'weight': 1 }),parent=self._main) self._dlabel = fbgui.Label("dlabel","Sa 04.05.2019", settings=fbgui.Settings({ 'font_size': self.theme.font_size_s, 'align': fbgui.CENTER }),parent=self._main) self._tlabel = fbgui.Label("tlabel","14:23:12", settings=fbgui.Settings({ 'font_size': self.theme.font_size_xxl, 'align': fbgui.CENTER }),parent=self._main) fbgui.VGap("gap2", settings=fbgui.Settings({ 'width': 10, 'weight': 1 }),parent=self._main)
def _add_button_box(self,main): """ add button-box """ box = fbgui.HBox("button_box", settings=fbgui.Settings({ 'width': 1.0, 'uniform': True, 'height': 0.093, 'padding': 12, }),parent=main) fbgui.Button("btn_red",None,"Off", settings=fbgui.Settings({ 'weight': 1, 'bg_color': fbgui.Color.RED }),parent=box) fbgui.Button("btn_green",None,"Standby", settings=fbgui.Settings({ 'weight': 1, 'bg_color': fbgui.Color.GREEN }),parent=box) fbgui.Button("btn_yellow",None,"Kodi", settings=fbgui.Settings({ 'weight': 1, 'bg_color': fbgui.Color.YELLOW }),parent=box) fbgui.Button("btn_blue",None,"Off-mode", settings=fbgui.Settings({ 'weight': 1, 'bg_color': fbgui.Color.BLUE }),parent=box)
def get_widgets(self): """ create widget-tree """ main = fbgui.Panel("main", settings=fbgui.Settings( {'margins': (10, 10, 10, 10)}), toplevel=True) # add HBox hbox = fbgui.HBox("hbox", settings=fbgui.Settings({ 'margins': 5, 'padding': 30, 'bg_color': fbgui.Color.SILVER, 'align': (fbgui.CENTER, fbgui.CENTER), }), parent=main) main.add(hbox) # and text label = fbgui.Label("id_label", "Number:", settings=fbgui.Settings({ 'font_size': FONT_LARGE, }), parent=hbox) number = fbgui.Label("id_number", "x", settings=fbgui.Settings({ 'font_size': FONT_LARGE, }), parent=hbox) return main, number
def _create_childs(self): """ create widget-tree for self widget """ self._weekday = fbgui.Label("dt_weekday","", settings=fbgui.Settings({ 'font_name' : 'DSEG14Modern-Regular.ttf' }), parent=self) fbgui.HGap("dt_gap1", settings=fbgui.Settings({ 'size': 10 }), parent=self) self._day = fbgui.Label("dt_day","",parent=self) self._month = fbgui.Label("dt_month","",parent=self) self._year = fbgui.Label("dt_year","",parent=self) fbgui.HGap("dt_gap2", settings=fbgui.Settings({ 'size': 10 }), parent=self) self._time = fbgui.Label("dt_time","",parent=self) if self._with_secs: self._secs = fbgui.Label("dt_secs","", settings=fbgui.Settings({ 'font_size': fbgui.App.theme.font_size_m }), parent=self) self._set_time(refresh=False)
def add_images(parent): """ add images """ # add HBox hbox = fbgui.HBox("hbox_images", settings=fbgui.Settings({ 'margins': 5, 'padding': 30, 'width': 1.0, 'height': 80, 'bg_color': fbgui.Color.SILVER, 'align': (fbgui.CENTER, fbgui.TOP), }), parent=parent) images = glob.glob(os.path.join(os.path.dirname(sys.argv[0]), "*.png")) index = 0 for img in images: settings = fbgui.Settings({ 'width': 40, 'height': 40, 'scale': False, 'weight': 1, 'align': (fbgui.CENTER, fbgui.CENTER), }) if index % 2: settings.scale = True fbgui.Image("img_%d" % index, img=img, settings=settings, parent=hbox) index += 1
def _create_list_entry(self,entry,nr): """ create a HBox for the info-box """ fbgui.App.logger.msg("DEBUG","creating entry for %r" % (entry,)) text = "%s %s %s %s %s" % (entry['status'], entry['channel'], entry['title'], entry['date'], entry['time']) prefix = "entry_%d" % nr hbox = fbgui.HBox(prefix+"_hbox", settings=fbgui.Settings({ 'bg_color': fbgui.Color.SILVER, 'padding': 10, 'width': 1.0 })) settings = fbgui.Settings({ 'bg_color': fbgui.Color.SILVER, 'align': (fbgui.LEFT,fbgui.BOTTOM), 'font_size': FONT_MEDIUM, }) fbgui.Label(prefix+"_status",entry['status'], settings=settings,parent=hbox) settings.width=0.15 fbgui.Label(prefix+"_channel",entry['channel'], settings=settings,parent=hbox) fbgui.Label(prefix+"_date",entry['date'], settings=settings,parent=hbox) fbgui.Label(prefix+"_time",entry['time'], settings=settings,parent=hbox) settings.width=0.5 fbgui.Label(prefix+"_title",entry['title'], settings=settings,parent=hbox) return hbox
def _get_widgets(self): """ create widget-tree """ main = fbgui.VBox("main", settings=fbgui.Settings({ 'margins': 20, 'padding': 10 }), toplevel=True) # add date-box self._add_date_box(main) # add info-box # since we set weight only here, the infobx will take all available space self._info_box = fbgui.List("info_box",None, settings=fbgui.Settings({ 'bg_color': fbgui.Color.SILVER, 'font_name': "FreeMonoBold.ttf", 'radius': 0.1, 'margins': 20, 'width': 1.0, 'weight': 1 }),parent=main) # add button-box self._add_button_box(main) return main
def get_widgets(): """ create widget-tree """ main = fbgui.Panel("main", settings=fbgui.Settings({'margins': (10, 10, 10, 10)}), toplevel=True) # add a text-box at the top txt1 = "The first line.\nThe second line.\n\nThe fourth line." text1 = fbgui.Text("txt1", txt1, settings=fbgui.Settings({ 'margins': 5, 'bg_color': fbgui.Color.BLUE, 'fg_color': fbgui.Color.WHITE, 'rows': 3, 'align': (fbgui.CENTER, fbgui.TOP), }), parent=main) # add a text-box in the center txt2 = "The first line.\nThe second line.\n clipped \nThe fourth line" text2 = fbgui.Text("txt2", txt2, settings=fbgui.Settings({ 'margins': 5, 'height': 0.115, 'bg_color': fbgui.Color.BLUE, 'fg_color': fbgui.Color.WHITE, 'align': (fbgui.CENTER, fbgui.CENTER), }), parent=main) # add a text-box at the bottom txt3 = "The first line.\nThe second line.\n\nThe fourth line." text2 = fbgui.Text("txt3", txt3, settings=fbgui.Settings({ 'margins': 5, 'bg_color': fbgui.Color.BLUE, 'fg_color': fbgui.Color.WHITE, 'align': (fbgui.CENTER, fbgui.BOTTOM), }), parent=main) return main
def __init__(self, id, img=None, text=None, settings=fbgui.Settings(), toplevel=False, parent=None): """ constructor """ # some default settings, bevor we call the super-constructor settings.padding = getattr(settings, 'padding', 5) settings.margins = getattr(settings, 'margins', 10) settings.radius = getattr(settings, 'radius', 0.9) settings.show_hover = True settings.show_down = True # now initialize HBox super(Button, self).__init__(id, settings=settings, toplevel=toplevel, parent=parent) self._img = None # image filename self._Image = None # Image widget self._text = None # button text self._Label = None # Label widget # use two gaps with weight to center image+label fbgui.HGap(self._id + "_gap1", settings=fbgui.Settings({ 'size': 0, 'weight': 1 }), parent=self) fbgui.HGap(self._id + "_gap2", settings=fbgui.Settings({ 'size': 0, 'weight': 1 }), parent=self) self.set_image(img, refresh=False) self.set_text(text, refresh=False) # colors for button-states # overwrite copy from parent or app in super-constructor if not hasattr(settings, 'bg_color_down'): self.theme.bg_color_down = fbgui.Color.darken(self.theme.bg_color) if not hasattr(settings, 'bg_color_hover'): self.theme.bg_color_hover = fbgui.Color.lighten( self.theme.bg_color)
def _create_gui(self): """ create widget-tree """ self._main_panel = fbgui.VBox("main", settings=fbgui.Settings({ 'margins': 2, 'padding': 5 }), toplevel=True) # add datetime self._dt = wstation.WSGuiDateTime("dt_hbox", settings=fbgui.Settings({ 'secs': False, 'align': fbgui.CENTER, 'stop_event': self._stop_event }), parent=self._main_panel) fbgui.Line("main_line_dt", settings=fbgui.Settings({ 'align': fbgui.CENTER, 'width': 0.9 }), parent=self._main_panel) # add sensor-displays self._sensor_widgets = {} for group in self._sensors.keys(): stype = self._sensors[group]['type'] slabel = self._sensors[group]['label'] # create GUI-object for stype fbgui.App.logger.msg( "DEBUG", "creating widget for %s (type: %s)" % (slabel, stype)) self._sensor_widgets[group] = (wstation.__dict__["WSGui" + stype]( "widget_" + group, settings=fbgui.Settings({ 'align': fbgui.LEFT, 'name': group, 'group': self._sensors[group] }), parent=self._main_panel)) # add a divider fbgui.Line("main_line_" + group, settings=fbgui.Settings({ 'align': fbgui.CENTER, 'width': 0.9 }), parent=self._main_panel)
def add_labels(parent): """ add HBox with labels """ # add HBox hbox = fbgui.HBox("hbox_labels", settings=fbgui.Settings({ 'margins': 5, 'padding': 30, 'width': 1.0, 'bg_color': fbgui.Color.SILVER, 'align': (fbgui.CENTER, fbgui.TOP), }), parent=parent) # add three texts txt1 = fbgui.Label("id_txt1", "this is", settings=fbgui.Settings({ 'width': 0.25, 'font_size': FONT_SMALL, 'bg_color': fbgui.Color.RED080, 'align': (fbgui.CENTER, fbgui.BOTTOM), }), parent=hbox) txt2 = fbgui.Label("id_txt2", "a small", settings=fbgui.Settings({ 'width': 0.25, 'font_size': FONT_MEDIUM, 'bg_color': fbgui.Color.GREEN080, 'align': (fbgui.RIGHT, fbgui.CENTER), }), parent=hbox) txt3 = fbgui.Label("id_txt3", "and long text", settings=fbgui.Settings({ 'weight': 2, 'bg_color': fbgui.Color.BLUE080, 'font_size': FONT_LARGE, }), parent=hbox)
def get_widgets(): """ create widget-tree """ main = fbgui.Panel("main", settings=fbgui.Settings({'margins': (10, 10, 10, 10)}), toplevel=True) # add VBox vbox = fbgui.VBox("vbox", settings=fbgui.Settings({ 'margins': 20, 'padding': 2, 'align': (fbgui.CENTER, fbgui.TOP), }), parent=main) # add a label label = fbgui.Label("msg", "", settings=fbgui.Settings({ 'align': (fbgui.CENTER, fbgui.BOTTOM), }), parent=main) # add four buttons colors = [ fbgui.Color.RED075, fbgui.Color.GREEN075, fbgui.Color.YELLOW, fbgui.Color.BLUE075 ] text = ["play", "pause", "stop", "record"] images = ["play.png", "pause.png", "stop.png", "record.png"] attribs = zip(colors, text, images) index = 1 for color, text, image in attribs: image = os.path.join(PGM_DIR, image) btn = fbgui.Button("btn_%d" % index, img=image, text=text, settings=fbgui.Settings({ 'width': 150, 'font_size': FONT_MEDIUM, 'bg_color': color, 'align': fbgui.CENTER, }), parent=vbox) btn.on_click = lambda widget, event, text=text: set_msg( widget, event, text, label) index += 1 return main
def get_widgets(self): """ create widget-tree """ main = fbgui.Panel("main", settings=fbgui.Settings({'margins': (10,10,10,10)}), toplevel=True) # add Image self._img_widget = fbgui.Image("img",img=None, settings=fbgui.Settings({ 'width': 600, 'height': 200, 'scale': False, 'align': (fbgui.CENTER,fbgui.CENTER), }),parent=main) return main
def get_widgets(): """ create widget-tree """ colors = [ fbgui.Color.RED, fbgui.Color.GREEN, fbgui.Color.BLUE, fbgui.Color.RED075, fbgui.Color.GREEN075, fbgui.Color.BLUE075, fbgui.Color.RED025, fbgui.Color.GREEN025, fbgui.Color.BLUE025 ] labels = [ "top-left", "top-center", "top-right", "center-left", "center-center", "center-right", "bottom-left", "bottom-center", "bottom-right" ] sizes = [ FONT_SMALL, FONT_MEDIUM, FONT_LARGE, FONT_SMALL, FONT_MEDIUM, FONT_LARGE, FONT_SMALL, FONT_MEDIUM, FONT_LARGE ] main = fbgui.Panel("main", settings=fbgui.Settings({'margins': (5, 5, 5, 5)}), toplevel=True) # add child panels index = 0 for valign in [fbgui.TOP, fbgui.CENTER, fbgui.BOTTOM]: for halign in [fbgui.LEFT, fbgui.CENTER, fbgui.RIGHT]: config = fbgui.Settings({ 'fg_color': colors[index], 'font_size': sizes[index], 'align': (halign, valign) }) text = labels[index] if index == 1: # test background config.bg_color = fbgui.Color.GRAY090 elif index == 4: # test empty label: fill with background text = "" config.bg_color = fbgui.Color.BLACK config.width = 80 config.height = 40 label = fbgui.Label("label-%d" % index, text, settings=config, parent=main) index += 1 return main
def __init__(self, id, settings=fbgui.Settings(), toplevel=False, parent=None): """ constructor """ super(Box, self).__init__(id, settings=settings, toplevel=toplevel, parent=parent) self.padding = getattr(settings, 'padding', (0, 0)) if not type(self.padding) is tuple: self.padding = (self.padding, self.padding) self.uniform = getattr(settings, 'uniform', (False, False)) if not type(self.uniform) is tuple: self.uniform = (self.uniform, self.uniform) self._child_w_max = 0 self._child_h_max = 0 self._child_w_sum = 0 self._child_h_sum = 0 self._child_sizes = []
def _set_text(self,text,refresh=True): """ set the text of the widget (internal method) """ if text == self._text: return fbgui.App.logger.msg("TRACE","changing text of %s" % self._id) self._text = text if not text: self.clear(refresh=refresh) return # cleanup of old state if self._lines: del self._lines[:] self.remove_all() # split text and create labels self._lines = text.split('\n') n_labels = self._rows if self._rows > 0 else len(self._lines) settings = fbgui.Settings(self._settings) settings.width = 0 settings.height = 0 settings.weight = 0 settings.align = fbgui.LEFT for n in range(n_labels): label = fbgui.Label("%s_line_%d" % (self._id,n),"", settings=settings,parent=self) label.set_text(self._lines[n],refresh=False) if refresh: self.post_layout()
def __init__(self, settings=fbgui.Settings()): """ constructor """ super(WSGuiApp, self).__init__(settings=settings) self._stop_event = getattr(settings, 'stop_event', threading.Event()) self._sensors = settings.sensor_info.sensors self._update_interval = settings.sensor_info.update self._create_gui() self._main_panel.pack() self.set_widget(self._main_panel) # prebuild query-string for data-provider self._query_string = ("/query?groups=%s&metrics=current" % ','.join(self._sensors.keys())) fbgui.App.logger.msg("DEBUG", "query-string: %s" % self._query_string) # create reusable request-object try: self._request = httplib.HTTPConnection(settings.web.host, settings.web.port, timeout=10) fbgui.App.logger.msg("DEBUG", "created request-object") except: fbgui.App.logger.msg("ERROR", "could not create request-object") fbgui.App.logger.msg("ERROR", traceback.format_exc()) self._request = None
def add_panels(parent): """ add HBox with panels """ # add a full-size HBox hbox = fbgui.HBox("hbox_panels", settings=fbgui.Settings({ 'margins': 5, 'padding': 30, 'width': 1.0, 'bg_color': fbgui.Color.SILVER, 'align': (fbgui.CENTER, fbgui.TOP), }), parent=parent) # add three panels panel1 = fbgui.Panel("id_panel1", settings=fbgui.Settings({ 'height': 20, 'weight': 1, 'bg_color': fbgui.Color.RED080, 'align': fbgui.BOTTOM, }), parent=hbox) panel2 = fbgui.Panel("id_panel2", settings=fbgui.Settings({ 'height': 30, 'weight': 1, 'bg_color': fbgui.Color.GREEN080, 'align': fbgui.CENTER, }), parent=hbox) panel3 = fbgui.Panel("id_panel3", settings=fbgui.Settings({ 'height': 40, 'weight': 2, 'bg_color': fbgui.Color.BLUE080, }), parent=hbox)
def __init__(self, settings=fbgui.Settings()): """ constructor """ super(MyApp, self).__init__(settings=settings) self._stop_event = threading.Event() panel, self.number_label = self.get_widgets() panel.pack() self.set_widget(panel)
def _create_group_box(self): """ create sensor display-box """ return fbgui.HBox(self._name+"_hbox", settings=fbgui.Settings({ 'width': 1.0, 'align': fbgui.CENTER, 'margins': (25,25,0,0) }), parent=self)
def _add_date_box(self,main): """ add date-box """ panel = fbgui.Panel("date_box", settings=fbgui.Settings({ 'bg_color': fbgui.Color.SILVER, 'radius': 0.9, 'margins': 20, 'width': 1.0, 'height': 0.093 }),parent=main) self._msg = fbgui.Label("msg_label","initializing...", settings=fbgui.Settings({ 'align': fbgui.LEFT }),parent=panel) self._date = fbgui.Label("date_label","", settings=fbgui.Settings({ 'align': fbgui.RIGHT }),parent=panel)
def _create_label(self): """ create label for widget """ # label within outer-vbox self._widget_label = fbgui.Label(self._name+"_label",self._label, settings=fbgui.Settings({ 'font_name' : 'FreeSans', 'font_size' : fbgui.App.theme.font_size_s, }), parent=self)
def get_widgets(): """ create widget-tree """ colors = [ fbgui.Color.RED, fbgui.Color.GREEN, fbgui.Color.BLUE, fbgui.Color.RED075, fbgui.Color.GREEN075, fbgui.Color.BLUE075, fbgui.Color.RED025, fbgui.Color.GREEN025, fbgui.Color.BLUE025 ] main = fbgui.Panel("main", settings=fbgui.Settings({'margins': (5, 5, 5, 5)}), toplevel=True) # add child panels index = 0 for valign in [fbgui.TOP, fbgui.CENTER, fbgui.BOTTOM]: for halign in [fbgui.LEFT, fbgui.CENTER, fbgui.RIGHT]: config = fbgui.Settings({ 'width': 80, 'height': 40, 'radius': 0.1 * index, 'bg_color': colors[index], 'align': (halign, valign) }) box = fbgui.Panel("box%d" % index, settings=config, parent=main) index += 1 # add child lines config = fbgui.Settings({ 'width': 1.0, 'height': 0, 'fg_color': fbgui.Color.BLACK, 'align': fbgui.CENTER, 'orientation': fbgui.HORIZONTAL }) line = fbgui.Line("hline", settings=config, parent=main) config.width = 0 config.height = 1.0 config.orientation = fbgui.VERTICAL line = fbgui.Line("vline", settings=config, parent=main) return main
def __init__(self,settings=fbgui.Settings()): """ constructor """ super(PvrGui,self).__init__(settings=settings) self._stop_event = threading.Event() panel = self._get_widgets() panel.pack() self.set_widget(panel) self._cec = CECController(self)
def __init__(self, id, settings=fbgui.Settings(), toplevel=False, parent=None): """ constructor """ super(HBox, self).__init__(id, settings=settings, toplevel=toplevel, parent=parent)
def __init__(self, id, settings=fbgui.Settings(), toplevel=False, parent=None): """ constructor """ super(Line, self).__init__(id, settings=settings, toplevel=toplevel, parent=parent) self.orientation = getattr(settings, 'orientation', fbgui.HORIZONTAL)
def __init__(self,id,settings=fbgui.Settings(),parent=None): """ constructor """ settings.padding = 2 super(WSGuiDateTime,self).__init__(id,settings=settings,parent=parent) self.theme.font_name = 'DSEG7Modern-Regular.ttf' self.theme.font_size = fbgui.App.theme.font_size_l self._stop_event = settings.stop_event self._with_secs = getattr(settings,"secs",True) self._create_childs()
def __init__(self, id, settings=fbgui.Settings(), toplevel=False, parent=None): """ constructor """ settings.orientation = fbgui.HORIZONTAL super(VGap, self).__init__(id, settings=settings, toplevel=toplevel, parent=parent)