Skip to content

Commit

Permalink
Add labels around enum buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
TeamSpen210 committed Aug 10, 2024
1 parent 4d6316c commit e4fb0f6
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
3 changes: 3 additions & 0 deletions src/app/corridor_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
TRANS_NO_OPTIONS = TransToken.ui('No options!')
TRANS_RAND_OPTION = TransToken.ui('Randomise')
TRANS_ONLY_THIS = TransToken.ui('Use Only This')
TRANS_GROUP_MODE = TransToken.ui('Game Mode')
TRANS_GROUP_DIR = TransToken.ui('Corridor Type')
TRANS_GROUP_ATTACH = TransToken.ui('Attachment Surface')

OPTS_MODE = [
(GameMode.SP, TransToken.ui('SP')),
Expand Down
10 changes: 6 additions & 4 deletions src/ui_tk/corridor_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

from app import WidgetCache, img
from app.corridor_selector import (
WIDTH, HEIGHT, IMG_ARROW_LEFT, IMG_ARROW_RIGHT, IMG_CORR_BLANK, Icon,
TRANS_GROUP_ATTACH, TRANS_GROUP_DIR, TRANS_GROUP_MODE, WIDTH, HEIGHT, IMG_ARROW_LEFT,
IMG_ARROW_RIGHT,
IMG_CORR_BLANK, Icon,
OPTS_DIR, OPTS_MODE, OPTS_ATTACH, OptionRow, Selector,
TRANS_HELP, TRANS_NO_OPTIONS, TRANS_ONLY_THIS, TRANS_RAND_OPTION, TRANS_TITLE,
)
Expand Down Expand Up @@ -262,9 +264,9 @@ def __init__(self, packset: packages.PackagesSet, tk_img: TKImages, cur_style: u

button_frm = ttk.Frame(frm_left)
button_frm.grid(row=0, column=0, columnspan=3)
self.btn_mode = tk_tools.EnumButton(button_frm, self.state_mode, OPTS_MODE)
self.btn_direction = tk_tools.EnumButton(button_frm, self.state_dir, OPTS_DIR)
self.btn_attach = tk_tools.EnumButton(button_frm, self.state_attach, OPTS_ATTACH)
self.btn_mode = tk_tools.EnumButton(button_frm, self.state_mode, TRANS_GROUP_MODE, OPTS_MODE)
self.btn_direction = tk_tools.EnumButton(button_frm, self.state_dir, TRANS_GROUP_DIR, OPTS_DIR)
self.btn_attach = tk_tools.EnumButton(button_frm, self.state_attach, TRANS_GROUP_ATTACH, OPTS_ATTACH)

self.btn_mode.frame.grid(row=0, column=0, padx=8)
self.btn_direction.frame.grid(row=0, column=1, padx=8)
Expand Down
6 changes: 4 additions & 2 deletions src/ui_tk/tk_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,17 +776,19 @@ class EnumButton[EnumT: Enum]:
This is bound to the provided AsyncValue, updating it when changed.
"""
frame: ttk.Frame
frame: ttk.LabelFrame
buttons: dict[EnumT, ttk.Button]
current: AsyncValue[EnumT]

def __init__(
self,
master: tk.Misc,
current: AsyncValue[EnumT],
title: TransToken,
values: Sequence[tuple[EnumT, TransToken]],
) -> None:
self.frame = ttk.Frame(master)
self.frame = ttk.LabelFrame(master, labelanchor='n')
set_text(self.frame, title)
self.current = current
self.buttons = {}

Expand Down
10 changes: 6 additions & 4 deletions src/ui_wx/corridor_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

from app import WidgetCache, img
from app.corridor_selector import (
WIDTH, HEIGHT, IMG_ARROW_LEFT, IMG_ARROW_RIGHT, IMG_CORR_BLANK, Icon,
TRANS_GROUP_ATTACH, TRANS_GROUP_DIR, TRANS_GROUP_MODE, WIDTH, HEIGHT, IMG_ARROW_LEFT,
IMG_ARROW_RIGHT,
IMG_CORR_BLANK, Icon,
OPTS_DIR, OPTS_MODE, OPTS_ATTACH, OptionRow, Selector,
TRANS_HELP, TRANS_NO_OPTIONS, TRANS_ONLY_THIS, TRANS_RAND_OPTION, TRANS_TITLE,
)
Expand Down Expand Up @@ -271,9 +273,9 @@ def __init__(self, packset: packages.PackagesSet, wx_img: WXImages, cur_style: u
sizer_btns = wx.BoxSizer(wx.HORIZONTAL)
sizer_left.Add(sizer_btns, wx.SizerFlags().CentreHorizontal())

self.btn_mode = EnumButton(self.pane_left, self.state_mode, OPTS_MODE)
self.btn_direction = EnumButton(self.pane_left, self.state_dir, OPTS_DIR)
self.btn_attach = EnumButton(self.pane_left, self.state_attach, OPTS_ATTACH)
self.btn_mode = EnumButton(self.pane_left, self.state_mode, TRANS_GROUP_MODE, OPTS_MODE)
self.btn_direction = EnumButton(self.pane_left, self.state_dir, TRANS_GROUP_DIR, OPTS_DIR)
self.btn_attach = EnumButton(self.pane_left, self.state_attach, TRANS_GROUP_ATTACH, OPTS_ATTACH)

btn_flags = wx.SizerFlags().Border(wx.LEFT | wx.RIGHT, 4)
sizer_btns.Add(self.btn_mode.sizer, btn_flags)
Expand Down
7 changes: 5 additions & 2 deletions src/ui_wx/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ def __init__(
self,
parent: wx.Window,
current: AsyncValue[EnumT],
title: TransToken,
values: Sequence[tuple[EnumT, TransToken]],
) -> None:
self.sizer = sizer = wx.BoxSizer(wx.HORIZONTAL)
self.frame = wx.StaticBox(parent, style=wx.ALIGN_CENTRE_HORIZONTAL)
self.sizer = sizer = wx.StaticBoxSizer(self.frame, wx.HORIZONTAL)
set_text(self.frame, title)
self.current = current
self.buttons = {}

for x, (val, label) in enumerate(values):
btn = wx.ToggleButton(parent)
btn = wx.ToggleButton(self.frame)
btn.Bind(wx.EVT_TOGGLEBUTTON, self._pressed_func(val))
set_text(btn, label)
sizer.Add(btn)
Expand Down

0 comments on commit e4fb0f6

Please sign in to comment.