Executor most likely ready

This commit is contained in:
piotr
2021-01-21 00:49:51 +01:00
parent 255bffa245
commit ebbcefcdad
4 changed files with 80 additions and 25 deletions

View File

@@ -8,3 +8,5 @@ outputs = {}
taskbars_list = []
config_dir = ""
app_dirs = []
key_missing = False

View File

@@ -32,6 +32,8 @@ def listener_reply():
def instantiate_content(panel, container, content_list):
check_key(panel, "items-padding", 0)
for item in content_list:
if item == "sway-taskbar":
if "sway-taskbar" in panel:
@@ -42,39 +44,38 @@ def instantiate_content(panel, container, content_list):
taskbar = SwayTaskbar(panel["sway-taskbar"], display_name="{}".format(panel["output"]))
common.taskbars_list.append(taskbar)
container.pack_start(taskbar, True, False, 0)
container.pack_start(taskbar, True, False, panel["items-padding"])
else:
print("'sway-taskbar' not defined in this panel instance")
if item == "sway-workspaces":
if "sway-workspaces" in panel:
workspaces = SwayWorkspaces(panel["sway-workspaces"])
container.pack_start(workspaces, True, False, 0)
container.pack_start(workspaces, True, False, panel["items-padding"])
else:
print("'sway-workspaces' not defined in this panel instance")
if "button-" in item:
if item in panel:
button = CustomButton(panel[item])
container.pack_start(button, True, False, 0)
container.pack_start(button, True, False, panel["items-padding"])
else:
print("'{}' not defined in this panel instance".format(item))
if "executor-" in item:
if item in panel:
executor = Executor(panel[item])
container.pack_start(executor, True, False, 0)
container.pack_start(executor, True, False, panel["items-padding"])
else:
print("'{}' not defined in this panel instance".format(item))
if item == "clock":
if item in panel:
clock = Clock(panel[item])
container.pack_start(clock, True, False, 0)
container.pack_start(clock, True, False, panel["items-padding"])
else:
clock = Clock({})
container.pack_start(clock, True, False, 0)
#print("'{}' not defined in this panel instance".format(item))
container.pack_start(clock, True, False, panel["items-padding"])
def main():
@@ -175,6 +176,10 @@ def main():
if output_to_focus:
common.i3.command("focus output {}".format(output_to_focus))
if common.key_missing:
print("Saving amended config")
save_json(panels, os.path.join(common.config_dir, "config_amended"))
#GLib.timeout_add(100, listener_reply)
Gdk.threads_add_timeout(GLib.PRIORITY_DEFAULT_IDLE, 50, listener_reply)
Gtk.main()

View File

@@ -8,6 +8,7 @@ import threading
from nwg_panel.tools import check_key
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('Gdk', '3.0')
@@ -19,25 +20,44 @@ class Executor(Gtk.EventBox):
self.settings = settings
Gtk.EventBox.__init__(self)
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.new_from_icon_name("wtf", Gtk.IconSize.MENU)
self.label = Gtk.Label("")
# We won't warn about these keys missing, so they need to be mentioned id README
if "css-name" in settings:
self.label.set_property("name", settings["css-name"])
else:
self.label.set_property("name", "executor-label")
if "icon-size" not in self.settings:
self.settings["icon-size"] = 16
self.icon_path = None
check_key(settings, "script", "")
check_key(settings, "interval", 0)
check_key(settings, "css-name", "")
check_key(settings, "icon-size", 16)
check_key(settings, "show-icon", True)
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", "")
if settings["css-name"]:
self.set_property("name", settings["css-name"])
else:
self.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()
check_key(settings, "interval", 0)
if settings["interval"] > 0:
Gdk.threads_add_timeout_seconds(GLib.PRIORITY_LOW, settings["interval"], self.refresh)
@@ -64,7 +84,7 @@ class Executor(Gtk.EventBox):
return False
def get_output(self):
if "script" in self.settings:
if "script" in self.settings and self.settings["script"]:
try:
output = subprocess.check_output(self.settings["script"].split()).decode("utf-8").splitlines()
GLib.idle_add(self.update_widget, output)
@@ -78,7 +98,34 @@ class Executor(Gtk.EventBox):
return True
def build_box(self):
self.box.pack_start(self.image, False, False, 4)
self.box.pack_start(self.label, False, False, 0)
self.box.pack_start(self.image, False, False, 2)
self.box.pack_start(self.label, False, False, 2)
self.label.show()
def on_enter_notify_event(self, widget, event):
self.get_style_context().set_state(Gtk.StateFlags.SELECTED)
def on_leave_notify_event(self, widget, event):
self.get_style_context().set_state(Gtk.StateFlags.NORMAL)
def on_button_press(self, widget, event):
if event.button == 1 and self.settings["on-left-click"]:
self.launch(self.settings["on-left-click"])
elif event.button == 2 and self.settings["on-middle-click"]:
self.launch(self.settings["on-middle-click"])
elif event.button == 3 and self.settings["on-right-click"]:
self.launch(self.settings["on-right-click"])
else:
print("No command assigned")
def on_scroll(self, widget, event):
if event.direction == Gdk.ScrollDirection.UP and self.settings["on-scroll-up"]:
self.launch(self.settings["on-scroll-up"])
elif event.direction == Gdk.ScrollDirection.DOWN and self.settings["on-scroll-up"]:
self.launch(self.settings["on-scroll-up"])
else:
print("No command assigned")
def launch(self, cmd):
print("Executing '{}'".format(cmd))
subprocess.Popen('exec {}'.format(cmd), shell=True)

View File

@@ -137,3 +137,4 @@ def check_key(dictionary, key, default_value):
if key not in dictionary:
dictionary[key] = default_value
print('Key missing, using default: "{}": {}'.format(key, default_value))
common.key_missing = True