Skip to content

Commit 452d9d8

Browse files
committed
Added PyQt6 support for Krita Next
Thanks Freya Lupen
1 parent fb5e057 commit 452d9d8

File tree

11 files changed

+138
-104
lines changed

11 files changed

+138
-104
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/__pycache__

plugindevtools/PluginDevTools/EventViewerWidget.ui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@
193193
</item>
194194
<item>
195195
<property name="text">
196-
<string>qApp.installEventFilter(self)</string>
196+
<string>QApplication.instance().installEventFilter(self)</string>
197197
</property>
198198
</item>
199199
</widget>

plugindevtools/PluginDevTools/GetKritaAPI.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@
99
import re
1010
import io
1111
import os
12-
from PyQt5.QtCore import *
13-
from PyQt5.QtGui import *
12+
try:
13+
from PyQt6.QtCore import *
14+
from PyQt6.QtGui import *
15+
except:
16+
from PyQt5.QtCore import *
17+
from PyQt5.QtGui import *
1418

1519
class GetKritaAPI(QObject):
1620

plugindevtools/PluginDevTools/PluginDevToolsWidget.py

Lines changed: 84 additions & 73 deletions
Large diffs are not rendered by default.

plugindevtools/PluginDevTools/PluginGenerator.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
from krita import *
2-
from PyQt5 import uic
2+
try:
3+
from PyQt6 import uic
4+
except:
5+
from PyQt5 import uic
36
import re
47
import os
58
import subprocess
@@ -37,7 +40,7 @@ def doneClicked(self):
3740
data={}
3841
for row in range(0,self.model.rowCount()):
3942
index = self.model.index(row,0)
40-
rec=index.data(Qt.UserRole+1)
43+
rec=index.data(Qt.ItemDataRole.UserRole+1)
4144
if rec['category'] not in data:
4245
data[rec['category']]={ 'text':rec['categoryText'], 'actions':[] }
4346
newRec={}
@@ -56,18 +59,18 @@ def newItem(self, name=None, data=None):
5659
if not data:
5760
data=self.defaultForm
5861
item = QStandardItem(name)
59-
item.setData(data, Qt.UserRole+1)
62+
item.setData(data, Qt.ItemDataRole.UserRole+1)
6063
self.model.appendRow(item)
6164
index = self.model.indexFromItem(item)
62-
self.centralWidget.listView.selectionModel().select(index, QtCore.QItemSelectionModel.ClearAndSelect)
65+
self.centralWidget.listView.selectionModel().select(index, QtCore.QItemSelectionModel.SelectionFlag.ClearAndSelect)
6366
def deleteItem(self):
6467
items = self.centralWidget.listView.selectionModel().selectedIndexes()
6568
for item in items:
6669
self.model.removeRow(item.row(),item.parent())
6770
def openItem(self, old, new):
6871
items = self.centralWidget.listView.selectionModel().selectedIndexes()
6972
for item in items:
70-
data = item.data(Qt.UserRole+1)
73+
data = item.data(Qt.ItemDataRole.UserRole+1)
7174
print ("open form", data )
7275
if data:
7376
self.loadForm(self.centralWidget, data)
@@ -78,8 +81,8 @@ def saveItem(self):
7881
self.saveForm(self.centralWidget, data)
7982
print ("SAVE", data, item)
8083

81-
self.model.setData(item,data, Qt.UserRole+1)
82-
self.model.setData(item,data['action.name'], Qt.DisplayRole)
84+
self.model.setData(item,data, Qt.ItemDataRole.UserRole+1)
85+
self.model.setData(item,data['action.name'], Qt.ItemDataRole.DisplayRole)
8386
self.defaultForm['category']=data['category']
8487
self.defaultForm['categoryText']=data['categoryText']
8588

