Skip to content

Commit

Permalink
config: Support PyQt or PySide.
Browse files Browse the repository at this point in the history
  • Loading branch information
jakirkham committed Jun 8, 2016
1 parent 15072d7 commit f0b4f95
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
37 changes: 27 additions & 10 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@

from __future__ import print_function

from collections import OrderedDict
import collections as col
import json
import os
import sys

from PyQt4 import QtCore, QtGui, uic

try:
from PySide import QtCore, QtGui, QtUiTools
except ImportError:
from PyQt4 import QtCore, QtGui, uic

# Python 3 compatibility
try:
Expand All @@ -22,18 +25,27 @@ class Config(QtGui.QDialog):
Parses the configuration the user applies
"""

def __init__(self):
super(Config, self).__init__()
def __init__(self, *args, **kwargs):
super(Config, self).__init__(*args, **kwargs)
self.modal = True

self.config = OrderedDict()
self.config = col.OrderedDict()

self.ui = uic.loadUi("config.ui")
self.ui.show()
try:
self.ui = QtUiTools.QUiLoader().load("config.ui")
except NameError:
self.ui = uic.loadUi("config.ui")

btn = self.ui.buttonBox.button(
btn_box = self.ui.buttonBox
ok_btn = btn_box.button(
QtGui.QDialogButtonBox.Ok
)
btn.clicked.connect(self.accept)
ok_btn.clicked.connect(self.accept)

def show(self):
self.ui.show()
self.ui.activateWindow()
self.ui.raise_()

def accept(self):
table = self.ui.tableWidget
Expand All @@ -50,12 +62,17 @@ def accept(self):
"",
"*.json"
)
# PySide gives us a tuple.
# The actual filename is first
if isinstance(filename, tuple):
filename = filename[0]
with open(filename, "w") as f:
json.dump(self.config, f, indent=True)

def main(*argv):
app = QtGui.QApplication(sys.argv)
window = Config()
window.show()
return app.exec_()

if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion config.ui
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
</item>
</layout>
</item>
<item row="0" column="0" alignment="Qt::AlignHCenter">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>&lt;b&gt;Lab Data Configuration Generator&lt;/b&gt;</string>
Expand Down

0 comments on commit f0b4f95

Please sign in to comment.