Skip to content

Commit f0b4f95

Browse files
committed
config: Support PyQt or PySide.
1 parent 15072d7 commit f0b4f95

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

config.py

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33

44
from __future__ import print_function
55

6-
from collections import OrderedDict
6+
import collections as col
77
import json
8+
import os
89
import sys
910

10-
from PyQt4 import QtCore, QtGui, uic
11-
11+
try:
12+
from PySide import QtCore, QtGui, QtUiTools
13+
except ImportError:
14+
from PyQt4 import QtCore, QtGui, uic
1215

1316
# Python 3 compatibility
1417
try:
@@ -22,18 +25,27 @@ class Config(QtGui.QDialog):
2225
Parses the configuration the user applies
2326
"""
2427

25-
def __init__(self):
26-
super(Config, self).__init__()
28+
def __init__(self, *args, **kwargs):
29+
super(Config, self).__init__(*args, **kwargs)
30+
self.modal = True
2731

28-
self.config = OrderedDict()
32+
self.config = col.OrderedDict()
2933

30-
self.ui = uic.loadUi("config.ui")
31-
self.ui.show()
34+
try:
35+
self.ui = QtUiTools.QUiLoader().load("config.ui")
36+
except NameError:
37+
self.ui = uic.loadUi("config.ui")
3238

33-
btn = self.ui.buttonBox.button(
39+
btn_box = self.ui.buttonBox
40+
ok_btn = btn_box.button(
3441
QtGui.QDialogButtonBox.Ok
3542
)
36-
btn.clicked.connect(self.accept)
43+
ok_btn.clicked.connect(self.accept)
44+
45+
def show(self):
46+
self.ui.show()
47+
self.ui.activateWindow()
48+
self.ui.raise_()
3749

3850
def accept(self):
3951
table = self.ui.tableWidget
@@ -50,12 +62,17 @@ def accept(self):
5062
"",
5163
"*.json"
5264
)
65+
# PySide gives us a tuple.
66+
# The actual filename is first
67+
if isinstance(filename, tuple):
68+
filename = filename[0]
5369
with open(filename, "w") as f:
5470
json.dump(self.config, f, indent=True)
5571

5672
def main(*argv):
5773
app = QtGui.QApplication(sys.argv)
5874
window = Config()
75+
window.show()
5976
return app.exec_()
6077

6178
if __name__ == "__main__":

config.ui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
</item>
131131
</layout>
132132
</item>
133-
<item row="0" column="0" alignment="Qt::AlignHCenter">
133+
<item row="0" column="0">
134134
<widget class="QLabel" name="label">
135135
<property name="text">
136136
<string>&lt;b&gt;Lab Data Configuration Generator&lt;/b&gt;</string>

0 commit comments

Comments
 (0)