Skip to content

Commit

Permalink
Do some GUI cleanup for OWS profiles feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Crozzers committed May 5, 2024
1 parent 5a92fcd commit 14df286
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 23 deletions.
48 changes: 27 additions & 21 deletions src/gui/on_spawn_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ def header(text: str):
txt.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
return txt

sizer = wx.StaticBoxSizer(wx.VERTICAL, self, label=f'{profile["name"]!r} profile')

# create widgets
enable_opt = wx.CheckBox(self, id=1, label='React to new windows being created')
enable_opt = wx.CheckBox(sizer.GetStaticBox(), id=1, label='React to new windows being created')
enable_opt.SetToolTip('It\'s recommended to disable "Prune window history" when this is enabled')
self.panel = wx.Panel(self)
self.panel = wx.Panel(sizer.GetStaticBox())
header1 = header('When a new window spawns:')

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

### TODO: add note here explaining why one must be filled

apply_to_widgets = (header5, window_name_label, window_name, window_exe_label, window_exe)
apply_to_widgets = (header5, explainer_box, window_name_label, window_name, window_exe_label, window_exe)

# set state
enable_opt.SetValue(self.profile['enabled'])
Expand Down Expand Up @@ -178,6 +188,7 @@ def header(text: str):
simple_box_sizer(
self.panel,
(
*apply_to_widgets,
header1,
self.rc_opt,
header2,
Expand All @@ -189,16 +200,14 @@ def header(text: str):
skip_non_resizable_opt,
match_resizability_opt,
header4,
fuzzy_mtm_opt,
*apply_to_widgets
fuzzy_mtm_opt
),
group_mode=wx.HORIZONTAL,
)

sizer = wx.BoxSizer(wx.VERTICAL)
for widget in (enable_opt, self.panel):
# panel does its own padding
sizer.Add(widget, 0, wx.ALL, 5 if widget != self.panel else 0)
sizer.Add(widget, 0, wx.ALL | wx.EXPAND, 5 if widget != self.panel else 0)
self.SetSizerAndFit(sizer)

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

self.profile_box = wx.StaticBox(self, label='Profiles')
action_panel = wx.Panel(self.profile_box)
profile_box_sizer = wx.StaticBoxSizer(wx.VERTICAL, self, label='Profiles')
action_panel = wx.Panel(profile_box_sizer.GetStaticBox())
add_profile_btn = wx.Button(action_panel, label='Add profile')
del_profile_btn = wx.Button(action_panel, label='Delete profile')

self.profiles_list = EditableListCtrl(
self.profile_box,
profile_box_sizer.GetStaticBox(),
post_edit=self.rename_profile,
style=wx.LC_REPORT | wx.LC_EDIT_LABELS | wx.LC_SINGLE_SEL
)
Expand All @@ -278,20 +287,17 @@ def __init__(self, parent: wx.Frame):
action_sizer.Add(del_profile_btn)
action_panel.SetSizerAndFit(action_sizer)

profile_sizer = wx.BoxSizer(wx.VERTICAL)
profile_sizer.Add(action_panel)
profile_sizer.Add(self.profiles_list)
self.profile_box.SetSizerAndFit(profile_sizer)

profile_box_sizer.Add(action_panel, 0, wx.ALL, 5)
profile_box_sizer.Add(self.profiles_list, 0, wx.ALL, 5)

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

self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(self.profile_box)
self.sizer.Add(self.profile_panel)
self.sizer.Add(profile_box_sizer, 0, wx.ALL | wx.EXPAND, 5)
self.sizer.Add(self.profile_panel, 0, wx.ALL | wx.EXPAND, 5)
self.SetSizerAndFit(self.sizer)

self.SetupScrolling()

def add_profile(self, event: wx.Event):
new = default_spawn_settings()
self.profiles_list.Append((new['name'],))
Expand Down Expand Up @@ -343,7 +349,7 @@ def set_state(self, selected = None):
else:
profile = self.settings['profiles'][selected - 1]
self.profile_panel = OnSpawnPanel(self, profile, self.on_save)
self.sizer.Add(self.profile_panel, 0, wx.ALL | wx.EXPAND, 0)
self.sizer.Add(self.profile_panel, 0, wx.ALL | wx.EXPAND, 5)
self.sizer.Layout()
self.profile_panel.Update()
self.SetupScrolling()
Expand Down
8 changes: 6 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,13 @@ def find_matching_profile(window: Window) -> Optional[dict]:
apply_to = profile.get('apply_to', {})
if not apply_to:
continue
name = apply_to.get('name', '') or None
exe = apply_to.get('executable', '') or None
if not name and not exe:
continue
score = (
match(apply_to.get('name', '') or None, window.name)
+ match(apply_to.get('executable', '') or None, window.executable)
match(name, window.name)
+ match(exe, window.executable)
)
matches.append((score, profile))
if not matches:
Expand Down

0 comments on commit 14df286

Please sign in to comment.