@@ -104,7 +107,7 @@ def loadForm(self, form, items):
104107
w.setCurrentIndex(w.findText(v))
105108
elif isinstance(w,QListView) and w.model():
106109
index = w.model().match(w.model().index(0, 0),
107-
Qt.DisplayRole,
110+
Qt.ItemDataRole.DisplayRole,
108111
v,
109112
1);
110113
items[name]=w.setCurrentIndex(index)
@@ -127,7 +130,7 @@ def saveForm(self, form, items):
127130
else:
128131
items[name]=w.currentText()
129132
elif isinstance(w,QListView) and w.model():
130-
items[name]=w.currentIndex().data(Qt.DisplayRole)
133+
items[name]=w.currentIndex().data(Qt.ItemDataRole.DisplayRole)
131134

132135

133136
def getData(self, data):
@@ -384,7 +387,7 @@ def gitRemotePath(self):
384387

385388

386389
def projectPath(self):
387-
destDir = QFileDialog.getExistingDirectory(None, 'Select Project Directory',QDir.homePath(), QFileDialog.ShowDirsOnly)
390+
destDir = QFileDialog.getExistingDirectory(None, 'Select Project Directory',QDir.homePath(), QFileDialog.Option.ShowDirsOnly)
388391
self.centralWidget.projectPathLabel.setText(destDir)
389392

390393
def writeToFile(self,path,s):
@@ -406,9 +409,9 @@ def downloadKritaAPI(self):
406409

407410
if os.path.isfile(respath + ".KritaAPI."+ver+".zip"):
408411
return True
409-
msgbox = QMessageBox(QMessageBox.Question,'Would you like to download the API details automatically?',
410-
'', QMessageBox.Yes | QMessageBox.No)
411-
msgbox.setTextFormat(Qt.RichText)
412+
msgbox = QMessageBox(QMessageBox.Icon.Question,'Would you like to download the API details automatically?',
413+
'', QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No)
414+
msgbox.setTextFormat(Qt.TextFormat.RichText)
412415

413416
msgbox.setText("""Developer Tools would like to connect to the internet to download Krita API details.
414417
This process will only access Krita's offical git repository at invent.kde.org.
@@ -426,23 +429,23 @@ def downloadKritaAPI(self):
426429
Would you like to download the API details(less than 200kb of data) automatically?
427430
""")
428431

429-
if msgbox.exec() == QMessageBox.Yes:
432+
if msgbox.exec() == QMessageBox.StandardButton.Yes:
430433
getAPI = GetKritaAPI()
431434
res = {}
432435
try:
433436
res=getAPI.updateData(ver)
434437
except:
435-
QMessageBox(QMessageBox.Warning,'Failed!', "Failed to download API details! Make sure you have internet connection and your python urlib ssl is working properly").exec()
438+
QMessageBox(QMessageBox.Icon.Warning,'Failed!', "Failed to download API details! Make sure you have internet connection and your python urlib ssl is working properly").exec()
436439
return False
437440
print ("RES", res)
438441

439442
if res['status'] == 0:
440-
msgbox = QMessageBox(QMessageBox.Warning,'Error',str(res['error']))
443+
msgbox = QMessageBox(QMessageBox.Icon.Warning,'Error',str(res['error']))
441444

442445
msgbox.exec()
443446
return False
444447
else:
445-
QMessageBox(QMessageBox.Information,'Success!', "API details have been downloaded successfully!").exec()
448+
QMessageBox(QMessageBox.Icon.Information,'Success!', "API details have been downloaded successfully!").exec()
446449
else:
447450
return False
448451

plugindevtools/PluginDevTools/PluginGeneratorTemplates/BlankDocker/[SHORTNAME].py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
from PyQt5.QtWidgets import *
1+
try:
2+
from PyQt6.QtWidgets import *
3+
except:
4+
from PyQt5.QtWidgets import *
25
'''[%AUTOCOMPLETE%]'''
36

47
class '''[%SHORTNAME%]'''(DockWidget):
@@ -10,4 +13,4 @@ def __init__(self):
1013
def canvasChanged(self, canvas):
1114
pass
1215

