/usr/share/pyshared/wxglade/wxglade.py is in python-wxglade 0.6.4-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | #!/usr/bin/env python
# wxglade.py: entry point of wxGlade
#
# Copyright (c) 2002-2007 Alberto Griggio <agriggio@users.sourceforge.net>
# License: MIT (see license.txt)
# THIS PROGRAM COMES WITH NO WARRANTY
import os
import sys
import gettext
import getopt
import common
t = gettext.translation(domain="wxglade", localedir="locale", fallback=True)
t.install("wxglade")
# check to see if the Python release supports boolean identifiers
# and bool built-in function (>= Python 2.2.1).
try:
True, False, bool
except NameError:
setattr(__builtins__, 'True', 1)
setattr(__builtins__, 'False', not True)
def bool(value): return not not value
setattr(__builtins__, 'bool', bool)
# and this is for Python <= 2.3
try:
sorted
except NameError:
def sorted(l):
l = list(l)[:]
l.sort()
return l
setattr(__builtins__, 'sorted', sorted)
def _fix_path(path):
"""\
Returns an absolute version of path, accroding to the invoking dir of
wxglade (which can be different from '.' if it is invoked from a shell
script)
"""
if not os.path.isabs(path):
return os.path.join(os.getcwd(), path)
#getenv('WXGLADE_INVOKING_DIR', '.'), path)
return path
def parse_command_line():
try:
options, args = getopt.getopt(
sys.argv[1:],
"g:o:",
['generate-code=', 'output=']
)
except getopt.GetoptError:
#import traceback; traceback.print_exc()
usage()
return options, args
def command_line_code_generation(options, args):
"""\
starts a code generator without starting the GUI.
"""
if not options:
usage()
if not options[0]:
usage() # a language for code generation must be provided
if len(args) != 1:
usage() # an input file name must be provided
common.use_gui = False # don't import wxPython.wx
# use_gui has to be set before importing config
import config
config.init_preferences()
common.load_code_writers()
common.load_widgets()
common.load_sizers()
try:
from xml_parse import CodeWriter
out_path = None
language = ''
for option, arg in options:
if option == '-g' or option == '--generate-code':
language = arg
elif option == '-o' or option == '--output':
out_path = _fix_path(arg)
writer = common.code_writers[language]
CodeWriter(writer, _fix_path(args[0]), out_path=out_path)
except KeyError:
print >> sys.stderr, \
_('Error: no writer for language "%s" available') % language
sys.exit(1)
except Exception, e:
print >> sys.stderr, _("Error: %s") % e
import traceback; traceback.print_exc()
sys.exit(1)
sys.exit(0)
def usage():
"""\
Prints a help message about the usage of wxGlade from the command line.
"""
msg = _("""\
wxGlade usage:
- to start the GUI: python wxglade.py [WXG_FILE]
- to generate code from the command line: python wxglade.py OPTIONS... FILE
OPTIONS are the following:
-g, --generate-code=LANGUAGE (required) give the output language
-o, --output=PATH (optional) name of the output file (in
single-file mode) or directory (in
multi-file mode)
""")
print msg
print _('Valid LANGUAGE values:'),
common.use_gui = False
common.load_code_writers()
for value in common.code_writers:
print value,
print '\n'
sys.exit(1)
def determine_wxglade_path():
try:
root = __file__
if os.path.islink(root):
root = os.path.realpath(root)
return os.path.dirname(os.path.abspath(root))
except:
# __file__ is not defined when building an .exe with McMillan
return os.path.dirname(sys.argv[0])
def run_main():
"""\
This main procedure is started by calling either wxglade.py or
wxglade.pyw on windows
"""
# prepend the widgets dir to the
# app's search path
wxglade_path = determine_wxglade_path()
#sys.path = [os.getcwd(), os.path.join(os.getcwd(), 'widgets')] + sys.path
sys.path = [wxglade_path, os.path.join(wxglade_path, 'widgets')] + sys.path
# set the program's path
common.wxglade_path = wxglade_path #os.getcwd()
# before running the GUI, let's see if there are command line options for
# code generation
filename = None
start_gui = False
options, args = parse_command_line()
if len(sys.argv) == 1:
start_gui = True
elif not options:
filename = _fix_path(args[0])
start_gui = True
if start_gui:
# print versions first
import main
import wx
print _("Starting wxGlade version %s on Python %s and wxPython %s") % (
common.version,
sys.version.split()[0],
wx.__version__,
)
# if there was no option, start the app in GUI mode
main.main(filename)
else:
# print versions first
print _("Starting wxGlade version %s on Python %s") % (
common.version,
sys.version.split()[0],
)
command_line_code_generation(options, args)
if __name__ == "__main__":
run_main()
|