Skip to content

Commit

Permalink
feat(gui): Add key binding for profile application and update menu sh…
Browse files Browse the repository at this point in the history
…ortcuts

- Added a key binding for Ctrl+P to select a conversation profile in ConversationTab.
- Removed `on_key_down` method and integrated key event handling in `on_char_hook`.
- Updated key combination for preferences in MainFrame menu from Ctrl+Shift+P to Ctrl+,.
- Removed unused ID for preferences in MainFrame.
  • Loading branch information
AAClause committed Oct 5, 2024
1 parent d22ef64 commit fdee8ff
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
28 changes: 20 additions & 8 deletions basilisk/gui/conversation_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ def init_ui(self):

self.SetSizerAndFit(sizer)

self.Bind(wx.EVT_CHAR_HOOK, self.on_char_hook)

def init_data(self, profile: Optional[config.ConversationProfile]):
self.refresh_images_list()
self.apply_profile(profile, True)
Expand All @@ -223,6 +225,24 @@ def update_ui(self):
control.Show(advanced_mode)
self.Layout()

def on_choose_profile(self, event: wx.KeyEvent):
menu = wx.GetTopLevelParent(self).build_profile_menu(
wx.GetTopLevelParent(self).on_apply_conversation_profile
)

self.PopupMenu(menu)
menu.Destroy()

def on_char_hook(self, event: wx.KeyEvent):
modifiers = event.GetModifiers()
key_code = event.GetKeyCode()
actions = {(wx.MOD_CONTROL, ord('P')): self.on_choose_profile}
action = actions.get((modifiers, key_code))
if action:
action(event)
else:
event.Skip()

def on_account_change(self, event: wx.CommandEvent):
account = super().on_account_change(event)
if not account and not config.accounts():
Expand Down Expand Up @@ -769,14 +789,6 @@ def on_prompt_key_down(self, event: wx.KeyEvent):
def on_prompt_paste(self, event):
self.on_image_paste(event)

def on_key_down(self, event: wx.KeyEvent):
if (
event.GetModifiers() == wx.ACCEL_CTRL
and event.GetKeyCode() == wx.WXK_RETURN
):
self.on_submit(event)
event.Skip()

def insert_previous_prompt(self, event: wx.CommandEvent = None):
if self.conversation.messages:
last_user_message = self.conversation.messages[-1].request.content
Expand Down
7 changes: 2 additions & 5 deletions basilisk/gui/main_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def __init__(self, *args, **kwargs):
self.ID_ADD_IMAGE_FILE = wx.NewIdRef()
self.ID_ADD_URL_IMAGE = wx.NewIdRef()
self.ID_MANAGE_ACCOUNTS = wx.NewIdRef()
self.ID_PREFERENCES = wx.NewIdRef()
self.ID_VIEW_LOG = wx.NewIdRef()
self.ID_TOGGLE_RECORDING = wx.NewIdRef()
self.ID_TRANSCRIBE_AUDIO = wx.NewIdRef()
Expand Down Expand Up @@ -162,7 +161,7 @@ def update_item_label_suffix(item: wx.MenuItem, suffix: str = "..."):
conversation_profile_item = tool_menu.Append(
wx.ID_ANY,
# Translators: A label for a menu item to manage conversation profiles
_("Manage conversation &profiles") + "...\tCtrl+Shift+O",
_("Manage conversation &profiles") + "...\tCtrl+Shift+P",
)
self.Bind(
wx.EVT_MENU,
Expand All @@ -172,7 +171,7 @@ def update_item_label_suffix(item: wx.MenuItem, suffix: str = "..."):

preferences_item = tool_menu.Append(wx.ID_PREFERENCES)
self.Bind(wx.EVT_MENU, self.on_preferences, preferences_item)
update_item_label_suffix(preferences_item, "... (Ctrl+Shift+P)")
update_item_label_suffix(preferences_item, "...\tCtrl+,")
tool_menu.AppendSeparator()
install_nvda_addon = tool_menu.Append(
wx.ID_ANY, _("Install NVDA addon")
Expand Down Expand Up @@ -238,7 +237,6 @@ def init_accelerators(self):
self.Bind(
wx.EVT_MENU, self.on_manage_accounts, id=self.ID_MANAGE_ACCOUNTS
)
self.Bind(wx.EVT_MENU, self.on_preferences, id=self.ID_PREFERENCES)
self.Bind(wx.EVT_MENU, self.on_view_log, id=self.ID_VIEW_LOG)
self.Bind(
wx.EVT_MENU,
Expand All @@ -259,7 +257,6 @@ def init_accelerators(self):
(wx.ACCEL_CTRL, ord('I'), self.ID_ADD_IMAGE_FILE),
(wx.ACCEL_CTRL, ord('U'), self.ID_ADD_URL_IMAGE),
(wx.ACCEL_CTRL | wx.ACCEL_SHIFT, ord('A'), self.ID_MANAGE_ACCOUNTS),
(wx.ACCEL_CTRL | wx.ACCEL_SHIFT, ord('P'), self.ID_PREFERENCES),
(wx.ACCEL_CTRL | wx.ACCEL_SHIFT, wx.WXK_F1, self.ID_VIEW_LOG),
(wx.ACCEL_CTRL, ord('R'), self.ID_TOGGLE_RECORDING),
(
Expand Down

0 comments on commit fdee8ff

Please sign in to comment.