def add_button(self, s): # Description du bouton label = Gtk.Label() label.set_markup_with_mnemonic("_{}".format(s['name'])) label.set_width_chars(onglet_width) # pour avoir des onglets uniformes if len(s['apps']) > 0: page = Gtk.FlowBox() page.set_valign(Gtk.Align.CENTER) page.set_selection_mode(Gtk.SelectionMode.NONE) if len(s['apps']) % 3 == 0: page.set_max_children_per_line(3) else: page.set_max_children_per_line(4) for a in s['apps']: appname, icon, cmd, generic = a['name'], a['icon'], a[ 'cmd'], a['generic'] # image utilisée dans le bouton image = Gtk.Image() filename, ext = os.path.splitext(icon) if ext.lower() in ['.png', '.jpg', '.jpeg', '.gif']: try: if os.path.isfile(icon): pixbuf = Pixbuf.new_from_file(icon) scaled_buf = pixbuf.scale_simple( iconsize, iconsize, InterpType.BILINEAR) image.set_from_pixbuf(scaled_buf) else: image.set_from_icon_name("image-missing", Gtk.IconSize.DIALOG) except: image.set_from_icon_name("image-missing", Gtk.IconSize.DIALOG) elif ext == ".ico": if os.path.isfile(icon): pixbuf = Pixbuf.new_from_file(icon) scaled_buf = pixbuf.scale_simple( iconsize, iconsize, InterpType.BILINEAR) image.set_from_pixbuf(scaled_buf) else: image.set_from_icon_name("applications-internet", Gtk.IconSize.DIALOG) elif len(icon.split('/')) == 2: # mimetype? icon = content_type_get_icon(icon) image.set_from_gicon(icon, Gtk.IconSize.DIALOG) else: image.set_from_icon_name(icon, Gtk.IconSize.DIALOG) image.set_pixel_size(iconsize) # nom de l'appli appname = fill(appname, button_width) bapp = Gtk.Button.new_with_mnemonic('_{}'.format(appname)) bapp.set_border_width(1) bapp.set_image(image) # l'image est au dessus du texte bapp.set_image_position(Gtk.PositionType.TOP) # apparence du bouton bapp.set_relief(Gtk.ReliefStyle.NONE) # lancement au clic ou avec entrée bapp.connect("button_release_event", self.exec_app, a) bapp.connect("key_press_event", self.exec_app, a) bapp.set_tooltip_text(generic) page.add(bapp) else: page = Gtk.Label(_("This menu is still empty")) label = Gtk.Label(_("This menu is still empty")) return (page, label)
def add_button(self, s): # Description du bouton label = Gtk.Label(s['name']) label.set_width_chars(onglet_width) # pour avoir des onglets uniformes r = 2 # 2 lignes par défaut n = len(s['apps']) # number of apps to show if n > 0: r = ceil(n / 3) if r > 2: r -= 1 c = ceil(n / r) if c > 2: c -= 1 page = Gtk.Table(rows=r, columns=c, homogeneous=True) page.set_row_spacings(1) page.set_col_spacings(1) page.show() x, y = 0, 0 for a in s['apps']: appname, icon, cmd, generic = a['name'], a['icon'], a[ 'cmd'], a['generic'] # image utilisée dans le bouton image = Gtk.Image() image.show() filename, ext = os.path.splitext(icon) if ext.lower() in ['.png', '.jpg', '.jpeg', '.gif']: try: if os.path.isfile(icon): pixbuf = Pixbuf.new_from_file(icon) scaled_buf = pixbuf.scale_simple( iconsize, iconsize, InterpType.BILINEAR) image.set_from_pixbuf(scaled_buf) else: image.set_from_icon_name("image-missing", Gtk.IconSize.DIALOG) except: image.set_from_icon_name("image-missing", Gtk.IconSize.DIALOG) elif ext == ".ico": if os.path.isfile(icon): pixbuf = Pixbuf.new_from_file(icon) scaled_buf = pixbuf.scale_simple( iconsize, iconsize, InterpType.BILINEAR) image.set_from_pixbuf(scaled_buf) else: image.set_from_icon_name("applications-internet", Gtk.IconSize.DIALOG) elif len(icon.split('/')) == 2: # mimetype? icon = content_type_get_icon(icon) image.set_from_gicon(icon, Gtk.IconSize.DIALOG) else: image.set_from_icon_name(icon, Gtk.IconSize.DIALOG) image.set_pixel_size(iconsize) # nom de l'appli appname = fill(appname, button_width) bapp = Gtk.Button.new_with_mnemonic('_{}'.format(appname)) bapp.show() bapp.set_border_width(1) bapp.set_image(image) # l'image est au dessus du texte bapp.set_image_position(Gtk.PositionType.TOP) # apparence du bouton bapp.set_relief(Gtk.ReliefStyle.NONE) # lancement au clic ou avec entrée bapp.connect("button_release_event", self.exec_app, a) bapp.connect("key_press_event", self.exec_app, a) bapp.set_tooltip_text(generic) page.attach(bapp, x, x+1, y, y+1,\ xoptions=Gtk.AttachOptions.EXPAND|Gtk.AttachOptions.FILL,\ yoptions=Gtk.AttachOptions.EXPAND|Gtk.AttachOptions.FILL,\ xpadding=1, ypadding=1) if x < c: x += 1 elif x == c: x = 0 y += 1 else: page = Gtk.Label(_("This menu is still empty")) label = Gtk.Label(_("This menu is still empty")) page.show() label.show() self.onglets.append_page(page, label)
def add_button(self, s): r = 2 # 2 lignes par défaut # onglet coloré n = len(s['apps']) # number of apps to show if n > 0: r = ceil(n / 3) if r > 2: r -= 1 c = ceil(n / r) if c > 2: c -= 1 page = Gtk.Table(rows=r, columns=c, homogeneous=True) page.grab_focus() page.show() cur = [0, 0] for a in s['apps']: appname, icon, cmd, generic = a['name'], a['icon'], a[ 'cmd'], a['generic'] # image utilisée dans le bouton image = Gtk.Image() image.show() if icon.split('.')[-1] in ['png', 'jpg', 'jpeg', 'gif']: pixbuf = Pixbuf.new_from_file(icon) scaled_buf = pixbuf.scale_simple(iconsize, iconsize, InterpType.BILINEAR) image.set_from_pixbuf(scaled_buf) elif icon.endswith('.ico'): if os.path.isfile(icon): pixbuf = Pixbuf.new_from_file(icon) scaled_buf = pixbuf.scale_simple( iconsize, iconsize, InterpType.BILINEAR) image.set_from_pixbuf(scaled_buf) else: image.set_from_icon_name("applications-internet", Gtk.IconSize.DIALOG) image.set_pixel_size(iconsize) elif len(icon.split('/')) == 2: # mimetype? icon = content_type_get_icon(icon) image.set_from_gicon(icon, Gtk.IconSize.DIALOG) image.set_pixel_size(iconsize) else: image.set_from_icon_name(icon, Gtk.IconSize.DIALOG) image.set_pixel_size(iconsize) # nom de l'appli appname = fill(appname, button_width) bapp = Gtk.Button.new_with_mnemonic('_{}'.format(appname)) bapp.show() bapp.set_border_width(1) bapp.set_image(image) # l'image est au dessus du texte bapp.set_image_position(Gtk.PositionType.TOP) # apparence du bouton bapp.set_relief(Gtk.ReliefStyle.NONE) bapp.set_alignment(0.5, 0.5) #blab.props.wrap = True #blab.props.width_chars = 20 # lancement au clic ou avec entrée bapp.connect("button_release_event", self.exec_app, a) bapp.connect("key_press_event", self.exec_app, a) bapp.set_tooltip_text(generic) page.attach(bapp, cur[0], cur[0]+1, cur[1], cur[1]+1,\ xoptions=Gtk.AttachOptions.EXPAND|Gtk.AttachOptions.FILL,\ yoptions=Gtk.AttachOptions.EXPAND|Gtk.AttachOptions.FILL,\ xpadding=1, ypadding=1) if cur[0] < c: cur[0] += 1 elif cur[0] == c: cur[0] = 0 cur[1] += 1 #self.onglets.add_titled( page, s['name'], s['name']) GObject.idle_add(self.onglets.add_titled, page, s['name'], s['name']) else: desc = Gtk.Label(_("This menu is still empty")) desc.show() GObject.idle_add(self.onglets.add_titled, desc, _("This menu is still empty"), _("This menu is still empty"))