1
#!/usr/bin/env python
2
# This file is part of the PySide project.
3
#
4
# Copyright (C) 2009-2011 Nokia Corporation and/or its subsidiary(-ies).
5
# Copyright (C) 2010 Riverbank Computing Limited.
6
# Copyright (C) 2009 Torsten Marek
7
#
8
# Contact: PySide team <pyside@openbossa.org>
9
#
10
# This program is free software; you can redistribute it and/or
11
# modify it under the terms of the GNU General Public License
12
# version 2 as published by the Free Software Foundation.
13
#
14
# This program is distributed in the hope that it will be useful, but
15
# WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
# General Public License for more details.
18
#
19
# You should have received a copy of the GNU General Public License
20
# along with this program; if not, write to the Free Software
21
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22
# 02110-1301 USA
23
24
import sys
25
import optparse
26
27
from PySide import QtCore
28
from pysideuic.driver import Driver
29
from PySide import __version__ as PySideVersion
30
from pysideuic import __version__ as PySideUicVersion
31
32
Version = "PySide User Interface Compiler version %s, running on PySide %s." % (PySideUicVersion, PySideVersion)
33
34
def main():
35
    if sys.hexversion >= 0x03000000:
36
        from pysideuic.port_v3.invoke import invoke
37
    else:
38
        from pysideuic.port_v2.invoke import invoke
39
40
    parser = optparse.OptionParser(usage="pyside-uic [options] <ui-file>",
41
            version=Version)
42
    parser.add_option("-p", "--preview", dest="preview", action="store_true",
43
            default=False,
44
            help="show a preview of the UI instead of generating code")
45
    parser.add_option("-o", "--output", dest="output", default="-", metavar="FILE",
46
            help="write generated code to FILE instead of stdout")
47
    parser.add_option("-x", "--execute", dest="execute", action="store_true",
48
            default=False,
49
            help="generate extra code to test and display the class")
50
    parser.add_option("-d", "--debug", dest="debug", action="store_true",
51
            default=False, help="show debug output")
52
    parser.add_option("-i", "--indent", dest="indent", action="store", type="int",
53
            default=4, metavar="N",
54
            help="set indent width to N spaces, tab if N is 0 (default: 4)")
55
56
    g = optparse.OptionGroup(parser, title="Code generation options")
57
    g.add_option("--from-imports", dest="from_imports", action="store_true",
58
            default=False, help="generate imports relative to '.'")
59
    parser.add_option_group(g)
60
61
    opts, args = parser.parse_args()
62
63
    if len(args) != 1:
64
        sys.stderr.write("Error: one input ui-file must be specified\n")
65
        sys.exit(1)
66
67
    sys.exit(invoke(Driver(opts, args[0])))
68
69
if __name__ == "__main__":
70
     main()