Skip to content

Commit

Permalink
[gui] Implement installer UI and worker thread
Browse files Browse the repository at this point in the history
  • Loading branch information
kuba2k2 committed Dec 15, 2023
1 parent e4dc88d commit 0098651
Show file tree
Hide file tree
Showing 8 changed files with 674 additions and 21 deletions.
3 changes: 3 additions & 0 deletions gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
from ltchiptool.gui import cli

if __name__ == "__main__":
from ltchiptool.util.ltim import LTIM

LTIM.get().is_gui_entrypoint = True
cli()
35 changes: 32 additions & 3 deletions ltchiptool/gui/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@
from .base.window import BaseWindow
from .panels.log import LogPanel
from .utils import load_xrc_file
from .work.base import BaseThread
from .work.install import InstallThread


# noinspection PyPep8Naming
class InstallFrame(wx.Frame, BaseWindow):
failed: bool = False
finished: bool = False

def __init__(self, install_kwargs: dict, *args, **kw):
super().__init__(*args, **kw)

Expand All @@ -41,8 +45,9 @@ def __init__(self, install_kwargs: dict, *args, **kw):
self.SetMinSize((600, 200))
self.Center()

@staticmethod
def ShowExceptionMessage(e, msg):
def ShowExceptionMessage(self, e, msg):
self.failed = True
self.finished = True
wx.MessageBox(
message="Installation failed!\n\nRefer to the log window for details.",
caption="Error",
Expand All @@ -51,8 +56,32 @@ def ShowExceptionMessage(e, msg):

def OnShow(self, *_):
self.InitWindow(self)
self.StartWork(InstallThread(**self.install_kwargs))
thread = InstallThread(**self.install_kwargs)
thread.daemon = True
self.StartWork(thread)

def OnWorkStopped(self, t: BaseThread):
if self.failed:
return
wx.MessageBox(
message="Installation finished\n\nClick OK to close the installer",
caption="Success",
style=wx.ICON_INFORMATION,
)
self.Close()

def OnClose(self, *_):
if self.finished:
self.Destroy()
return
if (
wx.MessageBox(
message="Do you want to cancel the installation process?",
caption="Installation in progress",
style=wx.ICON_QUESTION | wx.YES_NO,
)
!= wx.YES
):
return
self.StopWork(InstallThread)
self.Destroy()
175 changes: 175 additions & 0 deletions ltchiptool/gui/ltchiptool.wxui
Original file line number Diff line number Diff line change
Expand Up @@ -696,5 +696,180 @@
</node>
</node>
</node>
<node
class="PanelForm"
base_file="installpanel_base"
class_name="InstallPanel">
<node
class="wxBoxSizer"
orientation="wxVERTICAL"
flags="wxEXPAND">
<node
class="wxStaticText"
label="This page allows to install ltchiptool on your computer, making it possible to install plugins and keep the tool up-to-date.&#10;&#10;The program can be installed for all users (recommended) or in &quot;portable&quot; mode (for transferring between PCs).&#10;&#10;Proceeding with the installation will install Python in an isolated environment.&#10;Desktop shortcuts for using the GUI or CLI can also be created." />
<node
class="wxStaticLine"
size="20,-1d"
colspan="3"
flags="wxEXPAND"
row="6" />
<node
class="wxStaticText"
label="Predefined installation modes:"
var_name="m_staticText_6"
alignment="wxALIGN_CENTER_HORIZONTAL"
borders="wxTOP|wxRIGHT|wxLEFT" />
<node
class="wxBoxSizer"
var_name="box_sizer_2"
alignment="wxALIGN_CENTER_HORIZONTAL"
borders="">
<node
class="wxButton"
auth_needed="1"
label="Full installation"
var_name="button_full" />
<node
class="wxButton"
label="Portable installation"
var_name="button_portable"
borders="wxTOP|wxBOTTOM|wxRIGHT" />
</node>
<node
class="wxStaticLine"
var_name="static_line_2"
size="20,-1d"
colspan="3"
flags="wxEXPAND"
row="6" />
<node
class="wxStaticText"
label="Target directory"
var_name="m_staticText_2" />
<node
class="wxBoxSizer"
var_name="box_sizer_3"
borders="wxBOTTOM"
flags="wxEXPAND">
<node
class="wxTextCtrl"
var_name="input_out_path"
borders="wxRIGHT|wxLEFT"
proportion="1" />
<node
class="wxButton"
label="Browse"
var_name="button_browse"
borders="wxRIGHT"
column="2"
flags="wxEXPAND"
row="3" />
</node>
<node
class="wxStaticLine"
var_name="static_line_3"
size="20,-1d"
flags="wxEXPAND" />
<node
class="wxBoxSizer"
var_name="box_sizer_4"
borders=""
flags="wxEXPAND">
<node
class="wxBoxSizer"
orientation="wxVERTICAL"
var_name="box_sizer_5"
borders=""
proportion="1">
<node
class="wxStaticText"
label="Desktop shortcuts"
var_name="m_staticText_3" />
<node
class="wxRadioButton"
label="Do not create"
style="wxRB_GROUP"
var_name="radio_shortcut_none"
borders="wxBOTTOM|wxRIGHT|wxLEFT" />
<node
class="wxRadioButton"
label="Just for me"
var_name="radio_shortcut_private" />
<node
class="wxRadioButton"
label="For all users"
var_name="radio_shortcut_public" />
</node>
<node
class="wxStaticLine"
style="wxLI_VERTICAL"
var_name="static_line_4"
size="-1,-1d"
borders="wxTOP|wxBOTTOM|wxRIGHT"
flags="wxEXPAND" />
<node
class="wxBoxSizer"
orientation="wxVERTICAL"
var_name="box_sizer_6"
borders=""
proportion="1">
<node
class="wxStaticText"
label="File association"
var_name="m_staticText_4" />
<node
class="wxCheckBox"
label="UF2"
var_name="checkbox_fta_uf2"
borders="wxBOTTOM|wxRIGHT|wxLEFT" />
<node
class="wxCheckBox"
label="RBL"
var_name="checkbox_fta_rbl" />
<node
class="wxCheckBox"
label="BIN"
var_name="checkbox_fta_bin" />
</node>
<node
class="wxStaticLine"
style="wxLI_VERTICAL"
var_name="static_line_5"
size="-1,-1d"
borders="wxTOP|wxBOTTOM|wxRIGHT"
flags="wxEXPAND" />
<node
class="wxBoxSizer"
orientation="wxVERTICAL"
var_name="box_sizer_7"
borders=""
proportion="1">
<node
class="wxStaticText"
label="Other options"
var_name="m_staticText_5" />
<node
class="wxCheckBox"
label="Add to PATH"
var_name="checkbox_add_path"
borders="wxBOTTOM|wxRIGHT|wxLEFT" />
</node>
</node>
<node
class="wxStaticLine"
var_name="static_line_6"
size="20,-1d"
flags="wxEXPAND" />
<node
class="wxCommandLinkButton"
main_label="Start"
note="-"
var_name="button_start"
borders="wxBOTTOM|wxRIGHT|wxLEFT"
column="1"
flags="wxEXPAND"
row="7" />
</node>
</node>
</node>
</wxUiEditorData>
Loading

0 comments on commit 0098651

Please sign in to comment.