Skip to content

Commit b5a442f

Browse files
authored
Merge pull request #279 from nxt-dev/features/qt/pyside_6
PySide 6 Upgrade
2 parents e61b288 + 3ba049e commit b5a442f

16 files changed

+55
-87
lines changed

nxt_editor/__init__.py

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -36,48 +36,21 @@ class StringSignaler(QtCore.QObject):
3636

3737

3838
def make_resources(qrc_path=None, result_path=None):
39-
import PySide2
40-
pyside_dir = os.path.dirname(PySide2.__file__)
41-
full_pyside2rcc_path = os.path.join(pyside_dir, 'pyside2-rcc')
42-
full_rcc_path = os.path.join(pyside_dir, 'rcc')
39+
import subprocess
4340
this_dir = os.path.dirname(os.path.realpath(__file__))
4441
if not qrc_path:
4542
qrc_path = os.path.join(this_dir, 'resources/resources.qrc')
4643
if not result_path:
4744
result_path = os.path.join(this_dir, 'qresources.py')
4845
msg = 'First launch nxt resource generation from {} to {}'
4946
logger.info(msg.format(qrc_path, result_path))
50-
import subprocess
51-
ver = ['-py2']
52-
if sys.version_info[0] == 3:
53-
ver += ['-py3']
54-
args = [qrc_path] + ver + ['-o', result_path]
55-
try:
56-
subprocess.check_call(['pyside2-rcc'] + args)
57-
except:
58-
pass
59-
else:
60-
return
6147

