Skip to content

Commit

Permalink
Connection info + font
Browse files Browse the repository at this point in the history
  • Loading branch information
randomouscrap98 committed Aug 5, 2023
1 parent a489305 commit 0991b95
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,4 @@ cython_debug/
ignore/
!arduboy_toolset_cli.spec
!arduboy_toolset.spec
*log.txt
Binary file added appresource/NotoEmoji-Medium.ttf
Binary file not shown.
4 changes: 2 additions & 2 deletions arduboy/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ def get_connected_devices(log = True, bootloader_only = False):

# Find a single arduboy device, and force it to use the bootloader. Note:
# MAY disconnect and reboot your arduboy device!
def find_single():
def find_single(enter_bootloader = True):
devices = get_connected_devices()
if len(devices) == 0:
raise Exception("No Arduboys found!")
# Assume first device is what you want
device = devices[0]
if not device.has_bootloader:
if enter_bootloader and not device.has_bootloader:
logging.info(f"Attempting to reset device {device}")
s_port = Serial(device.port,1200)
s_port.close()
Expand Down
85 changes: 79 additions & 6 deletions main_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
import os
import sys
import constants
import arduboy.device
from PyQt5.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QHBoxLayout, QWidget, QPushButton, QLabel, QTabWidget
from PyQt5 import QtGui
from PyQt5.QtCore import QTimer

# I don't know what registering a font multiple times will do, might as well just make it a global
EMOJIFONT = None

def main():

Expand All @@ -17,15 +21,45 @@ def main():
except ImportError:
pass

logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
logging.basicConfig(filename=os.path.join(constants.SCRIPTDIR, "arduboy_toolset_gui_log.txt"), level=logging.DEBUG,
format="%(asctime)s - %(levelname)s - %(message)s")

app = QApplication(sys.argv)
app = QApplication(sys.argv) # Frustrating... you HAVE to run this first before you do ANY QT stuff!
app.setWindowIcon(QtGui.QIcon(resource_file("icon.ico")))

global EMOJIFONT
try:
EMOJIFONT = setup_font("NotoEmoji-Medium.ttf")
except Exception as ex:
logging.error(f"Could not load emoji font, falling back to system default! Error: {ex}")

window = MainWindow()
window.show()
sys.exit(app.exec_())


def setup_font(name):
font_id = QtGui.QFontDatabase.addApplicationFont(resource_file(name))
if font_id != -1:
loaded_font_families = QtGui.QFontDatabase.applicationFontFamilies(font_id)
if loaded_font_families:
return loaded_font_families[0]
else:
raise Exception(f"Failed to find font after adding to database: {name}")
else:
raise Exception(f"Failed adding font to database: {name}")


def set_emoji_font(widget, size):
global EMOJIFONT
if EMOJIFONT:
widget.setFont(QtGui.QFont(EMOJIFONT, size))
else:
font = widget.font()
font.setPointSize(size)
widget.setFont(font)


def resource_file(name):
basedir = os.path.dirname(__file__)
return os.path.join(basedir, 'appresource', name)
Expand All @@ -37,7 +71,7 @@ def __init__(self):

# Set up the main window
self.setWindowTitle(f"Arduboy Toolset v{constants.VERSION}")
self.setGeometry(100, 100, 400, 300) # Set a reasonable window size
self.setGeometry(100, 100, 600, 500) # Set a reasonable window size

# Create a vertical layout
layout = QVBoxLayout()
Expand All @@ -62,13 +96,52 @@ def __init__(self):
class ConnectionInfo(QWidget):
def __init__(self):
super().__init__()
self.timer = QTimer(self)
self.timer.timeout.connect(self.refresh)
self.do_updates = True
self.update_count = 0

layout = QHBoxLayout()

label = QLabel("Label")
layout.addWidget(label)
self.status_picture = QLabel("$")
set_emoji_font(self.status_picture, 24)
layout.addWidget(self.status_picture)

self.setLayout(layout)
self.status_label = QLabel("Label")
font = self.status_label.font() # Get the current font of the label
font.setPointSize(16) # Set the font size to 16 points
self.status_label.setFont(font)
layout.addWidget(self.status_label)

layout.setStretchFactor(self.status_picture, 0)
layout.setStretchFactor(self.status_label, 1)

self.setLayout(layout)
# self.setObjectName("coninfo");
# self.setStyleSheet('#coninfo { border: 2px solid rgba(128, 128, 128, 0.5); padding: 15px; border-radius: 7px; }')
# Set transparent border with alpha
self.refresh()
self.timer.start(1000)

def stop_updates(self):
self.do_updates = False

def start_updates(self):
self.do_updates = True

def refresh(self):
if self.do_updates:
self.update_count += 1
palette = self.status_picture.palette()
try:
device = arduboy.device.find_single(enter_bootloader=False)
self.status_label.setText("Connected!")
self.status_picture.setText("✅")
self.status_picture.setStyleSheet("color: #30c249")
except:
self.status_label.setText("Searching for Arduboy" + "." * ((self.update_count % 3) + 1))
self.status_picture.setText("⏳")
self.status_picture.setStyleSheet("color: rgba(128,128,128,0.5)")

# The table of actions which can be performed. Has functions to enable/disable parts of itself
# based on common external interactions
Expand Down

0 comments on commit 0991b95

Please sign in to comment.