pycamGUI 5.06 KB
Newer Older
1
#!/usr/bin/python
2

3 4
from pycam.Gui.ode_objects import override_ode_availability
import pycam.Gui.common as GuiCommon
5
from optparse import OptionParser
6
import sys
7
import os
lode_leroy's avatar
lode_leroy committed
8

9 10 11 12 13
# check if we were started as a separate program
if __name__ == "__main__":
    inputfile = None
    outputfile = None

14
    parser = OptionParser(usage="usage: %prog [options] [inputfile [outputfile]]")
15 16
    parser.add_option("", "--gui", dest="display",
            action="store_true", default=False,
17
            help="don't create the outputfile on the fly - just preset the output filename and show the GUI")
18
    parser.add_option("", "--gtk", dest="gtk_gui",
19 20 21 22 23
            action="store_true", default=True,
            help="use the new GTK interface (default)")
    parser.add_option("", "--tk", dest="gtk_gui",
            action="store_false",
            help="use the (old) Tk interface")
24 25
    parser.add_option("-c", "--config", dest="config_file",
            default=None, action="store", type="string",
26
            help="load a task settings file (requires the GTK interface)")
27 28
    parser.add_option("", "--task", dest="task",
            default=None, action="store", type="int",
29
            help="choose a specific task from task settings by number (requires the GTK interface)")
30 31
    parser.add_option("", "--disable-ode", dest="ode_disabled",
            default=False, action="store_true", help="disable experimental ODE collision detection")
32 33 34 35 36 37 38 39 40
    (options, args) = parser.parse_args()

    if len(args) > 0:
        inputfile = args[0]
    if len(args) > 1:
        outputfile = args[1]
    if len(args) > 2:
        parser.error("too many arguments given (%d instead of %d)" % (len(args), 2))

41
    # try the configured interface first and then try to fall back to the alternative, if necessary
42 43 44 45
    deps_gtk = GuiCommon.dependency_details_gtk()
    deps_tk = GuiCommon.dependency_details_tk()
    report_gtk = GuiCommon.get_dependency_report(deps_gtk, prefix="\t")
    report_tk = GuiCommon.get_dependency_report(deps_tk, prefix="\t")
46
    if options.gtk_gui:
47
        if GuiCommon.check_dependencies(deps_gtk):
48
            from pycam.Gui.Project import ProjectGui
49
            gui_class = ProjectGui
50 51 52 53
        else:
            print >> sys.stderr, "Error: Failed to load the GTK interface."
            print >> sys.stderr, "Details:"
            print >> sys.stderr, report_gtk
54
            print >> sys.stderr, "I will try to use the alternative Tk interface now ..."
55
            if GuiCommon.check_dependencies(deps_tk):
56
                from pycam.Gui.SimpleGui import SimpleGui
57
                gui_class = SimpleGui
58
                options.gtk_gui = False
59
            else:
60
                gui_class = None
61
    else:
62
        if GuiCommon.check_dependencies(deps_tk):
63
            from pycam.Gui.SimpleGui import SimpleGui
64
            gui_class = SimpleGui
65 66 67 68
        else:
            print >> sys.stderr, "Error: Failed to load the Tk interface."
            print >> sys.stderr, "Details:"
            print >> sys.stderr, report_tk
69
            print >> sys.stderr, "I will try to use the alternative GTK interface now ..."
70
            if GuiCommon.check_dependencies(deps_gtk):
71
                from pycam.Gui.Project import ProjectGui
72
                gui_class = ProjectGui
73
                options.gtk_gui = True
74
            else:
75
                gui_class = None
76
    # exit if no interface is found
77
    if gui_class is None:
78 79 80 81 82 83 84 85 86 87 88 89
        full_report = []
        full_report.append("Neither the GTK nor the Tk interface is available. Please install the corresponding packages!")
        full_report.append("")
        full_report.append("Dependency report for GTK interface:")
        full_report.append(report_gtk)
        full_report.append("")
        full_report.append("Dependency report for Tk interface:")
        full_report.append(report_tk)
        full_report.append("")
        full_report.append("Detailed list of requirements: %s" % GuiCommon.REQUIREMENTS_LINK)
        full_report.append("")
        GuiCommon.EmergencyDialog("PyCAM dependency problem", os.linesep.join(full_report))
90
        sys.exit(1)
91 92 93 94

    if options.ode_disabled:
        override_ode_availability(False)

95
    if outputfile and not options.display:
96
        gui = gui_class(no_dialog=True)
97
    else:
98
        gui = gui_class()
99 100

    if not inputfile:
101
        from pycam.Importers.TestModel import TestModel
102
        gui.load_model(TestModel())
103
    else:
104
        gui.open(inputfile)
105
    # load task settings file
106 107 108
    # only available for the GTK interface
    if options.gtk_gui:
        if options.config_file:
109
            gui.open_task_settings_file(options.config_file)
110 111
    if outputfile and not options.display:
        # an output filename is given and no gui is explicitly requested
112 113 114 115 116 117 118
        if options.gtk_gui:
            if not options.task is None:
                gui.process_one_task(options.task)
            else:
                gui.process_multiple_tasks()
        else:
            gui.generateToolpath()
119
        if outputfile:
120
            gui.save_toolpath(outputfile)
121 122 123 124 125
    else:
        # the gui should be shown
        if outputfile:
            gui.setOutputFilename(outputfile)
        gui.mainloop()
126