gui

GUI frontend for tools, based on customtkinter.

The window is built from the click commands of the tool, with a checkbox for each command flag. Log messages are shown in a textbox, and progress bars are reported through logging messages with a “prg-” prefix.

class hacktools.gui.tqdm_gui(*args, **kwargs)[source]

Progress bar that also reports its state through logging messages.

The messages use a “prg-” prefix, they’re hidden from the log file and turned into progress bar updates by LogHandler. The console bar is still shown when the tool has a console attached.

display(*args, **kwargs)[source]

Log a prg-update message with the current progress.

close()[source]

Log a prg-end message and close the bar.

clear(*args, **kwargs)[source]

Clear the console bar, when the tool has a console attached.

cancel()[source]

Run the cancel callback, if any, and close the bar.

reset(total=None)[source]

Log a prg-start message and reset the bar.

Parameters:

total (int | None) – New total number of iterations.

class hacktools.gui.LogHandler(guiapp)[source]

Logging handler that forwards log messages to the GUI.

Parameters:

guiapp (GUIApp) – The application window to forward messages to.

guiapp

The application window.

prgtotal

Total count of the progress bar being updated.

emit(record)[source]

Show a log record in the textbox, or update the progress bar.

Records with the “prg-” prefix logged by tqdm_gui update the progress bar, the others are added to the textbox. Records below info level are ignored.

Parameters:

record (LogRecord) – Log record to show.

Return type:

None

class hacktools.gui.GUIOptions(advanced=False, appearance='System', command='extract', options=[])[source]

Options saved in the tool json config file.

Parameters:
  • advanced (bool)

  • appearance (str)

  • command (str)

  • options (list[str])

advanced

Whether advanced mode is enabled.

appearance

Appearance mode, “System”, “Light” or “Dark”.

command

Last command that was selected.

options

Names of the flags that were checked for the last command.

class hacktools.gui.GUIApp[source]

Main window of the GUI frontend, a singleton.

The window is created empty and built by initialize().

initialize(cligroup, appname, appversion, datafolder)[source]

Build the window and load the saved options.

Parameters:
  • cligroup – click.Group holding the commands of the tool.

  • appname (str) – Name of the tool, used for the title and the config file.

  • appversion (str) – Version of the tool, shown in the title.

  • datafolder (str) – Folder with the tool data files, mentioned in the message shown when a command finishes.

Return type:

None

createEntry()[source]

Create the manual command entry shown in advanced mode.

Return type:

None

entryPressed(_)[source]

Run the command typed in the manual entry.

Parameters:

_ – Key event, unused.

Return type:

None

changeCommand(currentval)[source]

Switch to a command, showing a checkbox for each of its flags.

Parameters:

currentval (str) – Name of the command to switch to.

Return type:

None

changeCheckbox()[source]

Save the currently checked flags in the options.

Return type:

None

runCommand()[source]

Run the selected command with the checked flags.

Return type:

None

runThread(func)[source]

Run an async function in a new thread with its own event loop.

Parameters:

func (Callable) – Async function to run.

Return type:

None

clearTextbox()[source]

Delete all the messages in the textbox.

Return type:

None

addMessages(messages)[source]

Append messages to the textbox and scroll to the bottom.

Parameters:

messages (list[str]) – List of messages to add.

Return type:

None

setInputEnabled(enabled)[source]

Enable or disable all the input widgets.

Parameters:

enabled (bool) – Whether the widgets should be enabled.

Return type:

None

clickContext(choice)[source]

Handle the context menu, toggling advanced mode or the appearance.

Parameters:

choice (str) – Selected menu entry.

Return type:

None

loadOptions()[source]

Load the options from the config file, resetting them if invalid.

Return type:

None

saveOptions()[source]

Save the current options to the config file.

Return type:

None

async runClickCommand()[source]

Invoke the current command, showing a message when it finishes.

async runStartup()[source]

Run the startup checks of the tool.