fixed performance issue with StringIO.
[sface.git] / sface-run
1 #!/usr/bin/env python
2
3 import os
4 import sys
5 from optparse import OptionParser
6 from PyQt4.QtGui import *
7
8 sys.path.append(".")
9 exe = os.path.abspath(sys.argv[0])
10
11 def using_env(e):
12     print "Using %s = %s" % (e, os.environ[e])
13
14 def print_env(config):
15     if not config.verbose:
16         return
17
18     if sys.platform == "darwin":
19         using_env("DYLD_FRAMEWORK_PATH")
20         using_env("DYLD_LIBRARY_PATH")
21
22     using_env("PATH")
23     print "Using sys.path =", sys.path
24
25 if sys.platform == "darwin":
26     # for testing on mac os x 10.5 - baris
27     sys.path.append("/opt/local/lib/python2.5/site-packages/")
28
29     DIR = os.path.dirname(exe)
30     CONTENTS = os.path.dirname(DIR)
31     RESOURCES = os.path.join(CONTENTS, "Resources")
32     FRAMEWORKS = os.path.join(CONTENTS, "Frameworks")
33      
34     DYLD_FRAMEWORK_PATH = FRAMEWORKS
35     DYLD_LIBRARY_PATH = RESOURCES
36     PATH = os.getenv("PATH")
37     SFI_PATH = os.path.join(RESOURCES, "sfa/client")
38     PATH=":".join([RESOURCES, SFI_PATH, PATH])
39
40     os.environ["PATH"] = PATH
41     os.environ["DYLD_LIBRARY_PATH"] = DYLD_LIBRARY_PATH
42     os.environ["DYLD_FRAMEWORK_PATH"] = DYLD_FRAMEWORK_PATH
43     if os.path.exists(RESOURCES):  sys.path.append(RESOURCES)
44     if os.path.exists(FRAMEWORKS): sys.path.append(FRAMEWORKS)
45
46 elif sys.platform == "linux2":
47     sys.path.extend(["/usr/share", "/usr/share/sface"])
48
49
50 from sface.mainwindow import MainWindow
51 from sface.config import config
52
53 def main(args):
54     app = QApplication(args)
55     app.setStyleSheet('''
56 /* transparency
57 QDialog, MainWindow {
58   background-color:rgba(255,255,255,120);
59 }
60 */
61
62 QTreeView, QLineEdit { 
63   border: 2px solid gray;
64   border-radius: 4px;
65   padding: 1px;
66   margin: 2px;
67 }
68
69 QPushButton {
70   background-color: white;
71   border: 2px solid gray;
72   border-radius: 4px;
73   padding: 6px;
74 }
75
76 QPushButton:pressed {
77   background-color: #5599FF;
78 }
79
80 QLabel {
81   font-size: 14px;
82 }
83
84 ''')
85
86
87     win = MainWindow()
88     win.redirectOutputToLog()
89     win.setWindowTitle("Sface: SFA Interface")
90     win.show()
91     win.raise_()
92     win.activateWindow()
93     app.setActiveWindow(win)
94
95     sys.exit(app.exec_())
96
97
98 if __name__ == "__main__":
99     parser=OptionParser()
100     config.add_options_to_OptionParser(parser)
101     (options,args)=parser.parse_args()
102     config.update_from_OptionParser(options)
103     config.display("After command-line")
104     print_env(config)
105     main(sys.argv)