Commit 76c76d3b authored by sumpfralle's avatar sumpfralle

added a warning message displayed in a Tk window (requires no dependencies)...

added a warning message displayed in a Tk window (requires no dependencies) for missing dependencies
This should be especially useful for Windows users, since they don't see any error messages
when starting PyCAM via its menu item.


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@262 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent d603348b
Version 0.2.3 - UNRELEASED
* fixed "overlap" calculation
* added a warning dialog (GUI) for missing dependencies during startup (especially useful for Windows)
Version 0.2.2 - 2010-03-17
* added a graphical installer for Windows (via distutils)
......
......@@ -2,6 +2,8 @@ import Tkinter
# "ode" is imported later, if required
#import ode_objects
import random
import sys
import os
MODEL_TRANSFORMATIONS = {
......@@ -17,6 +19,23 @@ MODEL_TRANSFORMATIONS = {
"y_swap_z": ((1, 0, 0, 0), (0, 0, 1, 0), (0, 1, 0, 0)),
}
DEPENDENCY_DESCRIPTION = {
"gtk": ("Python bindings for GTK+",
"Install the package 'python-gtk2'",
"see http://www.bonifazi.eu/appunti/pygtk_windows_installer.exe"),
"opengl": ("Python bindings for OpenGL",
"Install the package 'python-opengl'",
"see http://www.bonifazi.eu/appunti/pygtk_windows_installer.exe"),
"gtkgl": ("GTK extension for OpenGL",
"Install the package 'python-gtkglext1'",
"see http://www.bonifazi.eu/appunti/pygtk_windows_installer.exe"),
"togl": ("Tk for OpenGL",
"see http://downloads.sourceforge.net/togl/",
"see http://downloads.sourceforge.net/togl/"),
}
REQUIREMENTS_LINK = "https://sourceforge.net/apps/mediawiki/pycam/index.php?title=Requirements"
def transform_model(model, direction="normal"):
model.transform(MODEL_TRANSFORMATIONS[direction])
......@@ -29,8 +48,64 @@ def scale_model(model, scale):
matrix = ((scale, 0, 0, 0), (0, scale, 0, 0), (0, 0, scale, 0))
model.transform(matrix)
def dependency_details_gtk():
result = {}
try:
import gtk
result["gtk"] = True
except ImportError:
result["gtk"] = False
try:
import gtk.gtkgl
result["gtkgl"] = True
except ImportError:
result["gtkgl"] = False
try:
import OpenGL
result["opengl"] = True
except ImportError:
result["opengl"] = False
return result
def dependency_details_tk():
result = {}
try:
import OpenGL
result["opengl"] = True
except ImportError:
result["opengl"] = False
try:
import OpenGL.Tk
result["togl"] = True
except (ImportError, Tkinter.TclError):
result["togl"] = False
return result
def check_dependencies(details):
"""you can feed this function with the output of "dependency_details_gtk" or "..._tk".
The result is True if all dependencies are met.
"""
failed = [key for (key, state) in details.items() if not state]
return len(failed) == 0
def get_dependency_report(details, prefix=""):
result = []
DESC_COL = 0
if sys.platform.startswith("win"):
ADVICE_COL = 2
else:
ADVICE_COL = 1
for key, state in details.items():
text = "%s%s: " % (prefix, DEPENDENCY_DESCRIPTION[key][DESC_COL])
if state:
text += "OK"
else:
text += "MISSING (%s)" % DEPENDENCY_DESCRIPTION[key][ADVICE_COL]
result.append(text)
return os.linesep.join(result)
class EmergencyDialog(Tkinter.Frame):
class EmergencyDialog:
""" This graphical message window requires no external dependencies.
The Tk interface package is part of the main python distribution.
Use this class for displaying dependency errors (especially on Windows).
......@@ -47,20 +122,22 @@ class EmergencyDialog(Tkinter.Frame):
root.bind("<Return>", self.finish)
root.bind("<Escape>", self.finish)
root.minsize(300, 100)
Tkinter.Frame.__init__(self, root, width=400)
self.pack()
self.root = root
frame = Tkinter.Frame(root)
frame.pack()
# add text output as label
message = Tkinter.Message(self, text=message, width=200)
message["width"] = 200
message = Tkinter.Message(root, text=message)
# we need some space for the dependency report
message["width"] = 800
message.pack()
# add the "close" button
close = Tkinter.Button(root, text="Close")
close["command"] = self.finish
close.pack(side=Tkinter.BOTTOM)
self.mainloop()
root.mainloop()
def finish(self, *args):
self.quit()
self.root.quit()
class ToolPathList(list):
......
#!/usr/bin/python
from pycam.Gui.common import override_ode_availability
from pycam.Gui.ode_objects import override_ode_availability
import pycam.Gui.common as GuiCommon
from optparse import OptionParser
import sys
import os
# check if we were started as a separate program
if __name__ == "__main__":
......@@ -37,35 +39,52 @@ if __name__ == "__main__":
parser.error("too many arguments given (%d instead of %d)" % (len(args), 2))
# try the configured interface first and then try to fall back to the alternative, if necessary
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")
if options.gtk_gui:
try:
if GuiCommon.check_dependencies(deps_gtk):
from pycam.Gui.Project import ProjectGui
gui_class = ProjectGui
except ImportError, err_msg:
print >> sys.stderr, "Failed to load GTK bindings for python. Please install the package 'python-gtk2'."
print >> sys.stderr, "Details: %s" % str(err_msg)
else:
print >> sys.stderr, "Error: Failed to load the GTK interface."
print >> sys.stderr, "Details:"
print >> sys.stderr, report_gtk
print >> sys.stderr, "I will try to use the alternative Tk interface now ..."
try:
if GuiCommon.check_dependencies(deps_tk):
from pycam.Gui.SimpleGui import SimpleGui
gui_class = SimpleGui()
except ImportError:
gui_class = SimpleGui
else:
gui_class = None
else:
try:
if GuiCommon.check_dependencies(deps_tk):
from pycam.Gui.SimpleGui import SimpleGui
gui_class = SimpleGui
except ImportError, err_msg:
print >> sys.stderr, "Failed to load TkInter bindings for python. Please install the package 'python-tk'."
print >> sys.stderr, "Details: %s" % str(err_msg)
else:
print >> sys.stderr, "Error: Failed to load the Tk interface."
print >> sys.stderr, "Details:"
print >> sys.stderr, report_tk
print >> sys.stderr, "I will try to use the alternative GTK interface now ..."
try:
if GuiCommon.check_dependencies(deps_gtk):
from pycam.Gui.Project import ProjectGui
gui_class = ProjectGui
except ImportError:
else:
gui_class = None
# exit if no interface is found
if gui_class is None:
print >> sys.stderr, "Neither the GTK nor the Tk interface is available. Please install the corresponding packages!"
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))
sys.exit(1)
if options.ode_disabled:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment