-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathpsg_ui_maker.py
54 lines (40 loc) · 1.41 KB
/
psg_ui_maker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from PySide2 import QtCore, QtGui, QtWidgets
from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtUiTools import QUiLoader
from PySide2.QtWidgets import *
from transpiler2 import *
import sys
import os
import PySimpleGUI as sg
class MyWin(QtWidgets.QMainWindow):
def __init__(self, object_name):
super().__init__(None)
# get path to files
cd = os.path.dirname(os.path.abspath(__file__))
tmp_untitled = os.path.join(cd, 'tmp_untitled.ui')
result_psg_ui = os.path.join(cd, 'result_psg.layout')
try:
# READ xml-UI into python-qt object
xml_ui_file = QFile(tmp_untitled)
xml_ui_file.open(QFile.ReadOnly)
ui = QUiLoader().load(xml_ui_file)
# convert to psg
no_bad_widgets = sys.argv[2] == '1'
psg_ui = optimize_psg_code(to_psg_element(
getattr(ui, object_name), pass_bad_widgets=no_bad_widgets))
# output psg code to file
with open(result_psg_ui, 'w', encoding='utf-8') as ff:
ff.write(psg_ui)
except Exception as e:
message = 'Error: \n' + str(e)
if '''PySide2.QtWidgets.QMainWindow' object has no attribute''' in str(e):
message = 'Error: \nElement with "object name"="' + object_name + '" not found'
# output psg code to file
with open(result_psg_ui, 'w', encoding='utf-8') as ff:
ff.write(message)
return message
if __name__ == "__main__":
qapp = QtWidgets.QApplication(sys.argv)
myqapp = MyWin(sys.argv[1])
myqapp.close()