Skip to content

Commit

Permalink
Merge pull request #366 from nwg-piotr/submap
Browse files Browse the repository at this point in the history
Add HyprlandSubmap module, improve SwayMode module
  • Loading branch information
nwg-piotr authored Dec 19, 2024
2 parents b09cff5 + 3fe70be commit 132d7b6
Show file tree
Hide file tree
Showing 9 changed files with 334 additions and 6 deletions.
1 change: 1 addition & 0 deletions nwg_panel/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
windows_list = []
h_taskbars_list = []
h_workspaces_list = []
h_submaps_list = []
controls_list = []
executors_list = []
tray_list = []
Expand Down
70 changes: 69 additions & 1 deletion nwg_panel/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,7 @@ def __init__(self, parent, file, panel_idx, plugin_menu_start):
builder.get_object("dwl-tags").set_text(voc["dwl-tags"])
builder.get_object("hyprland-taskbar").set_text(voc["hyprland-taskbar"])
builder.get_object("hyprland-workspaces").set_text(voc["hyprland-workspaces"])
builder.get_object("hyprland-submap").set_text(voc["hyprland-submap"])
builder.get_object("brightness-slider").set_text(voc["brightness-slider"])
builder.get_object("keyboard-layout").set_text(voc["keyboard-layout"])
builder.get_object("executors").set_text(voc["executors"])
Expand Down Expand Up @@ -831,7 +832,7 @@ def __init__(self, parent, file, panel_idx, plugin_menu_start):
builder.get_object("eb-dwl-tags").connect("button-press-event", self.edit_dwl_tags)
builder.get_object("eb-hyprland-taskbar").connect("button-press-event", self.edit_hyprland_taskbar)
builder.get_object("eb-hyprland-workspaces").connect("button-press-event", self.edit_hyprland_workspaces)

builder.get_object("eb-hyprland-submap").connect("button-press-event", self.edit_hyprland_submap)
builder.get_object("eb-keyboard-layout").connect("button-press-event", self.edit_keyboard_layout)

builder.get_object("eb-executors").connect("button-press-event", self.select_executor)
Expand Down Expand Up @@ -1273,6 +1274,8 @@ def apply_changes(self, *args):
self.update_hyprland_taskbar()
elif self.edited == "hyprland-workspaces":
self.update_hyprland_workspaces()
elif self.edited == "hyprland-submap":
self.update_hyprland_submap()
elif self.edited == "keyboard-layout":
self.update_keyboard_layout()
elif self.edited == "openweather":
Expand Down Expand Up @@ -2786,6 +2789,71 @@ def update_sway_mode(self, *args):

save_json(self.config, self.file)

def edit_hyprland_submap(self, *args):
self.load_panel()
self.edited = "hyprland-submap"
check_key(self.panel, "hyprland-submap", {})
settings = self.panel["hyprland-submap"]
defaults = {
"show-default": False,
"show-icon": True,
"css-name": "executor-label",
"icon-size": 16,
"angle": 0.0
}
for key in defaults:
check_key(settings, key, defaults[key])

builder = Gtk.Builder.new_from_file(os.path.join(dir_name, "glade/config_hyprland_submap.glade"))
frame = builder.get_object("frame")
frame.set_label(" {}: HyprlandSubmap ".format(voc["module"]))

builder.get_object("lbl-icon-size").set_text("{}:".format(voc["icon-size"]))
builder.get_object("lbl-css-name").set_text("{}:".format(voc["css-name"]))
builder.get_object("lbl-angle").set_text("{}:".format(voc["angle"]))

self.mode_css_name = builder.get_object("css-name")
self.mode_css_name.set_tooltip_text(voc["css-name-tooltip"])
self.mode_css_name.set_text(settings["css-name"])

self.mode_icon_size = builder.get_object("icon-size")
self.mode_icon_size.set_numeric(True)
adj = Gtk.Adjustment(value=0, lower=8, upper=128, step_increment=1, page_increment=10, page_size=1)
self.mode_icon_size.configure(adj, 1, 0)
self.mode_icon_size.set_value(settings["icon-size"])

self.mode_angle = builder.get_object("angle")
self.mode_angle.set_tooltip_text(voc["angle-tooltip"])
self.mode_angle.set_active_id(str(settings["angle"]))

self.mode_show_icon = builder.get_object("show-icon")
self.mode_show_icon.set_label(voc["show-icon"])
self.mode_show_icon.set_active(settings["show-icon"])

self.mode_show_default = builder.get_object("show-default")
self.mode_show_default.set_label(voc["show-default"])
self.mode_show_default.set_tooltip_text(voc["show-default-tooltip"])
self.mode_show_default.set_active(settings["show-default"])

for item in self.scrolled_window.get_children():
item.destroy()
self.scrolled_window.add(frame)

def update_hyprland_submap(self, *args):
settings = self.panel["hyprland-submap"]
settings["css-name"] = self.mode_css_name.get_text()
settings["icon-size"] = int(self.mode_icon_size.get_value())

try:
settings["angle"] = float(self.mode_angle.get_active_id())
except:
settings["angle"] = 0.0

settings["show-icon"] = self.mode_show_icon.get_active()
settings["show-default"] = self.mode_show_default.get_active()

save_json(self.config, self.file)

