Skip to content

Commit

Permalink
[gui] Add project support link
Browse files Browse the repository at this point in the history
  • Loading branch information
kuba2k2 committed Oct 28, 2023
1 parent 8dcb18a commit 82ae373
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 0 deletions.
1 change: 1 addition & 0 deletions gui-win32.spec
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ a = Analysis(
("ltchiptool/gui/ltchiptool-192x192.png", "."),
("ltchiptool/gui/ltchiptool.ico", "."),
("ltchiptool/gui/ltchiptool.xrc", "."),
("ltchiptool/gui/ko-fi.png", "."),
("ltchiptool/gui/colors.json", "."),
("pyproject.toml", "."),
]
Expand Down
Binary file added ltchiptool/gui/ko-fi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions ltchiptool/gui/ltchiptool.wxui
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,36 @@
border_size="0"
flags="wxEXPAND"
proportion="1" />
<node
class="wxPanel"
var_name="panel_donate"
window_style="wxTAB_TRAVERSAL"
borders=""
flags="wxEXPAND">
<node
class="wxBoxSizer"
var_name="sizer_donate">
<node
class="wxStaticBitmap"
scale_mode="Fill"
var_name="bmp_donate"
size="48,32"
alignment="wxALIGN_CENTER"
borders="wxRIGHT|wxLEFT" />
<node
class="wxHyperlinkCtrl"
label="Support the LibreTiny project"
url="https://ko-fi.com/kuba2k2"
var_name="link_donate"
size="-1,-1d"
alignment="wxALIGN_CENTER"
borders="wxTOP|wxBOTTOM|wxRIGHT"
proportion="1" />
<node
class="CloseButton"
var_name="button_donate_close" />
</node>
</node>
</node>
</node>
<node
Expand Down
34 changes: 34 additions & 0 deletions ltchiptool/gui/ltchiptool.xrc
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,40 @@
<fg>#FFFFFF</fg>
</object>
</object>
<object class="sizeritem">
<flag>wxEXPAND</flag>
<border>5</border>
<object class="wxPanel" name="panel_donate">
<style>wxTAB_TRAVERSAL</style>
<object class="wxBoxSizer" name="sizer_donate">
<orient>wxHORIZONTAL</orient>
<object class="sizeritem">
<flag>wxRIGHT|wxLEFT|wxALIGN_CENTER</flag>
<border>5</border>
<object class="wxStaticBitmap" name="bmp_donate">
<size>48,32</size>
</object>
</object>
<object class="sizeritem">
<flag>wxTOP|wxBOTTOM|wxRIGHT|wxALIGN_CENTER</flag>
<border>5</border>
<option>1</option>
<object class="wxHyperlinkCtrl" name="link_donate">
<label>Support the LibreTiny project</label>
<url>https://ko-fi.com/kuba2k2</url>
<style>wxHL_DEFAULT_STYLE</style>
</object>
</object>
<object class="sizeritem">
<flag>wxALL</flag>
<border>5</border>
<object class="wxBitmapButton" name="button_donate_close">
<close>1</close>
</object>
</object>
</object>
</object>
</object>
</object>
</object>
<object class="wxPanel" name="FlashPanel">
Expand Down
31 changes: 31 additions & 0 deletions ltchiptool/gui/panels/log.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Copyright (c) Kuba Szczodrzyński 2023-1-8.

import logging
import sys
import threading
import time
from logging import INFO, info, log, warning
from multiprocessing import Queue
from os.path import dirname, join
from queue import Empty

import wx
Expand Down Expand Up @@ -93,6 +95,7 @@ def render_finish(self) -> None:
# noinspection PyPep8Naming
class LogPanel(BasePanel):
log_queue: Queue
donate_closed: bool = False

def __init__(self, parent: wx.Window, frame):
super().__init__(parent, frame)
Expand All @@ -117,6 +120,20 @@ def __init__(self, parent: wx.Window, frame):
GUIProgressBar.render_finish(GUIProgressBar)
setattr(_termui_impl, "ProgressBar", GUIProgressBar)

if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"):
donate = join(sys._MEIPASS, "ko-fi.png")
else:
donate = join(dirname(__file__), "..", "ko-fi.png")

bitmap = self.FindStaticBitmap("bmp_donate")
height = 28
image = wx.Image(donate)
ratio = image.GetWidth() / image.GetHeight()
image.Rescale(int(ratio * height), height, wx.IMAGE_QUALITY_BICUBIC)
bitmap.SetBitmap(image)

This comment has been minimized.

Copy link
@makuser

makuser Nov 26, 2023

15:32:51: Debug: Adding duplicate image handler for 'Windows bitmap file'
E: TypeError: StaticBitmap.SetBitmap(): argument 1 has unexpected type 'Image'
E: |-- File "/home/marc/.local/lib/python3.10/site-packages/ltchiptool/gui/panels/log.py", line 133, in __init__

self.BindButton("button_donate_close", self.OnDonateClose)

def emit_raw(self, log_prefix: str, message: str, color: str):
if threading.current_thread() is not threading.main_thread():
# NEVER block worker threads by waiting for main thread availability
Expand Down Expand Up @@ -145,6 +162,7 @@ def GetSettings(self) -> dict:
raw=handler.raw,
full_traceback=handler.full_traceback,
dump_serial=LoggingStreamHook.is_registered(Serial),
donate_closed=self.donate_closed,
)

def SetSettings(
Expand All @@ -154,6 +172,7 @@ def SetSettings(
raw: bool = False,
full_traceback: bool = True,
dump_serial: bool = False,
donate_closed: bool = False,
**_,
):
handler = LoggingHandler.get()
Expand Down Expand Up @@ -181,6 +200,10 @@ def SetSettings(
case _ if item.GetItemLabel() == level_name:
item.Check()

if donate_closed:
# noinspection PyTypeChecker
self.OnDonateClose(None)

@on_event
def OnIdle(self):
while True:
Expand All @@ -189,6 +212,14 @@ def OnIdle(self):
except Empty:
break

@on_event
def OnDonateClose(self):
self.donate_closed = True
panel: wx.Panel = self.FindWindowByName("panel_donate", self)
panel.Hide()
self.Layout()
self.Update()

def OnClose(self):
super().OnClose()
LoggingHandler.get().clear_emitters()
Expand Down

0 comments on commit 82ae373

Please sign in to comment.