Skip to content

Commit 14df286

Browse files
committed
Do some GUI cleanup for OWS profiles feature
1 parent 5a92fcd commit 14df286

File tree

2 files changed

+33
-23
lines changed

2 files changed

+33
-23
lines changed

src/gui/on_spawn_manager.py

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,12 @@ def header(text: str):
6767
txt.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
6868
return txt
6969

70+
sizer = wx.StaticBoxSizer(wx.VERTICAL, self, label=f'{profile["name"]!r} profile')
71+
7072
# create widgets
71-
enable_opt = wx.CheckBox(self, id=1, label='React to new windows being created')
73+
enable_opt = wx.CheckBox(sizer.GetStaticBox(), id=1, label='React to new windows being created')
7274
enable_opt.SetToolTip('It\'s recommended to disable "Prune window history" when this is enabled')
73-
self.panel = wx.Panel(self)
75+
self.panel = wx.Panel(sizer.GetStaticBox())
7476
header1 = header('When a new window spawns:')
7577

7678
# reused later on in Misc settings.
@@ -127,6 +129,16 @@ def header(text: str):
127129
apply_to_widgets = ()
128130
else:
129131
header5 = header('Apply to:')
132+
explainer_box = wx.StaticText(
133+
self.panel,
134+
label=(
135+
'These boxes control which windows this profile will be applied against.'
136+
' If you leave one box empty, it will be ignored. If both are empty, the profile is ignored.'
137+
' Profiles are matched against windows based on the closest and most specific match.'
138+
' If no specific match is found, the "Global" profile is used.'
139+
)
140+
)
141+
explainer_box.Wrap(700)
130142
window_name_label = wx.StaticText(self.panel, label='Window name (regex) (leave empty to match all windows):')
131143
window_name = wx.TextCtrl(self.panel, id=12)
132144
window_exe_label = wx.StaticText(self.panel, label='Window executable (regex) (leave empty to match all windows):')
@@ -138,9 +150,7 @@ def header(text: str):
138150
window_name.Bind(wx.EVT_KEY_UP, self.on_setting)
139151
window_exe.Bind(wx.EVT_KEY_UP, self.on_setting)
140152

141-
### TODO: add note here explaining why one must be filled
142-
143-
apply_to_widgets = (header5, window_name_label, window_name, window_exe_label, window_exe)
153+
apply_to_widgets = (header5, explainer_box, window_name_label, window_name, window_exe_label, window_exe)
144154

145155
# set state
146156
enable_opt.SetValue(self.profile['enabled'])
@@ -178,6 +188,7 @@ def header(text: str):
178188
simple_box_sizer(
179189
self.panel,
180190
(
191+
*apply_to_widgets,
181192
header1,
182193
self.rc_opt,
183194
header2,
@@ -189,16 +200,14 @@ def header(text: str):
189200
skip_non_resizable_opt,
190201
match_resizability_opt,
191202
header4,
192-
fuzzy_mtm_opt,
193-
*apply_to_widgets
203+
fuzzy_mtm_opt
194204
),
195205
group_mode=wx.HORIZONTAL,
196206
)
197207

198-
sizer = wx.BoxSizer(wx.VERTICAL)
199208
for widget in (enable_opt, self.panel):
200209
# panel does its own padding
201-
sizer.Add(widget, 0, wx.ALL, 5 if widget != self.panel else 0)
210+
sizer.Add(widget, 0, wx.ALL | wx.EXPAND, 5 if widget != self.panel else 0)
202211
self.SetSizerAndFit(sizer)
203212

204213
def on_setting(self, event: wx.Event):
@@ -254,13 +263,13 @@ def __init__(self, parent: wx.Frame):
254263
if (ows := self.settings_file.get('on_window_spawn')) is not None:
255264
self.settings.update(ows)
256265

257-
self.profile_box = wx.StaticBox(self, label='Profiles')
258-
action_panel = wx.Panel(self.profile_box)
266+
profile_box_sizer = wx.StaticBoxSizer(wx.VERTICAL, self, label='Profiles')
267+
action_panel = wx.Panel(profile_box_sizer.GetStaticBox())
259268
add_profile_btn = wx.Button(action_panel, label='Add profile')
260269
del_profile_btn = wx.Button(action_panel, label='Delete profile')
261270

262271
self.profiles_list = EditableListCtrl(
263-
self.profile_box,
272+
profile_box_sizer.GetStaticBox(),
264273
post_edit=self.rename_profile,
265274
style=wx.LC_REPORT | wx.LC_EDIT_LABELS | wx.LC_SINGLE_SEL
266275
)
@@ -278,20 +287,17 @@ def __init__(self, parent: wx.Frame):
278287
action_sizer.Add(del_profile_btn)
279288
action_panel.SetSizerAndFit(action_sizer)
280289

281-
profile_sizer = wx.BoxSizer(wx.VERTICAL)
282-
profile_sizer.Add(action_panel)
283-
profile_sizer.Add(self.profiles_list)
284-
self.profile_box.SetSizerAndFit(profile_sizer)
290+
291+
profile_box_sizer.Add(action_panel, 0, wx.ALL, 5)
292+
profile_box_sizer.Add(self.profiles_list, 0, wx.ALL, 5)
285293

286294
self.profile_panel = OnSpawnPanel(self, self.settings, self.on_save)
287295

288296
self.sizer = wx.BoxSizer(wx.VERTICAL)
289-
self.sizer.Add(self.profile_box)
290-
self.sizer.Add(self.profile_panel)
297+
self.sizer.Add(profile_box_sizer, 0, wx.ALL | wx.EXPAND, 5)
298+
self.sizer.Add(self.profile_panel, 0, wx.ALL | wx.EXPAND, 5)
291299
self.SetSizerAndFit(self.sizer)
292300

293-
self.SetupScrolling()
294-
295301
def add_profile(self, event: wx.Event):
296302
new = default_spawn_settings()
297303
self.profiles_list.Append((new['name'],))
@@ -343,7 +349,7 @@ def set_state(self, selected = None):
343349
else:
344350
profile = self.settings['profiles'][selected - 1]
345351
self.profile_panel = OnSpawnPanel(self, profile, self.on_save)
346-
self.sizer.Add(self.profile_panel, 0, wx.ALL | wx.EXPAND, 0)
352+
self.sizer.Add(self.profile_panel, 0, wx.ALL | wx.EXPAND, 5)
347353
self.sizer.Layout()
348354
self.profile_panel.Update()
349355
self.SetupScrolling()

src/main.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,13 @@ def find_matching_profile(window: Window) -> Optional[dict]:
143143
apply_to = profile.get('apply_to', {})
144144
if not apply_to:
145145
continue
146+
name = apply_to.get('name', '') or None
147+
exe = apply_to.get('executable', '') or None
148+
if not name and not exe:
149+
continue
146150
score = (
147-
match(apply_to.get('name', '') or None, window.name)
148-
+ match(apply_to.get('executable', '') or None, window.executable)
151+
match(name, window.name)
152+
+ match(exe, window.executable)
149153
)
150154
matches.append((score, profile))
151155
if not matches:

0 commit comments

Comments
 (0)