Skip to content

Commit

Permalink
allow panel width as percentage #355
Browse files Browse the repository at this point in the history
  • Loading branch information
nwg-piotr committed Nov 29, 2024
1 parent 054bccc commit 46c539a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
6 changes: 6 additions & 0 deletions nwg_panel/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,7 @@ def check_defaults(self):
"controls": "off",
"menu-start": "off",
"width": "auto",
"width-as-percentage": False,
"height": 0,
"margin-top": 0,
"margin-bottom": 0,
Expand Down Expand Up @@ -1042,6 +1043,9 @@ def edit_panel(self, *args):
adj = Gtk.Adjustment(value=0, lower=0, upper=upper, step_increment=1, page_increment=10, page_size=1)
self.sb_width.configure(adj, 1, 0)

self.ckb_width_percentage = builder.get_object("as-percentage")
self.ckb_width_percentage.set_active(self.panel["width-as-percentage"])

self.ckb_width_auto = builder.get_object("width-auto")
if isinstance(self.panel["width"], int):
self.sb_width.set_value(float(self.panel["width"]))
Expand Down Expand Up @@ -1172,6 +1176,8 @@ def update_panel(self):
if val:
self.panel["layer"] = val

self.panel["width-as-percentage"] = self.ckb_width_percentage.get_active()

val = self.ckb_width_auto.get_active()
if val:
self.panel["width"] = "auto"
Expand Down
12 changes: 11 additions & 1 deletion nwg_panel/glade/config_panel.glade
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,17 @@
</packing>
</child>
<child>
<placeholder/>
<object class="GtkCheckButton" id="as-percentage">
<property name="label" translatable="yes">%</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">2</property>
<property name="top-attach">7</property>
</packing>
</child>
<child>
<placeholder/>
Expand Down
9 changes: 9 additions & 0 deletions nwg_panel/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,7 @@ def main():
# This is to allow width "auto" value. Actually all non-numeric values will be removed.
if "width" in panel and not isinstance(panel["width"], int):
panel.pop("width")
panel["width-as-percentage"] = False

if panel["output"] in common.outputs or not panel["output"]:
check_key(panel, "spacing", 6)
Expand All @@ -628,6 +629,8 @@ def main():
check_key(panel, "use-sigrt", False)
check_key(panel, "start-hidden", False)

check_key(panel, "width-as-percentage", True)

window = Gtk.Window()
global panel_windows_hide_show_sigs
if panel["use-sigrt"]:
Expand All @@ -649,6 +652,12 @@ def main():
if "output" in panel and panel["output"] and "width" not in panel:
panel["width"] = common.outputs[panel["output"]]["width"]

# Width defined as percentage
if "width" in panel and panel["width"] > 0 and panel["width-as-percentage"]:
if panel["width"] > 100:
panel["width"] = 100
panel["width"] = int(common.outputs[panel["output"]]["width"] * panel["width"] / 100)

check_key(panel, "width", 0)
w = panel["width"]

Expand Down

0 comments on commit 46c539a

Please sign in to comment.