Skip to content

Commit

Permalink
Fix camflasher problem with executable
Browse files Browse the repository at this point in the history
  • Loading branch information
remibert committed Feb 26, 2022
1 parent fa44a8d commit ce1a155
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
3 changes: 2 additions & 1 deletion tools/camflasher/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
/dist
/build
/*.spec
/__pycache__
/__pycache__
*.ini
1 change: 1 addition & 0 deletions tools/camflasher/flasher.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def on_write_file(self, command, directory):

for filename in filenames:
file_writer = FileWriter()
filename = filename.replace("\\","/")
filename_ = filename.replace(directory, "")
if file_writer.write(filename, self.serial, self.serial, directory) is True:
self.print(" %s\n"%filename_)
Expand Down
43 changes: 30 additions & 13 deletions tools/camflasher/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import sys
import os.path
import os
from platform import uname
try:
from PyQt6 import uic
from PyQt6.QtCore import QTimer, QEvent, Qt, QSettings
Expand All @@ -29,6 +30,7 @@
from qstdoutvt100 import QStdoutVT100

# Settings
SETTINGS_FILENAME = "CamFlasher.ini"
FONT_FAMILY = "camflasher.font.family"
FONT_SIZE = "camflasher.font.size"
WORKING_DIRECTORY = "camflasher.working_directory"
Expand All @@ -51,6 +53,19 @@ def accept(self):
""" Accept about dialog """
self.close()

def get_settings():
""" Return the QSettings class according to the os """
if sys.platform == "darwin":
result = QSettings()
elif sys.platform == "win32":
if uname() == "7":
result = QSettings(SETTINGS_FILENAME, QSettings.IniFormat)
else:
result = QSettings(SETTINGS_FILENAME)
else:
result = QSettings()#QSettings("."+SETTINGS_FILENAME, QSettings.IniFormat)
return result

class FlashDialog(QDialog):
""" Dialog box to select firmware """
def __init__(self, parent):
Expand All @@ -62,7 +77,7 @@ def __init__(self, parent):
from dialogflash import Ui_DialogFlash
self.dialog = Ui_DialogFlash()
self.dialog.setupUi(self)
settings = QSettings()
settings = get_settings()
firmware = settings.value(FIRMWARE_FILENAME, "")
if not os.path.exists(firmware):
firmware = ""
Expand All @@ -84,7 +99,7 @@ def accept(self):
msg.setText("Firmware not found")
msg.exec()
else:
settings = QSettings()
settings = get_settings()
settings.setValue(FIRMWARE_FILENAME, self.dialog.firmware.text())
super().accept()

Expand All @@ -106,23 +121,23 @@ def __init__(self, parent):
self.dialog = Ui_DialogOption()
self.dialog.setupUi(self)

settings = QSettings()
settings = get_settings()
self.dialog.working_directory.setText(settings.value(WORKING_DIRECTORY,"."))
self.dialog.spin_font_size.setValue(settings.value(FONT_SIZE ,12))
self.dialog.spin_font_size.setValue(int(settings.value(FONT_SIZE ,12)))
self.dialog.combo_font.setCurrentFont(QFont(settings.value(FONT_FAMILY ,"Courier")))
self.dialog.select_directory.clicked.connect(self.on_directory_clicked)

def on_directory_clicked(self, event):
""" Selection of directory button clicked """
settings = QSettings()
settings = get_settings()
directory = QFileDialog.getExistingDirectory(self, 'Select working directory', directory =settings.value(WORKING_DIRECTORY,"."))
if directory != '':
self.dialog.working_directory.setText(directory)

def accept(self):
""" Accept about dialog """
font = self.dialog.combo_font.currentFont()
settings = QSettings()
settings = get_settings()
settings.setValue(FONT_FAMILY , font.family())
settings.setValue(FONT_SIZE , self.dialog.spin_font_size.value())
settings.setValue(WORKING_DIRECTORY, self.dialog.working_directory.text())
Expand All @@ -136,15 +151,17 @@ def __init__(self):
self.stdout = sys.stdout
try:
self.window = uic.loadUi('camflasher.ui', self)
self.geometry_ = self.window
except Exception as err:
from camflasher import Ui_CamFlasher
self.window = Ui_CamFlasher()
self.window.setupUi(self)
self.geometry_ = self

# Select font
self.update_font()
settings = QSettings()
self.window.setGeometry(settings.value(WIN_GEOMETRY, self.window.geometry()))
settings = get_settings()
self.geometry_.setGeometry(settings.value(WIN_GEOMETRY, self.geometry_.geometry()))

self.window.output.setAcceptDrops(False)
self.window.output.setReadOnly(True)
Expand Down Expand Up @@ -195,10 +212,10 @@ def __init__(self):

def update_font(self):
""" Update console font """
settings = QSettings()
settings = get_settings()
font = QFont()
font.setFamily (settings.value(FONT_FAMILY ,"Courier"))
font.setPointSize (settings.value(FONT_SIZE ,12))
font.setPointSize (int(settings.value(FONT_SIZE ,12)))
self.window.output.setFont(font)

def on_about_clicked(self):
Expand Down Expand Up @@ -277,8 +294,8 @@ def eventFilter(self, obj, event):
def resize_console(self):
""" Resize console """
# Save the position
settings = QSettings()
geometry = self.window.geometry()
settings = get_settings()
geometry = self.geometry_.geometry()
settings.setValue(WIN_GEOMETRY, geometry)

# Calculate the dimension in pixels of a text of 200 lines with 200 characters
Expand Down Expand Up @@ -306,7 +323,7 @@ def on_option_clicked(self):
self.option_dialog.setWindowModality(Qt.WindowModality.ApplicationModal)
result = self.option_dialog.exec()
if result == 1:
settings = QSettings()
settings = get_settings()
self.flasher.set_directory(settings.value(WORKING_DIRECTORY,"."))
self.update_font()
self.resize_console()
Expand Down

0 comments on commit ce1a155

Please sign in to comment.