13-
Krita.instance().addDockWidgetFactory(DockWidgetFactory("'''[%SHORTNAME%]'''", DockWidgetFactoryBase.DockRight, '''[%SHORTNAME%]'''))
16+
Krita.instance().addDockWidgetFactory(DockWidgetFactory("'''[%SHORTNAME%]'''", DockWidgetFactoryBase.DockPosition.DockRight, '''[%SHORTNAME%]'''))

plugindevtools/PluginDevTools/PluginGeneratorTemplates/SimpleDockerGUI/[SHORTNAME].py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
from PyQt5.QtWidgets import *
1+
try:
2+
from PyQt6.QtWidgets import *
3+
except:
4+
from PyQt5.QtWidgets import *
25
'''[%AUTOCOMPLETE%]'''
36

47
class '''[%SHORTNAME%]'''(DockWidget):
@@ -8,7 +11,7 @@ def __init__(self):
811
self.setWindowTitle("'''[%PLUGINTITLE%]'''")
912
label = QLabel(self)
1013
label.setObjectName("label")
11-
label.setAlignment(Qt.AlignCenter)
14+
label.setAlignment(Qt.AlignmentFlag.AlignCenter)
1215
label.setText("Hello World")
1316

1417
self.centralWidget = QWidget()
@@ -23,4 +26,4 @@ def __init__(self):
2326
def canvasChanged(self, canvas):
2427
pass
2528

26-
Krita.instance().addDockWidgetFactory(DockWidgetFactory("'''[%SHORTNAME%]'''", DockWidgetFactoryBase.DockRight, '''[%SHORTNAME%]'''))
29+
Krita.instance().addDockWidgetFactory(DockWidgetFactory("'''[%SHORTNAME%]'''", DockWidgetFactoryBase.DockPosition.DockRight, '''[%SHORTNAME%]'''))

plugindevtools/PluginDevTools/PluginGeneratorTemplates/SimpleDockerGUIQML/[SHORTNAME].py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
from PyQt5.QtWidgets import *
1+
try:
2+
from PyQt6.QtWidgets import *
3+
except:
4+
from PyQt5.QtWidgets import *
25
'''[%AUTOCOMPLETE%]'''
3-
from PyQt5 import uic
6+
try:
7+
from PyQt6 import uic
8+
except:
9+
from PyQt5 import uic
410

511
class '''[%SHORTNAME%]'''(DockWidget):
612

@@ -17,4 +23,4 @@ def __init__(self):
1723
def canvasChanged(self, canvas):
1824
pass
1925

20-
Krita.instance().addDockWidgetFactory(DockWidgetFactory("'''[%SHORTNAME%]'''", DockWidgetFactoryBase.DockRight, '''[%SHORTNAME%]'''))
26+
Krita.instance().addDockWidgetFactory(DockWidgetFactory("'''[%SHORTNAME%]'''", DockWidgetFactoryBase.DockPosition.DockRight, '''[%SHORTNAME%]'''))

plugindevtools/PluginDevTools/PluginGeneratorTemplates/SimpleExtensionDialogGUI/[SHORTNAME].py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def __init__(self):
77
self.setWindowTitle("'''[%PLUGINTITLE%]'''")
88
label = QLabel(self)
99
label.setObjectName("label")
10-
label.setAlignment(Qt.AlignCenter)
10+
label.setAlignment(Qt.AlignmentFlag.AlignCenter)
1111
label.setText("Hello World")
1212

1313
layout = QVBoxLayout()

plugindevtools/PluginDevTools/PluginGeneratorTemplates/SimpleExtensionDialogGUIQML/[SHORTNAME].py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
'''[%AUTOCOMPLETE%]'''
2-
from PyQt5 import uic
2+
try:
3+
from PyQt6 import uic
4+
except:
5+
from PyQt5 import uic
36

47
class '''[%SHORTNAME%]'''Dialog(QDialog):
58

0 commit comments

Comments
 (0)