Skip to content

Commit

Permalink
Fix duplicate text fields and "Run Launch" tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
BGazotti committed Apr 18, 2024
1 parent bc22dd1 commit 46de7fe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
15 changes: 10 additions & 5 deletions Mopy/bash/basher/links_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"""Links initialization functions. Each panel's UIList has main and items Links
attributes which are populated here. Therefore the layout of the menus is
also defined in these functions."""
import multiprocessing
import os
import shlex
import threading
Expand Down Expand Up @@ -142,25 +143,29 @@ def _tool_args(app_key, app_path_data, clazz=AppButton, **kwargs):
'ShowAudioToolLaunchers']) for at in audio_tools.items())
all_links.extend(_tool_args(*mt) for mt in misc_tools.items())

# FIXME this is slow. Unusably slow. Even in parallel, there seems to be
# something about pefile that's incredibly slow and memory-hungry
# TODO native win32 handling for this
# should be very straightforward by requesting resources
# TODO switch to concurrent.futures.ThreadPoolExecutor? more elegant
local_PE_threads = list()
local_lock = threading.Lock()
def create_launcher_button(lpath: str, lname, largs): # TODO get this out of here

icons = (get_image('error_cross.16'),) * 3
try:
if icon_data := ExtractIcon(lpath).get_raw_windows_preferred_icon():
# -> this is an .ico file. Split icofrompath into two? Can't do that because wx expects a path
# very hacky: tmpfile? if only we could pass a fd instead of a path
# alternate hack: copy code from pillow's ico plugin? Might be
# a good call if we don't need any more code
icons = []
for value in (16, 24, 32):
# TODO use bash-specific wrappers - win32 does not need wx
icons.append(wx.Bitmap(wx.Image(value, value, icon_data)))
except pefile.PEFormatError:
pass # no icon in this file
# FIXME use AppButtonFactory?
pass # no icon in this file, or not an exe
# FIXME use AppButtonFactory? Maybe?
btn = AppButton(GPath_no_norm(lpath), icons,
_(f'Run {lname}'), lname,
lname, lname, # TODO custom tooltip
cli_args=largs, canHide=False)
local_lock.acquire()
all_links.append(btn)
Expand Down
30 changes: 11 additions & 19 deletions Mopy/bash/basher/settings_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
ScrollableWindow, Spacer, Stretch, TextArea, TextField, TreePanel, \
VBoxedLayout, VLayout, WrappingLabel, CENTER, VerticalLine, Spinner, \
showOk, askYes, askText, showError, askWarning, showInfo, ImageButton, \
get_image, HyperlinkLabel, FilePicker
get_image, HyperlinkLabel, FilePicker, popups
from ..update_checker import UpdateChecker, can_check_updates
from ..wbtemp import default_global_temp_dir

Expand Down Expand Up @@ -1532,7 +1532,7 @@ def should_appear():

# Launchers -------------------------------------------------------------------
class LaunchersPage(_AFixedPage):
"""Create, delete and toggle app launchers."""
"""Create, delete and toggle (soon!) app launchers."""

@staticmethod
def ___filter(): ##: todo temp we want to include all sb links that can be hidden
Expand All @@ -1556,6 +1556,7 @@ def __init__(self, parent, page_desc):
# Name, path and args
self._launcher_path = FilePicker(self)
self._launcher_path.button.tooltip = _('Select a file to launch.')
self._launcher_path.text_field.tooltip = _('Path to file')
self._launcher_args_txt = TextField(self)
self._launcher_args_txt.tooltip = _('Command line arguments')
self._launcher_name_txt = TextField(self)
Expand Down Expand Up @@ -1583,10 +1584,7 @@ def __init__(self, parent, page_desc):
(self._launcher_listbox, LayoutOptions(weight=1)),
HorizontalLine(self),
self._launcher_name_txt,
HLayout(spacing=2, item_expand=True, items=[
(self._launcher_path_txt, LayoutOptions(weight=1)),
self._pick_launcher_file_btn
]),
self._launcher_path,
self._launcher_args_txt,
HLayout(spacing=4, item_expand=True, items=[
self._save_launcher_btn,
Expand All @@ -1595,6 +1593,7 @@ def __init__(self, parent, page_desc):
])]).apply_to(self)

def _cleanup(self):
"""Clears text fields and resets button labels."""
# clear text fields
self._clear_textfields()
self._save_launcher_btn.button_label = _('Save')
Expand All @@ -1605,7 +1604,7 @@ def _cleanup(self):
self._new_launcher_btn.tooltip = _('New launcher')

def _clear_textfields(self):
for txt_field in (self._launcher_args_txt, self._launcher_path_txt,
for txt_field in (self._launcher_args_txt, self._launcher_path.text_field,
self._launcher_name_txt):
txt_field.text_content = ''

Expand All @@ -1614,20 +1613,14 @@ def _populate_launcher_listbox(self):
for launcher_name in bass.settings['bash.launchers']:
if launcher_name not in items:
items.append(launcher_name) # avoids duplicating custom items
self._launcher_listbox.lb_set_items(items)

def _update_file_txt_field(self):
picked_file = FileOpen.display_dialog(parent=self,
title=_('Choose app to launch'))
if picked_file:
self._launcher_path_txt.text_content = str(picked_file)
self._launcher_listbox.lb_set_items(items)

def _handle_launcher_selected(self, index: int, selected_str):
# is predefined?
if selected_str in bass.settings['bash.launchers']:
selected_launcher = bass.settings['bash.launchers'][selected_str]
# copy launcher details to textfields
(self._launcher_path_txt.text_content,
(self._launcher_path.text_field.text_content,
self._launcher_args_txt.text_content) = selected_launcher
self._remove_launcher_btn.enabled = True
self._save_launcher_btn.enabled = True
Expand All @@ -1636,16 +1629,16 @@ def _handle_launcher_selected(self, index: int, selected_str):
for comp in self._launcher_name_txt, self._launcher_args_txt:
comp.editable = False
app_as_button = BashStatusBar.all_sb_links[selected_str]
self._launcher_path_txt.text_content = app_as_button.app_path.cs
self._launcher_path.text_field.text_content = app_as_button.app_path.cs
self._launcher_args_txt.text_content = ''
for arg in app_as_button._exe_args: # FIXME dis ugly
self._launcher_args_txt.text_content += f'{arg} '
self._launcher_args_txt.text_content = self._launcher_args_txt. \
text_content[:-1]
text_content[:-1] # FIXME this is *very* ugly
self._launcher_name_txt.text_content = selected_str

def _reset_textfields(self):
self._launcher_path_txt.text_content = _('Path to application')
self._launcher_path.text_field.text_content = _('Path to application')
self._launcher_args_txt.text_content = _('Command line arguments')
self._launcher_name_txt.text_content = _('Shortcut name')

Expand Down Expand Up @@ -1705,7 +1698,6 @@ def _save_launcher(self):
self._populate_launcher_listbox()

def _remove_or_cancel(self):
from ..gui import popups
if self._is_creating_launcher: # cancel
self._new_launcher_mode(False)
self._clear_textfields()
Expand Down

0 comments on commit 46de7fe

Please sign in to comment.