48+
args = [qrc_path, '-o', result_path, '-g', 'python']
6249
try:
63-
subprocess.check_call([full_pyside2rcc_path] + args)
50+
subprocess.call(['pyside6-rcc'] + args)
6451
except:
65-
pass
66-
else:
67-
return
68-
try:
69-
subprocess.check_call([full_rcc_path, '-g', 'python', qrc_path,
70-
'-o', result_path], cwd=pyside_dir)
71-
except:
72-
pass
73-
else:
74-
return
75-
try:
76-
subprocess.check_call(['rcc', '-g', 'python', qrc_path,
77-
'-o', result_path], cwd=pyside_dir)
78-
except:
79-
raise Exception("Failed to generate UI resources using pyside2 rcc!"
80-
" Reinstalling pyside2 may fix the problem. If you "
52+
raise Exception("Failed to generate UI resources using PySide rcc!"
53+
" Reinstalling PySide6 may fix the problem. If you "
8154
"know how to use rcc please build from: \"{}\" and "
8255
"output to \"{}\"".format(qrc_path, result_path))
8356
else:
@@ -129,9 +102,12 @@ def launch_editor(paths=None, start_rpc=True):
129102

130103
def show_new_editor(paths=None, start_rpc=True):
131104
path = None
132-
if paths is not None:
105+
if paths and isinstance(paths, list):
133106
path = paths[0]
134107
paths.pop(0)
108+
elif isinstance(paths, str):
109+
path = paths
110+
paths = []
135111
else:
136112
paths = []
137113
# Deferred import since main window relies on us

nxt_editor/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class EDITOR_VERSION(object):
2222

2323

2424
class FONTS(object):
25-
DEFAULT_FAMILY = 'RobotoMono-Regular'
25+
DEFAULT_FAMILY = 'Roboto Mono'
2626
DEFAULT_SIZE = 10
2727

2828

nxt_editor/dialogs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def build_widgets(self):
297297
self.save_details_button.released.connect(self.on_save_details)
298298

299299
self.detail_buttons_layout = QtWidgets.QHBoxLayout()
300-
self.detail_buttons_layout.addStretch(streth=1)
300+
self.detail_buttons_layout.addStretch(1)
301301
self.detail_buttons_layout.addWidget(self.save_details_button)
302302
self.detail_buttons_layout.addWidget(self.copy_details_button)
303303

@@ -314,7 +314,7 @@ def build_widgets(self):
314314
self.top_right_layout = QtWidgets.QVBoxLayout()
315315
self.top_right_layout.addWidget(self.text_label)
316316
self.top_right_layout.addWidget(self.info_label)
317-
self.top_right_layout.addStretch(streth=1)
317+
self.top_right_layout.addStretch(1)
318318
self.top_right_layout.addLayout(self.buttons_layout)
319319
self.top_layout = QtWidgets.QHBoxLayout()
320320
self.top_layout.addWidget(self.icon)

nxt_editor/dockwidgets/build_view.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ class BuildTable(QtWidgets.QTableView):
315315
"""
316316
def __init__(self):
317317
super(BuildTable, self).__init__()
318-
self.setSelectionMode(self.NoSelection)
318+
self.setSelectionMode(QtWidgets.QAbstractItemView.NoSelection)
319319
self.horizontalHeader().hide()
320320
self.verticalHeader().hide()
321321
self.break_delegate = LetterCheckboxDelegeate('B')
@@ -342,7 +342,7 @@ def setModel(self, model):
342342
header = self.horizontalHeader()
343343
header.setStretchLastSection(False)
344344
header.setDefaultSectionSize(28)
345-
header.setSectionResizeMode(header.Fixed)
345+
header.setSectionResizeMode(QtWidgets.QHeaderView.Fixed)
346346
if header.count():
347347
column = BuildModel.PATH_COLUMN
348348
header.setSectionResizeMode(column, QtWidgets.QHeaderView.Stretch)

nxt_editor/dockwidgets/code_editor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,7 @@ def paintEvent(self, event):
12711271

12721272
def get_width(self):
12731273
count = self.editor.blockCount()
1274-
width = self.fontMetrics().width(str(count)) + 10
1274+
width = self.fontMetrics().horizontalAdvance(str(count)) + 10
12751275
return width
12761276

12771277
def update_width(self):

nxt_editor/dockwidgets/find_rep.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def setModel(self, model):
196196
super(SearchResultsTree, self).setModel(model)
197197
header = self.header()
198198
header.setStretchLastSection(False)
199-
header.setSectionResizeMode(header.ResizeToContents)
199+
header.setSectionResizeMode(QtWidgets.QHeaderView.ResizeToContents)
200200
if self.model():
201201
self.model().modelReset.connect(self.expandAll)
202202

nxt_editor/dockwidgets/layer_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def setModel(self, model):
100100
header = self.header()
101101
header.setStretchLastSection(False)
102102
header.setDefaultSectionSize(LayerTreeView.SIZE)
103-
header.setSectionResizeMode(header.Fixed)
103+
header.setSectionResizeMode(QtWidgets.QHeaderView.Fixed)
104104
if header.count():
105105
header.setSectionResizeMode(0, QtWidgets.QHeaderView.Stretch)
106106
self.hideColumn(LayerModel.TARGET_COLUMN)

nxt_editor/dockwidgets/output_log.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def __init__(self, graph_model=None, parent=None):
205205

206206
self.buttons_layout = QtWidgets.QHBoxLayout()
207207
self.buttons_layout.addWidget(self.log_filter_button)
208-
self.buttons_layout.addStretch(stretch=1)
208+
self.buttons_layout.addStretch(1)
209209
self.buttons_layout.addWidget(self.clear_rich_button)
210210

211211
self.rich_output_layout = QtWidgets.QVBoxLayout()

nxt_editor/dockwidgets/property_editor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
QtCore.QStringListModel
1313
except AttributeError:
1414
del QtCore
15-
from PySide2 import QtCore
15+
from PySide6 import QtCore
1616

1717
# Internal
1818
from nxt_editor import user_dir

nxt_editor/dockwidgets/syntax.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ class PythonHighlighter(QSyntaxHighlighter):
3939
# Comparison
4040
'==', '!=', '<', '<=', '>', '>=',
4141
# Arithmetic
42-
'\+', '-', '\*', '/', '//', '\%', '\*\*',
42+
r'\+', '-', r'\*', '/', '//', r'\%', r'\*\*',
4343
# In-place
44-
'\+=', '-=', '\*=', '/=', '\%=',
44+
r'\+=', '-=', r'\*=', '/=', r'\%=',
4545
# Bitwise
46-
'\^', '\|', '\&', '\~', '>>', '<<'
46+
r'\^', r'\|', r'\&', r'\~', '>>', '<<'
4747
]
4848

4949
# Python braces
50-
braces = ['\{', '\}', '\(', '\)', '\[', '\]']
50+
braces = [r'\{', r'\}', r'\(', r'\)', r'\[', r'\]']
5151

5252
def __init__(self, document=None):
5353
super(PythonHighlighter, self).__init__(document)
@@ -117,7 +117,8 @@ def highlightBlock(self, text):
117117
# Do other syntax formatting
118118
for rule in self.rules:
119119
expression, nth, formatting = rule
120-
index = expression.indexIn(text, 0)
120+
match = expression.match(text)
121+
index = match.capturedStart()
121122
# This is here because you can't do nested logic in regex
122123
nested = 0
123124
if rule in self.special_rules:
@@ -126,10 +127,10 @@ def highlightBlock(self, text):
126127

127128
while index >= 0:
128129
# We actually want the index of the nth match
129-
index = expression.pos(nth)
130-
length = len(expression.cap(nth))
130+
index = match.capturedStart(nth)
131+
length = len(match.captured(nth))
131132
self.setFormat(index, length + nested, formatting)
132-
index = expression.indexIn(text, index + length)
133+
index = match.capturedStart(text)
133134

134135
self.setCurrentBlockState(0)
135136

@@ -151,17 +152,19 @@ def match_multiline(self, text, delimiter, in_state, style):
151152
add = 0
152153
# Otherwise, look for the delimiter on this line
153154
else:
154-
start = delimiter.indexIn(text)
155+
match = delimiter.match(text)
156+
start = match.capturedStart()
155157
# Move past this match
156-
add = delimiter.matchedLength()
158+
add = match.capturedLength()
157159

158160
# As long as there's a delimiter match on this line...
159161
while start >= 0:
162+
match = delimiter.match(text)
160163
# Look for the ending delimiter
161-
end = delimiter.indexIn(text, start + add)
164+
end = match.capturedStart() + (start + add)
162165
# Ending delimiter on this line?
163166
if end >= add:
164-
length = end - start + add + delimiter.matchedLength()
167+
length = end - start + add + match.capturedLength()
165168
self.setCurrentBlockState(0)
166169
# No; multi-line string
167170
else:
@@ -170,7 +173,7 @@ def match_multiline(self, text, delimiter, in_state, style):
170173
# Apply formatting
171174
self.setFormat(start, length, style)
172175
# Look for the next match
173-
start = delimiter.indexIn(text, start + length)
176+
start = match.capturedStart() + (start + length)
174177

175178
# Return True if still inside a multi-line string, False otherwise
176179
if self.currentBlockState() == in_state:

0 commit comments

Comments
 (0)