Designer.py.in 1.78 KB
Newer Older
1
2
#! /usr/bin/env python
"""
3
4
5
After been configured properly using CMAKE, 
this module allows to:
 - update the environment variable QT_PLUGIN_PATH with Slicer QT Plugin path
6
7
8
9
10
 - start the designer
"""

import os
import sys
11
import subprocess
12
  
13
def startDesigner(open_command, argv):
14
  "Start QT Designer"
15
16

  addEnvVariable('QT_PLUGIN_PATH', toCygwinPath('@CTK_QTDESIGNERPLUGINS_DIR@'))
17
  addEnvVariable('QT_PLUGIN_PATH', toCygwinPath('@CMAKE_LIBRARY_OUTPUT_DIRECTORY@'))
18
19
20
  openCmd = open_command+'@QT_BINARY_DIR@'+os.sep+argv[0]
  print openCmd
  os.system(openCmd + " " + argv[1])
21
22
23
24
25
26
27
28
29

def toCygwinPath(path):
  "Attempt to convert to a cygwin path"
  if (sys.platform == 'cygwin'):
    os.system('cygpath -u '+path);
    new_path=subprocess.Popen(["cygpath", "-u",path], stdout=subprocess.PIPE).communicate()[0]
  else:
    new_path=path
  return new_path.strip()
30
31

def addEnvVariable(name, value):
32
33
34
35
36
37
38
39
  "Add variable to environment"

  # If platform is cygwin, force pathseparator to be ':'
  pathsep = os.pathsep
  if (sys.platform == 'cygwin'):
    pathsep = ':'

  # Update OS environment
40
41
42
  if (name in os.environ):
    sep = ''
    if (os.environ[name] != ""):
43
      sep = pathsep
44
45
46
47
48
49
  
    os.environ[name] += (sep + value)
  
  else:
    os.environ[name] = value

50

51
52
53
54
55
56
57
58
59
# Entry point
if __name__ == "__main__":
  if (len(sys.argv) > 2):
    print """
designer.py - Start QT Designer with Slicer plugins

Use: python designer.py [UI file]
"""
  else:
60
61
62
    # Default executable name
    executable_name ='designer'
    open_command = ''
63
64
65

  if (len(sys.argv) < 2):
    sys.argv.append("")
66
    
67
68
69
70
  # Handle MACOSX case
  if sys.platform == 'darwin':
    executable_name = 'Designer.app'
    open_command = 'open '
71

72
73
74
  # Update first value to match executable name
  sys.argv[0] = executable_name
  startDesigner(open_command, sys.argv);