Skip to content

Commit b9258be

Browse files
committed
PySide compat.
1 parent 15072d7 commit b9258be

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

config.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
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+
from PySide import QtCore, QtGui, QtUiTools
1112

1213

1314
# Python 3 compatibility
@@ -22,18 +23,29 @@ class Config(QtGui.QDialog):
2223
Parses the configuration the user applies
2324
"""
2425

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

28-
self.config = OrderedDict()
30+
self.config = col.OrderedDict()
2931

30-
self.ui = uic.loadUi("config.ui")
31-
self.ui.show()
32+
#self.setLayout(QtGui.QVBoxLayout())
33+
self.ui = QtUiTools.QUiLoader().load("config.ui")
34+
#self.layout().addWidget(self.ui)
35+
36+
print(dir(self))
37+
print(dir(self.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,19 @@ 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()
76+
window.activateWindow()
77+
window.raise_()
5978
return app.exec_()
6079

6180
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)