add common settings GUI

This commit is contained in:
piotr
2023-01-03 01:03:20 +01:00
parent 7294d9ead0
commit b8cc4c61f7
2 changed files with 59 additions and 6 deletions

View File

@@ -23,6 +23,22 @@ sway = os.getenv('SWAYSOCK') is not None
config_dir = get_config_dir()
data_home = os.getenv('XDG_DATA_HOME') if os.getenv('XDG_DATA_HOME') else os.path.join(os.getenv("HOME"),
".local/share")
cs_file = os.path.join(config_dir, "common-settings.json")
if not os.path.isfile(cs_file):
common_settings = {
"restart-delay": 0
}
save_json(common_settings, cs_file)
else:
common_settings = load_json(cs_file)
print("Common settings:", common_settings)
args_file = os.path.join(data_home, "nwg-panel", "args")
args = load_string(args_file) if os.path.isfile(args_file) else ""
restart_cmd = "nwg-panel {}".format(args)
print("Restart command: ", restart_cmd)
configs = {}
editor = None
selector_window = None
@@ -220,8 +236,7 @@ def handle_keyboard(window, event):
def build_common_settings_window():
win = Gtk.Window.new(Gtk.WindowType.TOPLEVEL)
# win.connect("key-release-event", handle_keyboard)
# win.connect('destroy', Gtk.main_quit)
win.set_modal(True)
vbox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0)
vbox.set_property("margin", 6)
@@ -229,10 +244,34 @@ def build_common_settings_window():
frame = Gtk.Frame()
frame.set_label(" nwg-panel: Common settings ")
frame.set_label_align(0.5, 0.5)
vbox.pack_start(frame, True, True, 6)
grid = Gtk.Grid()
frame.add(grid)
grid.set_column_spacing(6)
grid.set_row_spacing(6)
grid.set_property("margin", 12)
lbl = Gtk.Label.new("Restart delay [ms]:")
lbl.set_property("halign", Gtk.Align.END)
grid.attach(lbl, 0, 0, 1, 1)
sb = Gtk.SpinButton.new_with_range(0, 10000, 100)
sb.set_value(common_settings["restart-delay"])
sb.connect("changed", on_restart_delay_changed)
sb.set_tooltip_text("If, after turning a display off and back on, panels don't appear on it, it may mean\n"
"the display responds too slowly (e.g. if turned via HDMI). Try adding some delay.\n"
"Starting from 500 ms is a good idea.")
grid.attach(sb, 1, 0, 1, 1)
hbox = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 6)
vbox.pack_start(hbox, False, False, 6)
btn = Gtk.Button.new_with_label("Apply")
btn.connect("clicked", apply_common_settings, win)
hbox.pack_end(btn, False, False, 6)
btn = Gtk.Button.new_with_label("Close")
btn.connect("clicked", close_common_settings, win)
hbox.pack_end(btn, False, False, 6)
@@ -242,10 +281,22 @@ def build_common_settings_window():
return win
def on_restart_delay_changed(sb):
global common_settings
common_settings["restart-delay"] = int(sb.get_value())
def close_common_settings(btn, window):
window.close()
def apply_common_settings(btn, window):
save_json(common_settings, cs_file)
print(restart_cmd)
subprocess.Popen(restart_cmd, shell=True)
window.close()
class PanelSelector(Gtk.Window):
def __init__(self):
super(PanelSelector, self).__init__()
@@ -2339,7 +2390,8 @@ class EditorWrapper(object):
self.executor_sigrt = builder.get_object("sigrt")
self.executor_sigrt.set_numeric(True)
adj = Gtk.Adjustment(value=0, lower=signal.SIGRTMIN, upper=signal.SIGRTMAX+1, step_increment=1, page_increment=1, page_size=1)
adj = Gtk.Adjustment(value=0, lower=signal.SIGRTMIN, upper=signal.SIGRTMAX + 1, step_increment=1,
page_increment=1, page_size=1)
self.executor_sigrt.configure(adj, 1, 0)
self.executor_sigrt.set_value(settings["sigrt"])

View File

@@ -678,7 +678,8 @@ def list_configs(config_dir):
# allow to store json files other than panel config files in the config directory
# (prevents from crash w/ nwg-drawer>=0.1.7 and future nwg-menu versions)
exclusions = [os.path.join(config_dir, "preferred-apps.json"),
os.path.join(config_dir, "calendar.json")]
os.path.join(config_dir, "calendar.json"),
os.path.join(config_dir, "common-settings.json")]
entries = os.listdir(config_dir)
entries.sort()
for entry in entries: