mtkclient/mtk_gui

512 lines
22 KiB
Text
Raw Normal View History

2021-12-25 17:01:25 -05:00
#!/usr/bin/env python3
2022-01-01 12:46:52 -05:00
# MTK Flash Client (c) B.Kerler, G.Kreileman 2021.
2021-12-25 17:01:25 -05:00
# Licensed under GPLv3 License
import sys
import time
import mock
import traceback
import math
import logging
import ctypes
2022-01-01 12:46:52 -05:00
from functools import partial
from PySide6.QtCore import Qt, QVariantAnimation, Signal, QObject, QSize, QTranslator, QLocale, QLibraryInfo, \
Slot, QCoreApplication
2021-12-31 07:00:23 -05:00
from PySide6.QtGui import QTextOption, QPixmap, QTransform, QIcon, QAction
2022-01-01 12:46:52 -05:00
from PySide6.QtWidgets import QMainWindow, QApplication, QWidget, QCheckBox, QVBoxLayout, QHBoxLayout, QLineEdit, \
QPushButton
2021-12-25 17:01:25 -05:00
from mtkclient.Library.mtk import Mtk
from mtkclient.Library.mtk_da_cmd import DA_handler
2021-12-25 17:01:25 -05:00
from mtkclient.Library.gpt import gpt_settings
from mtkclient.Library.mtk_main import Main, Mtk_Config
from mtkclient.gui.readFlashPartitions import ReadFlashWindow
2021-12-30 14:41:25 -05:00
from mtkclient.gui.writeFlashPartitions import WriteFlashWindow
from mtkclient.gui.eraseFlashPartitions import EraseFlashWindow
from mtkclient.gui.toolsMenu import generateKeysMenu
2022-01-01 12:46:52 -05:00
from mtkclient.gui.toolkit import asyncThread, trap_exc_during_debug, convert_size, CheckBox, FDialog, TimeEstim
2021-12-25 17:01:25 -05:00
from mtkclient.config.payloads import pathconfig
from mtkclient.gui.main_gui import Ui_MainWindow
import os
2022-01-01 12:46:52 -05:00
os.environ['QT_MAC_WANTS_LAYER'] = '1' # This fixes a bug in pyside2 on MacOS Big Sur
2021-12-25 17:01:25 -05:00
# TO do Move all GUI modifications to signals!
# install exception hook: without this, uncaught exception would cause application to exit
sys.excepthook = trap_exc_during_debug
# Initiate MTK classes
variables = mock.Mock()
variables.cmd = "stage"
variables.debugmode = True
2022-01-01 12:46:52 -05:00
path = pathconfig()
2021-12-25 17:01:25 -05:00
# if sys.platform.startswith('darwin'):
# config.ptype = "kamakiri" #Temp for Mac testing
MtkTool = Main(variables)
guiState = "welcome"
phoneInfo = {"chipset": "", "bootMode": "", "daInit": False, "cdcInit": False}
2022-01-01 12:46:52 -05:00
class DeviceHandler(QObject):
sendToLogSignal = Signal(str)
2021-12-30 14:41:25 -05:00
sendToProgressSignal = Signal(int)
mtkClass = None
da_handler = None
def __init__(self, parent, preloader: str = None, loglevel=logging.INFO, *args, **kwargs):
super().__init__(parent, *args, **kwargs)
2021-12-30 14:41:25 -05:00
config = Mtk_Config(loglevel=logging.INFO, gui=self.sendToLogSignal, guiprogress=self.sendToProgressSignal)
config.gpt_settings = gpt_settings(gpt_num_part_entries='0', gpt_part_entry_size='0',
gpt_part_entry_start_lba='0') # This actually sets the right GPT settings..
self.mtkClass = Mtk(config=config, loglevel=logging.INFO)
self.loglevel = logging.DEBUG
self.da_handler = DA_handler(self.mtkClass, loglevel)
2021-12-25 17:01:25 -05:00
2022-01-01 12:46:52 -05:00
2021-12-25 17:01:25 -05:00
def getDevInfo(self, parameters):
loglevel = parameters[0]
phoneInfo = parameters[1]
devhandler = parameters[2]
mtkClass = devhandler.mtkClass
da_handler = devhandler.da_handler
try:
2021-12-29 18:17:55 -05:00
if not mtkClass.port.cdc.connect():
mtkClass.preloader.init()
else:
phoneInfo['cdcInit'] = True
except:
phoneInfo['cantConnect'] = True
phoneInfo['chipset'] = str(mtkClass.config.chipconfig.name) + \
" (" + str(mtkClass.config.chipconfig.description) + ")"
self.sendUpdateSignal.emit()
2021-12-25 17:01:25 -05:00
mtkClass = da_handler.configure_da(mtkClass, preloader=None)
if mtkClass:
phoneInfo['daInit'] = True
phoneInfo['chipset'] = str(mtkClass.config.chipconfig.name) + \
" (" + str(mtkClass.config.chipconfig.description) + ")"
if mtkClass.config.is_brom:
phoneInfo['bootMode'] = "Bootrom mode"
elif mtkClass.config.chipconfig.damode:
phoneInfo['bootMode'] = "DA mode"
else:
phoneInfo['bootMode'] = "Preloader mode"
self.sendUpdateSignal.emit()
else:
phoneInfo['cantConnect'] = True
self.sendUpdateSignal.emit()
2021-12-25 17:01:25 -05:00
2021-12-29 09:31:56 -05:00
def load_translations(application):
2022-01-01 12:46:52 -05:00
# Load application translations and the QT base translations for the current locale
2021-12-29 09:31:56 -05:00
locale = QLocale.system()
translator = QTranslator(application)
directory = os.path.dirname(__file__)
lang = 'mtkclient/gui/i18n/' + locale.name()
2022-01-01 12:46:52 -05:00
# lang = 'mtkclient/gui/i18n/fr_FR'
# lang = 'mtkclient/gui/i18n/de_DE'
# lang = 'mtkclient/gui/i18n/en_GB'
# lang = 'mtkclient/gui/i18n/es_ES'
2021-12-29 09:31:56 -05:00
if translator.load(lang, directory):
application.installTranslator(translator)
translations_path = QLibraryInfo.location(QLibraryInfo.TranslationsPath)
base_translator = QTranslator(application)
if base_translator.load(locale, "qtbase", "_", translations_path):
application.installTranslator(base_translator)
2021-12-29 10:08:38 -05:00
2021-12-29 18:17:55 -05:00
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
2022-01-01 12:46:52 -05:00
self.ui = Ui_MainWindow()
2021-12-29 18:17:55 -05:00
self.ui.setupUi(self)
2022-01-01 12:46:52 -05:00
self.fdialog = FDialog(self)
2021-12-29 18:17:55 -05:00
self.initpixmap()
2022-01-01 12:46:52 -05:00
self.Status={}
self.timeEst = TimeEstim()
self.timeEstTotal = TimeEstim()
2021-12-29 18:17:55 -05:00
self.ui.logBox.setWordWrapMode(QTextOption.NoWrap)
self.ui.menubar.setEnabled(False)
2022-01-01 12:46:52 -05:00
self.devhandler = None
self.readflash = None
@Slot()
def updateState(self):
totalBytes = 0
doneBytes = 0
if "allPartitions" in self.Status:
for partition in self.Status["allPartitions"]:
totalBytes = totalBytes + self.Status["allPartitions"][partition]['size']
if (self.Status["allPartitions"][partition]['done'] and partition != self.Status[
"currentPartition"]):
doneBytes = doneBytes + self.Status["allPartitions"][partition]['size']
else:
totalBytes = self.Status["currentPartitionSize"]
doneBytes = doneBytes + self.Status["currentPartitionSizeDone"]
percentageDone = (self.Status["currentPartitionSizeDone"] / self.Status["currentPartitionSize"]) * 100
fullPercentageDone = (doneBytes / totalBytes) * 100
self.ui.partProgress.setValue(percentageDone)
timeinfo = self.timeEst.update(doneBytes, totalBytes)
txt="Current partition: " + self.Status["currentPartition"] + " (" + \
convert_size(self.Status["currentPartitionSizeDone"]) + " / " + \
convert_size(self.Status["currentPartitionSize"])+") "+ \
timeinfo+QCoreApplication.translate("main"," left")
self.ui.partProgressText.setText(txt)
self.ui.fullProgress.setValue(fullPercentageDone)
timeinfototal = self.timeEstTotal.update(fullPercentageDone, 100)
self.ui.fullProgressText.setText("Total: (" + convert_size(doneBytes) + " / " + convert_size(totalBytes)+") "+
timeinfototal + QCoreApplication.translate("main"," left"))
def updateStateAsync(self, toolkit, parameters):
while not self.Status["done"]:
# print(self.dumpStatus)
time.sleep(0.1)
print("DONE")
self.ui.readpreloaderbtn.setEnabled(True)
self.ui.readpartitionsbtn.setEnabled(True)
self.ui.readboot2btn.setEnabled(True)
self.ui.readrpmbbtn.setEnabled(True)
self.ui.readflashbtn.setEnabled(True)
self.ui.writepartbtn.setEnabled(True)
self.ui.writeflashbtn.setEnabled(True)
self.ui.writeboot2btn.setEnabled(True)
self.ui.writepreloaderbtn.setEnabled(True)
self.ui.writerpmbbtn.setEnabled(True)
self.ui.erasepartitionsbtn.setEnabled(True)
self.ui.eraseboot2btn.setEnabled(True)
self.ui.erasepreloaderbtn.setEnabled(True)
self.ui.eraserpmbbtn.setEnabled(True)
@Slot(int)
def updateProgress(self, progress):
self.Status["currentPartitionSizeDone"] = progress
self.updateState()
def setdevhandler(self, devhandler):
self.devhandler = devhandler
devhandler.sendToProgressSignal.connect(self.updateProgress)
def initread(self):
self.readflash=ReadFlashWindow(self.ui, self, self.devhandler, self.devhandler.da_handler, self.sendToLog)
self.ui.readpartitionsbtn.clicked.connect(self.readflash.dumpPartition)
self.ui.readselectallcheckbox.clicked.connect(self.readflash.selectAll)
self.ui.readpreloaderbtn.clicked.connect(self.on_readpreloader)
self.ui.readflashbtn.clicked.connect(self.on_readfullflash)
self.ui.readrpmbbtn.clicked.connect(self.on_readrpmb)
self.ui.readboot2btn.clicked.connect(self.on_readboot2)
def initkeys(self):
self.genkeys = generateKeysMenu(self.ui, self, self.devhandler, self.devhandler.da_handler, self.sendToLog)
self.ui.generatekeybtn.clicked.connect(self.on_generatekeys)
def initerase(self):
self.eraseflash = EraseFlashWindow(self.ui, self, self.devhandler, self.devhandler.da_handler, self.sendToLog)
self.ui.eraseselectallpartitionscheckbox.clicked.connect(self.eraseflash.selectAll)
self.ui.erasepartitionsbtn.clicked.connect(self.on_erasepartflash)
self.ui.eraserpmbbtn.clicked.connect(self.on_eraserpmb)
self.ui.erasepreloaderbtn.clicked.connect(self.on_erasepreloader)
self.ui.eraseboot2btn.clicked.connect(self.on_eraseboot2)
def initwrite(self):
self.writeflash = WriteFlashWindow(self.ui, self, self.devhandler, self.devhandler.da_handler, self.sendToLog)
self.ui.writeselectfromdir.clicked.connect(self.writeflash.selectFiles)
self.ui.writeflashbtn.clicked.connect(self.on_writefullflash)
self.ui.writepartbtn.clicked.connect(self.on_writepartflash)
self.ui.writeboot2btn.clicked.connect(self.on_writeboot2)
self.ui.writepreloaderbtn.clicked.connect(self.on_writepreloader)
self.ui.writerpmbbtn.clicked.connect(self.on_writerpmb)
def disablebuttons(self):
self.ui.readpreloaderbtn.setEnabled(False)
self.ui.readpartitionsbtn.setEnabled(False)
self.ui.readboot2btn.setEnabled(False)
self.ui.readrpmbbtn.setEnabled(False)
self.ui.readflashbtn.setEnabled(False)
self.ui.writeflashbtn.setEnabled(False)
self.ui.writepartbtn.setEnabled(False)
self.ui.writepreloaderbtn.setEnabled(False)
self.ui.writeboot2btn.setEnabled(False)
self.ui.writerpmbbtn.setEnabled(False)
self.ui.eraseboot2btn.setEnabled(False)
self.ui.erasepreloaderbtn.setEnabled(False)
self.ui.eraserpmbbtn.setEnabled(False)
def enablebuttons(self):
self.ui.readpreloaderbtn.setEnabled(True)
self.ui.readpartitionsbtn.setEnabled(True)
self.ui.readboot2btn.setEnabled(True)
self.ui.readrpmbbtn.setEnabled(True)
self.ui.readflashbtn.setEnabled(True)
self.ui.writeflashbtn.setEnabled(True)
self.ui.writepartbtn.setEnabled(True)
self.ui.writepreloaderbtn.setEnabled(True)
self.ui.writeboot2btn.setEnabled(True)
self.ui.writerpmbbtn.setEnabled(True)
self.ui.eraseboot2btn.setEnabled(True)
self.ui.erasepreloaderbtn.setEnabled(True)
self.ui.eraserpmbbtn.setEnabled(True)
def getpartitions(self):
data, guid_gpt = self.devhandler.mtkClass.daloader.get_gpt()
if guid_gpt is None:
print("Error reading gpt")
self.ui.readtitle.setText(QCoreApplication.translate("main","Error reading gpt"))
else:
self.ui.readtitle.setText(QCoreApplication.translate("main","Select partitions to dump"))
readpartitionListWidgetVBox = QVBoxLayout()
readpartitionListWidget = QWidget(self)
readpartitionListWidget.setLayout(readpartitionListWidgetVBox)
self.ui.readpartitionList.setWidget(readpartitionListWidget)
self.ui.readpartitionList.setWidgetResizable(True)
#self.ui.readpartitionList.setGeometry(10,40,380,320)
self.ui.readpartitionList.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
self.ui.readpartitionList.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.readpartitionCheckboxes = {}
for partition in guid_gpt.partentries:
self.readpartitionCheckboxes[partition.name] = {}
self.readpartitionCheckboxes[partition.name]['size'] = (partition.sectors * guid_gpt.sectorsize)
self.readpartitionCheckboxes[partition.name]['box'] = QCheckBox()
self.readpartitionCheckboxes[partition.name]['box'].setText(partition.name + " (" +
convert_size(
partition.sectors * guid_gpt.sectorsize) + ")")
readpartitionListWidgetVBox.addWidget(self.readpartitionCheckboxes[partition.name]['box'])
writepartitionListWidgetVBox = QVBoxLayout()
writepartitionListWidget = QWidget(self)
writepartitionListWidget.setLayout(writepartitionListWidgetVBox)
self.ui.writepartitionList.setWidget(writepartitionListWidget)
self.ui.writepartitionList.setWidgetResizable(True)
#self.ui.writepartitionList.setGeometry(10,40,380,320)
self.ui.writepartitionList.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
self.ui.writepartitionList.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.writepartitionCheckboxes = {}
for partition in guid_gpt.partentries:
self.writepartitionCheckboxes[partition.name] = {}
self.writepartitionCheckboxes[partition.name]['size'] = (partition.sectors * guid_gpt.sectorsize)
vb = QVBoxLayout()
qc=CheckBox()
qc.setReadOnly(True)
qc.setText(partition.name + " (" + convert_size(partition.sectors * guid_gpt.sectorsize) + ")")
hc=QHBoxLayout()
ll=QLineEdit()
lb=QPushButton(QCoreApplication.translate("main","Set"))
lb.clicked.connect(partial(self.selectWriteFile,partition.name,qc,ll))
hc.addWidget(ll)
hc.addWidget(lb)
vb.addWidget(qc)
vb.addLayout(hc)
ll.setDisabled(True)
self.writepartitionCheckboxes[partition.name]['box'] = [qc,ll,lb]
writepartitionListWidgetVBox.addLayout(vb)
erasepartitionListWidgetVBox = QVBoxLayout()
erasepartitionListWidget = QWidget(self)
erasepartitionListWidget.setLayout(erasepartitionListWidgetVBox)
self.ui.erasepartitionList.setWidget(erasepartitionListWidget)
self.ui.erasepartitionList.setWidgetResizable(True)
#self.ui.erasepartitionList.setGeometry(10,40,380,320)
self.ui.erasepartitionList.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
self.ui.erasepartitionList.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.erasepartitionCheckboxes = {}
for partition in guid_gpt.partentries:
self.erasepartitionCheckboxes[partition.name] = {}
self.erasepartitionCheckboxes[partition.name]['size'] = (partition.sectors * guid_gpt.sectorsize)
self.erasepartitionCheckboxes[partition.name]['box'] = QCheckBox()
self.erasepartitionCheckboxes[partition.name]['box'].setText(partition.name + " (" +
convert_size(partition.sectors * guid_gpt.sectorsize)+")")
erasepartitionListWidgetVBox.addWidget(self.erasepartitionCheckboxes[partition.name]['box'])
def selectWriteFile(self, partition, checkbox, lineedit):
fname=self.fdialog.open(partition+".img")
if fname is None:
checkbox.setChecked(False)
lineedit.setText("")
lineedit.setDisabled(True)
return ""
checkbox.setChecked(True)
lineedit.setText(fname)
lineedit.setDisabled(False)
return fname
2021-12-30 04:47:08 -05:00
def on_writefullflash(self):
2022-01-01 12:46:52 -05:00
self.writeflash.writeFlash("user")
2021-12-30 14:41:25 -05:00
return
def on_writepreloader(self):
2022-01-01 12:46:52 -05:00
self.writeflash.writeFlash("boot1")
2021-12-30 14:41:25 -05:00
return
def on_writeboot2(self):
2022-01-01 12:46:52 -05:00
self.writeflash.writeFlash("boot2")
2021-12-30 04:47:08 -05:00
return
2022-01-01 12:46:52 -05:00
def on_writerpmb(self):
self.writeflash.writeFlash("rpmb")
2021-12-30 04:47:08 -05:00
return
2022-01-01 12:46:52 -05:00
def on_writepartflash(self):
self.writeflash.writePartition()
2021-12-30 04:47:08 -05:00
return
2022-01-01 12:46:52 -05:00
def on_erasepartflash(self):
self.eraseflash.erasePartition()
2021-12-30 04:47:08 -05:00
return
2022-01-01 12:46:52 -05:00
def on_eraseboot2(self):
self.eraseflash.eraseBoot2()
2021-12-30 14:41:25 -05:00
2022-01-01 12:46:52 -05:00
def on_erasepreloader(self):
self.eraseflash.erasePreloader()
2021-12-30 04:47:08 -05:00
2022-01-01 12:46:52 -05:00
def on_eraserpmb(self):
self.eraseflash.eraseRpmb()
2021-12-30 04:47:08 -05:00
def on_generatekeys(self):
2022-01-01 12:46:52 -05:00
self.genkeys.generateKeys()
2021-12-30 04:47:08 -05:00
return
def on_readpreloader(self):
2022-01-01 12:46:52 -05:00
self.readflash.dumpFlash("boot1")
2021-12-30 08:12:45 -05:00
return
def on_readboot2(self):
2022-01-01 12:46:52 -05:00
self.readflash.dumpFlash("boot2")
2021-12-30 04:47:08 -05:00
return
def on_readfullflash(self):
2022-01-01 12:46:52 -05:00
self.readflash.dumpFlash("user")
def on_readrpmb(self):
self.readflash.dumpFlash("rpmb")
return
2021-12-30 04:47:08 -05:00
2021-12-29 18:17:55 -05:00
def sendToLog(self, info):
t = time.localtime()
self.ui.logBox.appendPlainText(time.strftime("[%H:%M:%S", t) + "]: " + info)
self.ui.logBox.verticalScrollBar().setValue(self.ui.logBox.verticalScrollBar().maximum())
2021-12-30 14:41:25 -05:00
def sendToProgress(self, progress):
return
2021-12-29 18:17:55 -05:00
def updateGui(self):
global phoneInfo
if phoneInfo['cdcInit'] and phoneInfo['bootMode'] == "":
2022-01-01 12:46:52 -05:00
self.ui.phoneInfoTextbox.setText(QCoreApplication.translate("main","Phone detected:\nReading model info..."))
2021-12-29 18:17:55 -05:00
else:
2022-01-01 12:46:52 -05:00
self.ui.phoneInfoTextbox.setText(QCoreApplication.translate("main",
"Phone detected:\n" + phoneInfo['chipset'] + "\n" + phoneInfo['bootMode']))
self.ui.status.setText(QCoreApplication.translate("main","Device detected, please wait.\nThis can take a while..."))
2021-12-29 18:17:55 -05:00
if phoneInfo['daInit']:
2022-01-01 12:46:52 -05:00
self.ui.status.setText(QCoreApplication.translate("main","Device connected :)"))
2021-12-29 18:17:55 -05:00
self.ui.menubar.setEnabled(True)
self.pixmap = QPixmap(path.get_images_path("phone_connected.png"))
self.ui.pic.setPixmap(self.pixmap)
self.spinnerAnim.stop()
self.ui.spinner_pic.setHidden(True)
2022-01-01 12:46:52 -05:00
self.initread()
self.initkeys()
self.initerase()
self.initwrite()
self.getpartitions()
2021-12-29 18:17:55 -05:00
else:
if 'cantConnect' in phoneInfo:
2022-01-01 12:46:52 -05:00
self.ui.status.setText(QCoreApplication.translate("main","Error initialising. Did you install the drivers?"))
2021-12-29 18:17:55 -05:00
self.spinnerAnim.start()
self.ui.spinner_pic.setHidden(False)
def spinnerAnimRot(self, angle):
trans = QTransform()
dimension = self.pixmap.width() / math.sqrt(2)
newPixmap = self.pixmap.transformed(QTransform().rotate(angle), Qt.SmoothTransformation)
2022-01-01 12:46:52 -05:00
xoffset = (newPixmap.width() - self.pixmap.width()) / 2
yoffset = (newPixmap.height() - self.pixmap.height()) / 2
2021-12-29 18:17:55 -05:00
rotated = newPixmap.copy(xoffset, yoffset, self.pixmap.width(), self.pixmap.height())
self.ui.spinner_pic.setPixmap(rotated)
def initpixmap(self):
# phone spinner
self.pixmap = QPixmap(path.get_images_path("phone_loading.png")).scaled(96, 96, Qt.KeepAspectRatio,
2022-01-01 12:46:52 -05:00
Qt.SmoothTransformation)
2021-12-29 18:17:55 -05:00
self.pixmap.setDevicePixelRatio(2)
self.ui.spinner_pic.setPixmap(self.pixmap)
self.ui.spinner_pic.show()
nfpixmap = QPixmap(path.get_images_path("phone_notfound.png"))
self.ui.pic.setPixmap(nfpixmap)
logo = QPixmap(path.get_images_path("logo_256.png"))
self.ui.logoPic.setPixmap(logo)
self.spinnerAnim = QVariantAnimation()
self.spinnerAnim.setDuration(3000)
self.spinnerAnim.setStartValue(0)
self.spinnerAnim.setEndValue(360)
self.spinnerAnim.setLoopCount(-1)
self.spinnerAnim.valueChanged.connect(self.spinnerAnimRot)
self.ui.spinner_pic.setHidden(True)
2021-12-25 17:01:25 -05:00
if __name__ == '__main__':
2021-12-29 09:31:56 -05:00
# Enable nice 4K Scaling
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True)
os.environ["QT_AUTO_SCREEN_SCALE_FACTOR"] = "1"
2021-12-25 17:01:25 -05:00
# Init the app window
app = QApplication(sys.argv)
2021-12-29 09:31:56 -05:00
load_translations(app)
2021-12-29 18:17:55 -05:00
win = MainWindow()
2021-12-25 17:01:25 -05:00
icon = QIcon()
icon.addFile(path.get_images_path('logo_32.png'), QSize(32, 32))
icon.addFile(path.get_images_path('logo_64.png'), QSize(64, 64))
icon.addFile(path.get_images_path('logo_256.png'), QSize(256, 256))
icon.addFile(path.get_images_path('logo_512.png'), QSize(512, 512))
app.setWindowIcon(icon)
win.setWindowIcon(icon)
if sys.platform.startswith('win'):
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID('MTKTools.Gui')
dpiMultiplier = win.logicalDpiX()
if dpiMultiplier == 72:
dpiMultiplier = 2
else:
dpiMultiplier = 1
addTopMargin = 20
if sys.platform.startswith('darwin'): # MacOS has the toolbar in the top bar insted of in the app...
addTopMargin = 0
win.setWindowTitle("MTKClient - Version 2.0 beta")
# lay = QVBoxLayout(self)
win.show()
2022-01-01 12:46:52 -05:00
# win.setFixedSize(746, 400 + addTopMargin)
2021-12-25 17:01:25 -05:00
# Device setup
loglevel = logging.INFO
2022-01-01 12:46:52 -05:00
devhandler = DeviceHandler(parent=app, preloader=None, loglevel=loglevel)
2021-12-29 18:17:55 -05:00
devhandler.sendToLogSignal.connect(win.sendToLog)
2021-12-25 17:01:25 -05:00
# Get the device info
2022-01-01 12:46:52 -05:00
thread = asyncThread(parent=app, n=0, function=getDevInfo, parameters=[loglevel, phoneInfo, devhandler])
2021-12-29 18:17:55 -05:00
thread.sendToLogSignal.connect(win.sendToLog)
thread.sendUpdateSignal.connect(win.updateGui)
2021-12-30 14:41:25 -05:00
thread.sendToProgressSignal.connect(win.sendToProgress)
2021-12-25 17:01:25 -05:00
thread.start()
2022-01-01 12:46:52 -05:00
win.setdevhandler(devhandler)
2021-12-25 17:01:25 -05:00
# Run loop the app
2022-01-01 12:46:52 -05:00
app.exec()
2021-12-25 17:01:25 -05:00
# Prevent thread from not being closed and call error end codes
thread.terminate()
thread.wait()