def build_box(self): check_key(self.settings, "numbers", [1, 2, 3, 4, 5, 6, 7, 8]) for num in self.settings["numbers"]: btn = Gtk.Button.new_with_label("{}".format(num)) btn.connect("clicked", self.on_click, num) self.pack_start(btn, False, False, 0) self.show_all()
def __init__(self, con, settings, autotiling): self.con = con at_indicator = "a" if con.num in autotiling else "" Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL, spacing=0) check_key(settings, "workspace-buttons", False) if settings["workspace-buttons"]: widget = Gtk.Button.new_with_label("{}{}".format(at_indicator, con.num)) widget.connect("clicked", self.on_click) else: widget = Gtk.Label("{}{}:".format(at_indicator, con.num)) self.pack_start(widget, False, False, 4)
def __init__(self, i3, tree, settings, icons_path=""): Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL, spacing=0) self.settings = settings self.i3 = i3 self.tree = tree self.content = [] self.icons_path = icons_path defaults = {"css-name": "", "icon-size": 16} for key in defaults: check_key(settings, key, defaults[key])
def __init__(self, panel, icons_path=""): Gtk.Button.__init__(self) self.set_always_show_image(True) self.panel = panel check_key(panel, "menu-start-settings", {}) self.settings = panel["menu-start-settings"] self.set_property("name", "button-start") check_key(self.settings, "icon-size-button", 16) image = Gtk.Image() update_image(image, "nwg-shell", self.settings["icon-size-button"], icons_path) self.set_image(image) self.connect("clicked", self.on_click) self.show()
def __init__(self, settings, i3, position, display_name="", icons_path=""): self.position = position self.icons_path = icons_path check_key(settings, "workspaces-spacing", 0) check_key(settings, "image-size", 16) check_key(settings, "workspace-menu", [1, 2, 3, 4, 5, 6, 7, 8]) check_key(settings, "task-padding", 0) check_key(settings, "all-workspaces", True) Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL, spacing=settings["workspaces-spacing"]) self.settings = settings self.display_name = display_name self.i3 = i3 self.tree = i3.get_tree() self.displays_tree = self.list_tree() self.autotiling = load_autotiling() self.build_box() self.ipc_data = {} self.ws_box = None
def __init__(self, settings, icons_path=""): Gtk.Button.__init__(self) self.set_always_show_image(True) self.settings = settings check_key(settings, "icon", "dialog-error") check_key(settings, "icon-size", 16) image = Gtk.Image() update_image(image, settings["icon"], settings["icon-size"], icons_path) self.set_image(image) check_key(settings, "label", "") if "label" in settings and settings["label"]: if "label-position" in settings: if settings["label-position"] == "right": self.set_image_position(Gtk.PositionType.LEFT) self.set_label(settings["label"]) elif settings["label-position"] == "left": self.set_image_position(Gtk.PositionType.RIGHT) self.set_label(settings["label"]) elif settings["label-position"] == "top": self.set_image_position(Gtk.PositionType.BOTTOM) self.set_label(settings["label"]) elif settings["label-position"] == "bottom": self.set_image_position(Gtk.PositionType.TOP) self.set_label(settings["label"]) else: self.set_tooltip_text(settings["label"]) else: self.set_tooltip_text(settings["label"]) check_key(settings, "command", "") if settings["command"]: self.connect("clicked", self.on_click, settings["command"]) check_key(settings, "css-name", "") if settings["css-name"]: self.set_property("name", settings["css-name"]) self.show()
def __init__(self, settings, i3, position, display_name=""): self.position = position check_key(settings, "workspaces-spacing", 0) check_key(settings, "image-size", 16) check_key(settings, "workspace-menu", [1, 2, 3, 4, 5, 6, 7, 8]) Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL, spacing=settings["workspaces-spacing"]) self.settings = settings self.display_name = display_name self.i3 = i3 self.displays_tree = self.list_tree() self.build_box() self.ipc_data = {} self.ws_box = None
def __init__(self, settings): self.settings = settings Gtk.EventBox.__init__(self) self.box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0) self.add(self.box) self.label = Gtk.Label("") check_key(settings, "root-css-name", "root-clock") check_key(settings, "css-name", "clock") check_key(settings, "tooltip-text", "") check_key(settings, "on-left-click", "") check_key(settings, "on-right-click", "") check_key(settings, "on-middle-click", "") check_key(settings, "on-scroll-up", "") check_key(settings, "on-scroll-down", "") check_key(settings, "interval", 1) self.set_property("name", settings["root-css-name"]) self.label.set_property("name", settings["css-name"]) if settings["tooltip-text"]: self.set_tooltip_text(settings["tooltip-text"]) if "format" not in settings: self.settings["format"] = "%a, %d. %b %H:%M:%S" if settings["on-left-click"] or settings["on-right-click"] or settings[ "on-middle-click"] or settings["on-scroll-up"] or settings[ "on-scroll-down"]: self.connect('button-press-event', self.on_button_press) self.add_events(Gdk.EventMask.SCROLL_MASK) self.connect('scroll-event', self.on_scroll) self.connect('enter-notify-event', self.on_enter_notify_event) self.connect('leave-notify-event', self.on_leave_notify_event) self.build_box() self.refresh() if settings["interval"] > 0: Gdk.threads_add_timeout_seconds(GLib.PRIORITY_LOW, settings["interval"], self.refresh)
def __init__(self, con, settings, position): self.position = position self.settings = settings Gtk.EventBox.__init__(self) check_key(settings, "task-spacing", 0) self.box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=settings["task-spacing"] if settings["task-spacing"] else 0) self.add(self.box) self.con = con self.pid = con.pid self.old_name = "" if con.focused: self.box.set_property("name", "task-box-focused") else: self.box.set_property("name", "task-box") self.connect('enter-notify-event', self.on_enter_notify_event) self.connect('leave-notify-event', self.on_leave_notify_event) self.connect('button-press-event', self.on_click, self.box) self.add_events(Gdk.EventMask.SCROLL_MASK) self.connect('scroll-event', self.on_scroll) check_key(settings, "show-app-icon", True) if settings["show-app-icon"]: name = con.app_id if con.app_id else con.window_class icon_from_desktop = get_icon(name) if icon_from_desktop: if "/" not in icon_from_desktop and not icon_from_desktop.endswith( ".svg") and not icon_from_desktop.endswith(".png"): image = Gtk.Image() update_image(image, icon_from_desktop, settings["image-size"]) else: pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size( icon_from_desktop, settings["image-size"], settings["image-size"]) image = Gtk.Image.new_from_pixbuf(pixbuf) self.box.pack_start(image, False, False, 4) else: image = Gtk.Image() update_image(image, name, settings["image-size"]) self.box.pack_start(image, False, False, 4) if con.name: check_key(settings, "name-max-len", 10) name = con.name[:settings["name-max-len"]] if len( con.name) > settings["name-max-len"] else con.name label = Gtk.Label(name) self.box.pack_start(label, False, False, 0) check_key(settings, "show-layout", True) if settings["show-layout"] and con.parent.layout: if con.parent.layout == "splith": image = Gtk.Image() update_image(image, "go-next", 16) elif con.parent.layout == "splitv": image = Gtk.Image() update_image(image, "go-down", 16) elif con.parent.layout == "tabbed": image = Gtk.Image() update_image(image, "view-dual", 16) elif con.parent.layout == "stacked": image = Gtk.Image() update_image(image, "view-paged", 16) else: image = Gtk.Image() update_image(image, "window-new", 16) self.box.pack_start(image, False, False, 4)
def __init__(self, parent, position, alignment, settings, width, monitor=None, icons_path=""): Gtk.Window.__init__(self, type_hint=Gdk.WindowTypeHint.NORMAL) GtkLayerShell.init_for_window(self) if monitor: GtkLayerShell.set_monitor(self, monitor) check_key(settings, "css-name", "controls-window") self.parent = parent self.set_property("name", settings["css-name"]) self.icon_size = settings["icon-size"] self.icons_path = icons_path self.settings = settings self.position = position self.net_icon_name = "" self.menu_box = None self.sink_box = None self.bri_scale = None self.vol_scale = None self.src_tag = 0 self.connect("show", self.on_window_show) check_key(settings, "output-switcher", False) self.sinks = [] if commands["pamixer"] and settings["output-switcher"] and commands[ "pamixer"]: self.sinks = list_sinks() eb = Gtk.EventBox() eb.set_above_child(False) if settings["leave-closes"]: self.connect("leave_notify_event", self.on_window_exit) self.connect("enter_notify_event", self.on_window_enter) outer_vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0) eb.add(outer_vbox) self.add(eb) outer_hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0) Gtk.Widget.set_size_request(outer_hbox, width, 10) outer_vbox.pack_start(outer_hbox, True, True, 20) v_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0) outer_hbox.pack_start(v_box, True, True, 20) GtkLayerShell.set_layer(self, GtkLayerShell.Layer.TOP) # GtkLayerShell.set_keyboard_interactivity(self, True) GtkLayerShell.set_margin(self, GtkLayerShell.Edge.TOP, settings["window-margin"]) GtkLayerShell.set_margin(self, GtkLayerShell.Edge.BOTTOM, settings["window-margin"]) GtkLayerShell.set_margin(self, GtkLayerShell.Edge.RIGHT, settings["window-margin"]) GtkLayerShell.set_margin(self, GtkLayerShell.Edge.LEFT, settings["window-margin"]) if alignment == "left": GtkLayerShell.set_anchor(self, GtkLayerShell.Edge.LEFT, True) else: GtkLayerShell.set_anchor(self, GtkLayerShell.Edge.RIGHT, True) if position == "bottom": GtkLayerShell.set_anchor(self, GtkLayerShell.Edge.BOTTOM, True) else: GtkLayerShell.set_anchor(self, GtkLayerShell.Edge.TOP, True) check_key(settings, "commands", {"battery": "", "net": ""}) add_sep = False if "brightness" in settings["components"]: inner_hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0) v_box.pack_start(inner_hbox, False, False, 0) self.bri_icon_name = "view-refresh-symbolic" self.bri_image = Gtk.Image.new_from_icon_name( self.bri_icon_name, Gtk.IconSize.MENU) inner_hbox.pack_start(self.bri_image, False, False, 6) self.bri_scale = Gtk.Scale.new_with_range( orientation=Gtk.Orientation.HORIZONTAL, min=0, max=100, step=1) self.bri_scale.connect("value-changed", self.set_bri) inner_hbox.pack_start(self.bri_scale, True, True, 5) add_sep = True if "volume" in settings["components"] and commands["pamixer"]: inner_hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0) v_box.pack_start(inner_hbox, False, False, 6) self.vol_icon_name = "view-refresh-symbolic" self.vol_image = Gtk.Image.new_from_icon_name( self.vol_icon_name, Gtk.IconSize.MENU) if self.parent.vol_icon_name != self.vol_icon_name: update_image(self.vol_image, self.parent.vol_icon_name, self.icon_size, self.icons_path) self.vol_icon_name = self.parent.vol_icon_name eb = Gtk.EventBox() eb.connect("enter_notify_event", self.on_enter_notify_event) eb.connect("leave_notify_event", self.on_leave_notify_event) eb.connect("button-press-event", self.toggle_mute) eb.add(self.vol_image) inner_hbox.pack_start(eb, False, False, 6) self.vol_scale = Gtk.Scale.new_with_range( orientation=Gtk.Orientation.HORIZONTAL, min=0, max=100, step=1) self.vol_scale.set_value(self.parent.vol_value) self.vol_scale.connect("value-changed", self.set_vol) inner_hbox.pack_start(self.vol_scale, True, True, 5) if commands["pamixer"] and settings["output-switcher"]: pactl_eb = Gtk.EventBox() image = Gtk.Image() pactl_eb.add(image) pactl_eb.connect("enter_notify_event", self.on_enter_notify_event) pactl_eb.connect("leave_notify_event", self.on_leave_notify_event) update_image(image, "pan-down-symbolic", self.icon_size, self.icons_path) inner_hbox.pack_end(pactl_eb, False, False, 5) self.sink_box = SinkBox() pactl_eb.connect('button-press-event', self.sink_box.switch_visibility) v_box.pack_start(self.sink_box, False, False, 0) add_sep = True if add_sep: sep = Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL) v_box.pack_start(sep, True, True, 10) if "net" in settings["components"] and commands[ "netifaces"] and settings["net-interface"]: event_box = Gtk.EventBox() if "net" in settings["commands"] and settings["commands"]["net"]: event_box.connect("enter_notify_event", self.on_enter_notify_event) event_box.connect("leave_notify_event", self.on_leave_notify_event) event_box.connect('button-press-event', self.launch, settings["commands"]["net"]) inner_vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0) inner_hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0) inner_vbox.pack_start(inner_hbox, True, True, 6) v_box.pack_start(event_box, True, True, 0) self.net_icon_name = "view-refresh-symbolic" self.net_image = Gtk.Image.new_from_icon_name( self.net_icon_name, Gtk.IconSize.MENU) icon_name = "network-wired-symbolic" if self.parent.net_ip_addr else "network-wired-disconnected-symbolic" if icon_name != self.net_icon_name: update_image(self.net_image, icon_name, self.icon_size, self.icons_path) self.net_icon_name = icon_name inner_hbox.pack_start(self.net_image, False, False, 6) self.net_label = Gtk.Label("{}: {}".format( settings["net-interface"], self.parent.net_ip_addr)) inner_hbox.pack_start(self.net_label, False, True, 6) if "net" in settings["commands"] and settings["commands"]["net"]: img = Gtk.Image() update_image(img, "pan-end-symbolic", self.icon_size, self.icons_path) inner_hbox.pack_end(img, False, True, 4) event_box.add(inner_vbox) if "bluetooth" in settings["components"] and commands["pybluez"]: event_box = Gtk.EventBox() if "bluetooth" in settings["commands"] and settings["commands"][ "bluetooth"]: event_box.connect("enter_notify_event", self.on_enter_notify_event) event_box.connect("leave_notify_event", self.on_leave_notify_event) event_box.connect('button-press-event', self.launch, settings["commands"]["bluetooth"]) inner_vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0) inner_hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0) inner_vbox.pack_start(inner_hbox, True, True, 6) v_box.pack_start(event_box, True, True, 0) self.bt_icon_name = "view-refresh-symbolic" self.bt_image = Gtk.Image.new_from_icon_name( self.bt_icon_name, Gtk.IconSize.MENU) inner_hbox.pack_start(self.bt_image, False, False, 6) self.bt_label = Gtk.Label() inner_hbox.pack_start(self.bt_label, False, True, 6) if "bluetooth" in settings["commands"] and settings["commands"][ "bluetooth"]: img = Gtk.Image() update_image(img, "pan-end-symbolic", self.icon_size, self.icons_path) inner_hbox.pack_end(img, False, True, 4) event_box.add(inner_vbox) if "battery" in settings["components"]: event_box = Gtk.EventBox() if "battery" in settings["commands"] and settings["commands"][ "battery"]: event_box.connect("enter_notify_event", self.on_enter_notify_event) event_box.connect("leave_notify_event", self.on_leave_notify_event) event_box.connect('button-press-event', self.launch, settings["commands"]["battery"]) inner_vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0) inner_hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0) inner_vbox.pack_start(inner_hbox, True, True, 6) v_box.pack_start(event_box, True, True, 0) self.bat_icon_name = "view-refresh-symbolic" self.bat_image = Gtk.Image.new_from_icon_name( self.bat_icon_name, Gtk.IconSize.MENU) inner_hbox.pack_start(self.bat_image, False, False, 6) self.bat_label = Gtk.Label() inner_hbox.pack_start(self.bat_label, False, True, 6) if "battery" in settings["commands"] and settings["commands"][ "battery"]: img = Gtk.Image() update_image(img, "pan-end-symbolic", self.icon_size, self.icons_path) inner_hbox.pack_end(img, False, True, 4) event_box.add(inner_vbox) check_key(settings, "custom-items", []) if settings["custom-items"]: for item in settings["custom-items"]: check_key(item, "name", "undefined") check_key(item, "icon", "") check_key(item, "cmd", "") c_item = self.custom_item(item["name"], item["icon"], item["cmd"]) v_box.pack_start(c_item, True, True, 2) check_key(settings, "menu", {}) if settings["menu"]: template = settings["menu"] sep = Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL) v_box.pack_start(sep, True, True, 10) e_box = Gtk.EventBox() box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0) e_box.add(box) inner_hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0) box.pack_start(inner_hbox, True, True, 6) v_box.pack_start(e_box, True, True, 6) img = Gtk.Image() update_image(img, template["icon"], self.icon_size, self.icons_path) inner_hbox.pack_start(img, False, False, 6) check_key(template, "name", "Menu name") label = Gtk.Label(template["name"]) inner_hbox.pack_start(label, False, False, 6) check_key(template, "items", []) if template["items"]: img = Gtk.Image() update_image(img, "pan-down-symbolic", self.icon_size, self.icons_path) inner_hbox.pack_end(img, False, True, 5) e_box.connect("enter-notify-event", self.on_enter_notify_event) e_box.connect("leave-notify-event", self.on_leave_notify_event) self.menu_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6) v_box.pack_start(self.menu_box, False, False, 0) for item in template["items"]: eb = Gtk.EventBox() vb = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0) hb = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0) vb.pack_start(hb, False, False, 3) i = Gtk.Label(item["name"]) hb.pack_start(i, False, False, self.icon_size + 18) eb.add(vb) eb.connect("enter_notify_event", self.on_enter_notify_event) eb.connect("leave_notify_event", self.on_leave_notify_event) eb.connect("button-press-event", self.launch, item["cmd"]) self.menu_box.pack_start(eb, False, False, 0) e_box.connect('button-press-event', self.switch_menu_box) Gdk.threads_add_timeout(GLib.PRIORITY_LOW, 500, self.refresh)
def __init__(self, settings, position, alignment, width, monitor=None, icons_path=""): self.settings = settings self.position = position self.alignment = alignment self.icons_path = icons_path Gtk.EventBox.__init__(self) check_key(settings, "show-values", True) check_key(settings, "icon-size", 16) check_key(settings, "interval", 1) check_key(settings, "icon-size", 16) check_key(settings, "hover-opens", True) check_key(settings, "leave-closes", True) check_key(settings, "css-name", "controls-label") check_key(settings, "components", ["net", "brightness", "volume", "battery"]) check_key(settings, "net-interface", "") self.icon_size = settings["icon-size"] self.net_icon_name = "view-refresh-symbolic" self.net_image = Gtk.Image.new_from_icon_name(self.net_icon_name, Gtk.IconSize.MENU) self.net_label = Gtk.Label() if settings["show-values"] else None self.net_ip_addr = None self.bri_icon_name = "view-refresh-symbolic" self.bri_image = Gtk.Image.new_from_icon_name(self.bri_icon_name, Gtk.IconSize.MENU) self.bri_label = Gtk.Label() if settings["show-values"] else None self.bri_value = 0 self.vol_icon_name = "view-refresh-symbolic" self.vol_image = Gtk.Image.new_from_icon_name(self.vol_icon_name, Gtk.IconSize.MENU) self.vol_label = Gtk.Label() if settings["show-values"] else None self.vol_value = 0 self.vol_muted = False self.bt_icon_name = "view-refresh-symbolic" self.bt_image = Gtk.Image.new_from_icon_name(self.bt_icon_name, Gtk.IconSize.MENU) self.bt_label = Gtk.Label() if settings["show-values"] else None self.bt_name = "" self.bat_icon_name = "view-refresh-symbolic" self.bat_image = Gtk.Image.new_from_icon_name(self.bat_icon_name, Gtk.IconSize.MENU) self.bat_label = Gtk.Label() if settings["show-values"] else None self.bat_value = 0 self.bat_time = "" self.bat_charging = False self.pan_image = Gtk.Image() update_image(self.pan_image, "pan-down-symbolic", self.icon_size, self.icons_path) self.box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0) self.add(self.box) self.popup_window = PopupWindow(self, position, alignment, settings, width, monitor=monitor, icons_path=self.icons_path) self.connect('button-press-event', self.on_button_press) self.connect('enter-notify-event', self.on_enter_notify_event) self.connect('leave-notify-event', self.on_leave_notify_event) self.build_box() self.refresh() if "battery" in settings["components"]: self.refresh_bat() if settings["interval"] > 0: Gdk.threads_add_timeout_seconds(GLib.PRIORITY_LOW, settings["interval"], self.refresh) if "battery" in settings["components"]: Gdk.threads_add_timeout_seconds(GLib.PRIORITY_LOW, 5, self.refresh_bat)
def __init__(self, settings, icons_path): self.settings = settings self.icons_path = icons_path Gtk.EventBox.__init__(self) self.box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0) self.add(self.box) self.image = Gtk.Image() self.label = Gtk.Label("") self.icon_path = None check_key(settings, "script", "") check_key(settings, "interval", 0) check_key(settings, "css-name", "") check_key(settings, "icon-placement", "left") check_key(settings, "icon-size", 16) check_key(settings, "tooltip-text", "") check_key(settings, "on-left-click", "") check_key(settings, "on-right-click", "") check_key(settings, "on-middle-click", "") check_key(settings, "on-scroll-up", "") check_key(settings, "on-scroll-down", "") update_image(self.image, "view-refresh-symbolic", self.settings["icon-size"], self.icons_path) if settings["css-name"]: self.label.set_property("name", settings["css-name"]) else: self.label.set_property("name", "executor-label") if settings["tooltip-text"]: self.set_tooltip_text(settings["tooltip-text"]) if settings["on-left-click"] or settings["on-right-click"] or settings[ "on-middle-click"] or settings["on-scroll-up"] or settings[ "on-scroll-down"]: self.connect('button-press-event', self.on_button_press) self.add_events(Gdk.EventMask.SCROLL_MASK) self.connect('scroll-event', self.on_scroll) self.connect('enter-notify-event', self.on_enter_notify_event) self.connect('leave-notify-event', self.on_leave_notify_event) self.build_box() self.refresh() if settings["interval"] > 0: Gdk.threads_add_timeout_seconds(GLib.PRIORITY_LOW, settings["interval"], self.refresh)
def __init__(self, position, settings, width, monitor=None): Gtk.Window.__init__(self, type_hint=Gdk.WindowTypeHint.NORMAL) GtkLayerShell.init_for_window(self) if monitor: GtkLayerShell.set_monitor(self, monitor) check_key(settings, "css-name", "controls-window") self.set_property("name", settings["css-name"]) self.icon_size = settings["icon-size"] self.settings = settings self.position = position self.bt_icon_name = "" self.bt_image = Gtk.Image() eb = Gtk.EventBox() eb.set_above_child(False) self.connect("leave_notify_event", self.on_window_exit) outer_vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0) eb.add(outer_vbox) self.add(eb) outer_hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0) Gtk.Widget.set_size_request(outer_hbox, width, 10) outer_vbox.pack_start(outer_hbox, True, True, 20) v_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0) outer_hbox.pack_start(v_box, True, True, 20) GtkLayerShell.set_layer(self, GtkLayerShell.Layer.TOP) # GtkLayerShell.set_keyboard_interactivity(self, True) GtkLayerShell.set_margin(self, GtkLayerShell.Edge.TOP, 6) GtkLayerShell.set_margin(self, GtkLayerShell.Edge.BOTTOM, 6) GtkLayerShell.set_margin(self, GtkLayerShell.Edge.RIGHT, 6) GtkLayerShell.set_margin(self, GtkLayerShell.Edge.LEFT, 6) if settings["alignment"] == "left": GtkLayerShell.set_anchor(self, GtkLayerShell.Edge.LEFT, True) else: GtkLayerShell.set_anchor(self, GtkLayerShell.Edge.RIGHT, True) if position == "bottom": GtkLayerShell.set_anchor(self, GtkLayerShell.Edge.BOTTOM, True) else: GtkLayerShell.set_anchor(self, GtkLayerShell.Edge.TOP, True) check_key(settings, "commands", {"battery": "", "net": ""}) add_sep = False if "brightness" in settings["components"]: inner_hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0) v_box.pack_start(inner_hbox, False, False, 0) self.bri_icon_name = "view-refresh-symbolic" self.bri_image = Gtk.Image.new_from_icon_name(self.bri_icon_name, Gtk.IconSize.MENU) icon_name = bri_icon_name(int(get_brightness())) if icon_name != self.bri_icon_name: update_image(self.bri_image, icon_name, self.icon_size) self.bri_icon_name = icon_name inner_hbox.pack_start(self.bri_image, False, False, 6) scale = Gtk.Scale.new_with_range(orientation=Gtk.Orientation.HORIZONTAL, min=0, max=100, step=1) value = get_brightness() scale.set_value(value) scale.connect("value-changed", self.set_bri) inner_hbox.pack_start(scale, True, True, 5) add_sep = True if "volume" in settings["components"]: inner_hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0) v_box.pack_start(inner_hbox, False, False, 6) self.vol_icon_name = "view-refresh-symbolic" self.vol_image = Gtk.Image.new_from_icon_name(self.vol_icon_name, Gtk.IconSize.MENU) vol, switch = get_volume() icon_name = vol_icon_name(vol, switch) if icon_name != self.vol_icon_name: update_image(self.vol_image, icon_name, self.icon_size) self.vol_icon_name = icon_name inner_hbox.pack_start(self.vol_image, False, False, 6) scale = Gtk.Scale.new_with_range(orientation=Gtk.Orientation.HORIZONTAL, min=0, max=100, step=1) value, switch = get_volume() scale.set_value(value) scale.connect("value-changed", self.set_vol) inner_hbox.pack_start(scale, True, True, 5) add_sep = True if add_sep: sep = Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL) v_box.pack_start(sep, True, True, 10) if "net" in settings["components"] and dependencies["netifaces"]: event_box = Gtk.EventBox() if "net" in settings["commands"] and settings["commands"]["net"]: event_box.connect("enter_notify_event", self.on_enter_notify_event) event_box.connect("leave_notify_event", self.on_leave_notify_event) event_box.connect('button-press-event', self.launch, settings["commands"]["net"]) inner_vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0) inner_hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0) inner_vbox.pack_start(inner_hbox, True, True, 6) v_box.pack_start(event_box, True, True, 10) self.net_icon_name = "view-refresh-symbolic" self.net_image = Gtk.Image.new_from_icon_name(self.net_icon_name, Gtk.IconSize.MENU) ip_addr = get_interface(settings["net-interface"]) icon_name = "network-wired-symbolic" if ip_addr else "network-wired-disconnected-symbolic" if icon_name != self.net_icon_name: update_image(self.net_image, icon_name, self.icon_size) self.net_icon_name = icon_name inner_hbox.pack_start(self.net_image, False, False, 6) self.net_label = Gtk.Label("{}: {}".format(settings["net-interface"], ip_addr)) inner_hbox.pack_start(self.net_label, False, True, 6) if "net" in settings["commands"] and settings["commands"]["net"]: img = Gtk.Image() update_image(img, "pan-end-symbolic", self.icon_size) inner_hbox.pack_end(img, False, True, 4) event_box.add(inner_vbox) if bt_service_enabled() and "bluetooth" in settings["components"]: event_box = Gtk.EventBox() if "bluetooth" in settings["commands"] and settings["commands"]["bluetooth"]: event_box.connect("enter_notify_event", self.on_enter_notify_event) event_box.connect("leave_notify_event", self.on_leave_notify_event) event_box.connect('button-press-event', self.launch, settings["commands"]["bluetooth"]) inner_vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0) inner_hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0) inner_vbox.pack_start(inner_hbox, True, True, 6) v_box.pack_start(event_box, True, True, 6) self.bt_icon_name = "view-refresh-symbolic" self.bt_image = Gtk.Image.new_from_icon_name(self.bt_icon_name, Gtk.IconSize.MENU) icon_name = bt_icon_name(bt_on()) if icon_name != self.bt_icon_name: update_image(self.bt_image, icon_name, self.icon_size) self.bt_icon_name = icon_name inner_hbox.pack_start(self.bt_image, False, False, 6) self.bt_label = Gtk.Label(bt_name()) inner_hbox.pack_start(self.bt_label, False, True, 6) if "bluetooth" in settings["commands"] and settings["commands"]["bluetooth"]: img = Gtk.Image() update_image(img, "pan-end-symbolic", self.icon_size) inner_hbox.pack_end(img, False, True, 4) event_box.add(inner_vbox) if "battery" in settings["components"]: event_box = Gtk.EventBox() if "battery" in settings["commands"] and settings["commands"]["battery"]: event_box.connect("enter_notify_event", self.on_enter_notify_event) event_box.connect("leave_notify_event", self.on_leave_notify_event) event_box.connect('button-press-event', self.launch, settings["commands"]["battery"]) inner_vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0) inner_hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0) inner_vbox.pack_start(inner_hbox, True, True, 6) v_box.pack_start(event_box, True, True, 6) self.bat_icon_name = "view-refresh-symbolic" self.bat_image = Gtk.Image.new_from_icon_name(self.bat_icon_name, Gtk.IconSize.MENU) msg, level = get_battery() icon_name = bat_icon_name(level) if icon_name != self.bat_icon_name: update_image(self.bat_image, icon_name, self.icon_size) self.bat_icon_name = icon_name inner_hbox.pack_start(self.bat_image, False, False, 6) self.bat_label = Gtk.Label(msg) inner_hbox.pack_start(self.bat_label, False, True, 6) if "battery" in settings["commands"] and settings["commands"]["battery"]: img = Gtk.Image() update_image(img, "pan-end-symbolic", self.icon_size) inner_hbox.pack_end(img, False, True, 4) event_box.add(inner_vbox) check_key(settings, "custom-items", []) if settings["custom-items"]: for item in settings["custom-items"]: c_item = self.custom_item(item["name"], item["icon"], item["cmd"]) v_box.pack_start(c_item, True, True, 6) check_key(settings, "menu", {}) if settings["menu"]: template = settings["menu"] sep = Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL) v_box.pack_start(sep, True, True, 10) e_box = Gtk.EventBox() box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0) e_box.add(box) inner_hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0) box.pack_start(inner_hbox, True, True, 6) v_box.pack_start(e_box, True, True, 6) img = Gtk.Image() update_image(img, template["icon"], self.icon_size) inner_hbox.pack_start(img, False, False, 6) check_key(template, "name", "Menu name") label = Gtk.Label(template["name"]) inner_hbox.pack_start(label, False, False, 6) check_key(template, "items", []) if template["items"]: img = Gtk.Image() update_image(img, "pan-end-symbolic", self.icon_size) inner_hbox.pack_end(img, False, True, 0) e_box.connect("enter-notify-event", self.on_enter_notify_event) e_box.connect("leave-notify-event", self.on_leave_notify_event) self.menu_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6) v_box.pack_start(self.menu_box, False, False, 0) for item in template["items"]: eb = Gtk.EventBox() vb = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0) hb = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0) vb.pack_start(hb, False, False, 6) i = Gtk.Label(item["name"]) hb.pack_start(i, False, False, self.icon_size + 18) eb.add(vb) eb.connect("enter_notify_event", self.on_enter_notify_event) eb.connect("leave_notify_event", self.on_leave_notify_event) eb.connect("button-press-event", self.launch, item["cmd"]) self.menu_box.pack_start(eb, False, False, 0) e_box.connect('button-press-event', self.switch_menu_box) Gdk.threads_add_timeout_seconds(GLib.PRIORITY_LOW, settings["interval"], self.refresh)
def __init__(self, settings, icons_path=""): self.settings = settings self.icons_path = icons_path Gtk.EventBox.__init__(self) check_key(settings, "interval", 1) check_key(settings, "label-css-name", "") check_key(settings, "button-css-name", "") check_key(settings, "icon-size", 16) check_key(settings, "buttons-position", "left") check_key(settings, "chars", 30) self.box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0) self.box.set_property("name", "task-box") self.add(self.box) self.image = Gtk.Image() update_image(self.image, "view-refresh-symbolic", self.settings["icon-size"], icons_path=self.icons_path) self.label = Gtk.Label("") self.icon_path = None self.play_pause_btn = Gtk.Button() check_key(settings, "button-css-name", "") if self.settings["button-css-name"]: self.play_pause_btn.set_property("name", self.settings["button-css-name"]) self.status = "" self.retries = 2 # to avoid hiding the module on forward / backward btn when playing from the browser if settings["label-css-name"]: self.label.set_property("name", settings["label-css-name"]) self.build_box() self.refresh() if settings["interval"] > 0: Gdk.threads_add_timeout_seconds(GLib.PRIORITY_LOW, settings["interval"], self.refresh)
def build_box(self): check_key(self.settings, "numbers", [1, 2, 3, 4, 5, 6, 7, 8]) check_key(self.settings, "show-icon", True) check_key(self.settings, "image-size", 16) check_key(self.settings, "show-name", True) check_key(self.settings, "name-length", 40) check_key(self.settings, "mark-autotiling", True) check_key(self.settings, "mark-content", True) check_key(self.settings, "show-layout", True) if self.i3.get_tree().find_focused(): ws_num, win_name, win_id, non_empty, win_layout = self.find_details( ) for num in self.settings["numbers"]: eb = Gtk.EventBox() eb.connect("enter_notify_event", self.on_enter_notify_event) eb.connect("leave_notify_event", self.on_leave_notify_event) eb.connect("button-press-event", self.on_click, num) self.pack_start(eb, False, False, 0) box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0) eb.add(box) if self.settings["mark-autotiling"]: try: at = int(num) in self.autotiling except: at = False autotiling = "a" if at in self.autotiling else "" lbl = Gtk.Label("{}{}".format(autotiling, str(num))) else: lbl = Gtk.Label("{}".format(str(num))) self.ws_num2box[num] = eb self.ws_num2lbl[num] = lbl box.pack_start(lbl, False, False, 6) if num == str(ws_num): eb.set_property("name", "task-box-focused") else: eb.set_property("name", "task-box") if self.settings["show-icon"]: self.pack_start(self.icon, False, False, 6) if self.settings["show-name"]: self.pack_start(self.name_label, False, False, 0) if self.settings["show-layout"]: self.pack_start(self.layout_icon, False, False, 6)
def __init__(self, con, settings, position, icons_path, floating=False): self.position = position self.settings = settings Gtk.EventBox.__init__(self) self.box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0) self.add(self.box) self.con = con self.pid = con.pid self.icons_path = icons_path self.old_name = "" if con.focused: self.box.set_property("name", "task-box-focused") else: self.box.set_property("name", "task-box") self.connect('enter-notify-event', self.on_enter_notify_event) self.connect('leave-notify-event', self.on_leave_notify_event) self.connect('button-press-event', self.on_click, self.box) self.add_events(Gdk.EventMask.SCROLL_MASK) self.connect('scroll-event', self.on_scroll) check_key(settings, "show-app-icon", True) if settings["show-app-icon"]: name = con.app_id if con.app_id else con.window_class icon_from_desktop = get_icon(name) if icon_from_desktop: if "/" not in icon_from_desktop and not icon_from_desktop.endswith( ".svg") and not icon_from_desktop.endswith(".png"): image = Gtk.Image() update_image(image, icon_from_desktop, settings["image-size"], icons_path) else: try: pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size( icon_from_desktop, settings["image-size"], settings["image-size"]) except: pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size( os.path.join(get_config_dir(), "icons_light/icon-missing.svg"), settings["image-size"], settings["image-size"]) image = Gtk.Image.new_from_pixbuf(pixbuf) self.box.pack_start(image, False, False, 4) else: image = Gtk.Image() update_image(image, name, settings["image-size"], icons_path) self.box.pack_start(image, False, False, 4) if con.name: check_key(settings, "show-app-name", True) name = con.name[:settings["name-max-len"]] if len( con.name) > settings["name-max-len"] else con.name if settings["show-app-name"]: check_key(settings, "name-max-len", 10) label = Gtk.Label(name) self.box.pack_start(label, False, False, 0) else: self.set_tooltip_text(name) check_key(settings, "show-layout", True) if settings["show-layout"] and con.parent.layout: if con.parent.layout == "splith": image = Gtk.Image() update_image(image, "go-next-symbolic", 16, icons_path) elif con.parent.layout == "splitv": image = Gtk.Image() update_image(image, "go-down-symbolic", 16, icons_path) elif con.parent.layout == "tabbed": image = Gtk.Image() update_image(image, "view-dual-symbolic", 16, icons_path) elif con.parent.layout == "stacked": image = Gtk.Image() update_image(image, "view-paged-symbolic", 16, icons_path) if floating: image = Gtk.Image() update_image(image, "window-pop-out-symbolic", 16, icons_path) self.box.pack_start(image, False, False, 4)