Commit c38c1c2c authored by Paul Bonser's avatar Paul Bonser
parents 7d21a483 09088718
......@@ -61,7 +61,8 @@ def ImportModel(filename, use_kdtree=True, callback=None, **kwargs):
normal_conflict_warning_seen = False
if hasattr(filename, "read"):
f = filename
# make sure that the input stream can seek and has ".len"
f = StringIO.StringIO(filename.read())
# useful for later error messages
filename = "input stream"
else:
......@@ -70,6 +71,9 @@ def ImportModel(filename, use_kdtree=True, callback=None, **kwargs):
# urllib.urlopen objects do not support "seek" - so we need to read
# the whole file at once. This is ugly - anyone with a better idea?
f = StringIO.StringIO(url_file.read())
# TODO: the above ".read" may be incomplete - this is ugly
# see http://patrakov.blogspot.com/2011/03/case-of-non-raised-exception.html
# and http://stackoverflow.com/questions/1824069/urllib2-not-retrieving-entire-http-response
url_file.close()
except IOError, err_msg:
log.error("STLImporter: Failed to read file (%s): %s" \
......@@ -93,6 +97,8 @@ def ImportModel(filename, use_kdtree=True, callback=None, **kwargs):
f.seek(80)
numfacets = unpack("<I", f.read(4))[0]
binary = False
log.debug("STL import info: %s / %s / %s / %s" % \
(f.len, numfacets, header.find("solid"), header.find("facet")))
if f.len == (84 + 50*numfacets):
binary = True
......
......@@ -55,24 +55,19 @@ class GtkConsole(pycam.Plugins.PluginBase):
self._original_stdout = sys.stdout
self._original_stdin = sys.stdin
self._console_buffer = self.gui.get_object("ConsoleViewBuffer")
class ConsoleReplacement(object):
def __init__(self):
# clone sys.stdout
for item in dir(sys.stdout):
if item.startswith("_") or (item == "write"):
continue
child = getattr(sys.stdout, item)
setattr(self, item, child)
def write(self_obj, data):
self._console_buffer.insert(
self._console_buffer.get_end_iter(), data)
self._console_buffer.place_cursor(
self._console_buffer.get_end_iter())
self._original_stdout.write(data)
sys.stdout = ConsoleReplacement()
# redirect the virtual console output to the window
sys.stdout = StringIO.StringIO()
def console_write(data):
self._console_buffer.insert(
self._console_buffer.get_end_iter(), data)
self._console_buffer.place_cursor(
self._console_buffer.get_end_iter())
self._console.write = console_write
# make sure that we are never waiting for input (e.g. "help()")
sys.stdin = StringIO.StringIO()
self._console.write = sys.stdout.write
# multiprocessing has a bug regarding the handling of sys.stdin:
# see http://bugs.python.org/issue10174
sys.stdin.fileno = lambda: -1
self._clear_console()
console_action = self.gui.get_object("ToggleConsoleWindow")
self.register_gtk_accelerator("console", console_action, None,
......@@ -123,6 +118,12 @@ class GtkConsole(pycam.Plugins.PluginBase):
self._console.write(text + os.linesep)
# execute command - check if it needs more input
if not self._console.push(text):
# append result to console view
sys.stdout.seek(0)
for line in sys.stdout.readlines():
self._console.write(line)
# clear the buffer
sys.stdout.truncate(0)
# scroll down console view to the end of the buffer
view = self.gui.get_object("ConsoleView")
view.scroll_mark_onscreen(self._console_buffer.get_insert())
......
......@@ -20,7 +20,6 @@ You should have received a copy of the GNU General Public License
along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
"""
import uuid
# imported later (on demand)
#import gtk
......@@ -97,9 +96,11 @@ class Models(pycam.Plugins.ListPluginBase):
self.core.register_namespace("models",
pycam.Plugins.get_filter(self))
self.core.set("models", self)
self.register_state_item("models", self)
return True
def teardown(self):
self.clear_state_items()
self.core.unregister_namespace("models")
if self.gui:
self.core.unregister_ui_section("model_handling")
......@@ -210,6 +211,4 @@ class ModelEntity(pycam.Plugins.ObjectWithAttributes):
def __init__(self, model):
super(ModelEntity, self).__init__("model")
self.model = model
# this UUID is not connected with model.uuid
self["uuid"] = uuid.uuid4()
......@@ -115,7 +115,6 @@ class Processes(pycam.Plugins.ListPluginBase):
self.clear_state_items()
self.core.unregister_namespace("processes")
if self.gui:
self.core.unregister_chain("state_dump", self.dump_state)
self.core.unregister_ui("main", self.gui.get_object("ProcessBox"))
self.core.unregister_ui_section("process_path_parameters")
self.core.unregister_ui("process_parameters",
......
......@@ -23,6 +23,7 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
import os
import imp
import inspect
import uuid
# TODO: load these modules only on demand
import gtk
import gobject
......@@ -502,9 +503,9 @@ class ListPluginBase(PluginBase, list):
class ObjectWithAttributes(dict):
def __init__(self, key, params=None):
if params is None:
params = {}
self.update(params)
if not params is None:
self.update(params)
self["uuid"] = uuid.uuid4()
self.node_key = key
......
......@@ -42,7 +42,7 @@ def get_xml(item, name=None):
return leaf
else:
leaf = ET.Element(name)
leaf.text = repr(item)
leaf.text = str(item)
return leaf
def parse_xml_dict(item):
......
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