def edit_openweather(self, *args):
self.load_panel()
self.edited = "openweather"
Expand Down
143 changes: 143 additions & 0 deletions nwg_panel/glade/config_hyprland_submap.glade
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.40.0 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<object class="GtkFrame" id="frame">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label-xalign">0.5</property>
<property name="shadow-type">out</property>
<child>
<!-- n-columns=3 n-rows=4 -->
<object class="GtkGrid" id="grid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-start">6</property>
<property name="margin-end">6</property>
<property name="margin-top">6</property>
<property name="margin-bottom">6</property>
<property name="row-spacing">10</property>
<property name="column-spacing">10</property>
<child>
<object class="GtkEntry" id="css-name">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="placeholder-text" translatable="yes">executor-label</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="lbl-css-name">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">end</property>
<property name="label" translatable="yes">CSS name:</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="lbl-icon-size">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">end</property>
<property name="label" translatable="yes">Icon size:</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="icon-size">
<property name="visible">True</property>
<property name="can-focus">True</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="angle">
<property name="visible">True</property>
<property name="can-focus">False</property>
<items>
<item id="0.0" translatable="yes">0°</item>
<item id="90.0" translatable="yes">90°</item>
<item id="270.0" translatable="yes">270°</item>
</items>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="lbl-angle">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">end</property>
<property name="label" translatable="yes">Angle:</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="show-icon">
<property name="label" translatable="yes">Show icon</property>
<property name="name">all-outputs</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">False</property>
<property name="draw-indicator">True</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">3</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="show-default">
<property name="label" translatable="yes">Show 'default'</property>
<property name="name">all-outputs</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">False</property>
<property name="draw-indicator">True</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">3</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Module: SwayMode</property>
</object>
</child>
</object>
</interface>
22 changes: 22 additions & 0 deletions nwg_panel/glade/config_main.glade
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,28 @@
</child>
</object>
</child>
<child>
<object class="GtkListBoxRow">
<property name="visible">True</property>
<property name="can-focus">True</property>
<child>
<object class="GtkEventBox" id="eb-hyprland-submap">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkLabel" id="hyprland-submap">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="margin-left">6</property>
<property name="margin-start">6</property>
<property name="label" translatable="yes">Hyprland Submap</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkListBoxRow">
<property name="visible">True</property>
Expand Down
1 change: 1 addition & 0 deletions nwg_panel/langs/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
"humidity": "Humidity",
"hyprland-taskbar": "Hyprland Taskbar",
"hyprland-workspaces": "Hyprland Workspaces",
"hyprland-submap": "Hyprland Submap",
"icon": "Icon",
"icon-placement": "Icon placement",
"icon-set": "Icon set",
Expand Down
1 change: 1 addition & 0 deletions nwg_panel/langs/pl_PL.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
"humidity": "Wilgotność",
"hyprland-taskbar": "Pasek zadań Hyprland",
"hyprland-workspaces": "Obszary robocze Hyprland",
"hyprland-submap": "Submapa Hyprland",
"icon": "Ikona",
"icon-placement": "Położenie ikony",
"icon-set": "Zestaw ikon",
Expand Down
16 changes: 16 additions & 0 deletions nwg_panel/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
from nwg_panel.modules.dwl_tags import DwlTags
from nwg_panel.modules.swaync import SwayNC
from nwg_panel.modules.sway_mode import SwayMode
from nwg_panel.modules.hyprland_submap import HyprlandSubmap
from nwg_panel.modules.keyboard_layout import KeyboardLayout
from nwg_panel.modules.random_wallpaper import RandomWallpaper

Expand Down Expand Up @@ -206,6 +207,10 @@ def hypr_watcher():
just_refreshed = True
break

elif event_name == "submap":
for item in common.h_submaps_list:
GLib.timeout_add(0, item.refresh)


def on_i3ipc_event(i3conn, event):
if common_settings["restart-on-display"]:
Expand Down Expand Up @@ -328,6 +333,17 @@ def instantiate_content(panel, container, content_list, icons_path=""):
else:
eprint("'hyprland-workspaces' ignored")

if item == "hyprland-submap":
if his:
if item in panel:
h_submap = HyprlandSubmap(panel[item], icons_path=icons_path)
else:
h_submap = HyprlandSubmap({}, icons_path=icons_path)
container.pack_start(h_submap, False, False, panel["items-padding"])
common.h_submaps_list.append(h_submap)
else:
eprint("HyprlandSubmap module only works on Hyprland, ignoring")

if item == "keyboard-layout":
if his or sway:
if "keyboard-layout" not in panel:
Expand Down
54 changes: 54 additions & 0 deletions nwg_panel/modules/hyprland_submap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env python3

from gi.repository import Gtk, GLib

from nwg_panel.tools import check_key, update_image, hyprctl


class HyprlandSubmap(Gtk.Box):
def __init__(self, settings, icons_path=""):
Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL, spacing=0)
self.settings = settings
self.label = Gtk.Label.new("default")
self.submap = "default"

icon = Gtk.Image()

defaults = {
"show-default": False,
"show-icon": True,
"css-name": "executor-label",
"icon-size": 16,
"angle": 0.0
}
for key in defaults:
check_key(settings, key, defaults[key])

update_image(icon, "mode", self.settings["icon-size"], icons_path)

if self.settings["css-name"]:
self.set_property("name", self.settings["css-name"])
else:
self.set_property("name", "executor-label")

if settings["angle"] != 0.0:
self.set_orientation(Gtk.Orientation.VERTICAL)
self.label.set_angle(settings["angle"])

if settings["show-icon"]:
self.pack_start(icon, False, False, 0)

self.pack_start(self.label, False, False, 6)

self.refresh()

if self.submap == "default" and not self.settings["show-default"]:
GLib.idle_add(self.hide, priority=GLib.PRIORITY_HIGH)

def refresh(self):
self.submap = hyprctl("submap").strip()
self.label.set_text(self.submap)
if self.submap != "default" or self.settings["show-default"]:
self.show_all()
else:
self.hide()
Loading

0 comments on commit 132d7b6

Please sign in to comment.