33
44from __future__ import print_function
55
6- from collections import OrderedDict
6+ import collections as col
77import json
8+ import os
89import 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
1417try :
@@ -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
5672def main (* argv ):
5773 app = QtGui .QApplication (sys .argv )
5874 window = Config ()
75+ window .show ()
5976 return app .exec_ ()
6077
6178if __name__ == "__main__" :
0 commit comments