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): ...@@ -61,7 +61,8 @@ def ImportModel(filename, use_kdtree=True, callback=None, **kwargs):
normal_conflict_warning_seen = False normal_conflict_warning_seen = False
if hasattr(filename, "read"): 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 # useful for later error messages
filename = "input stream" filename = "input stream"
else: else:
...@@ -70,6 +71,9 @@ def ImportModel(filename, use_kdtree=True, callback=None, **kwargs): ...@@ -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 # 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? # the whole file at once. This is ugly - anyone with a better idea?
f = StringIO.StringIO(url_file.read()) 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() url_file.close()
except IOError, err_msg: except IOError, err_msg:
log.error("STLImporter: Failed to read file (%s): %s" \ log.error("STLImporter: Failed to read file (%s): %s" \
...@@ -93,6 +97,8 @@ def ImportModel(filename, use_kdtree=True, callback=None, **kwargs): ...@@ -93,6 +97,8 @@ def ImportModel(filename, use_kdtree=True, callback=None, **kwargs):
f.seek(80) f.seek(80)
numfacets = unpack("<I", f.read(4))[0] numfacets = unpack("<I", f.read(4))[0]
binary = False 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): if f.len == (84 + 50*numfacets):
binary = True binary = True
......
...@@ -55,24 +55,19 @@ class GtkConsole(pycam.Plugins.PluginBase): ...@@ -55,24 +55,19 @@ class GtkConsole(pycam.Plugins.PluginBase):
self._original_stdout = sys.stdout self._original_stdout = sys.stdout
self._original_stdin = sys.stdin self._original_stdin = sys.stdin
self._console_buffer = self.gui.get_object("ConsoleViewBuffer") self._console_buffer = self.gui.get_object("ConsoleViewBuffer")
class ConsoleReplacement(object): # redirect the virtual console output to the window
def __init__(self): sys.stdout = StringIO.StringIO()
# clone sys.stdout def console_write(data):
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.insert(
self._console_buffer.get_end_iter(), data) self._console_buffer.get_end_iter(), data)
self._console_buffer.place_cursor( self._console_buffer.place_cursor(
self._console_buffer.get_end_iter()) self._console_buffer.get_end_iter())
self._original_stdout.write(data) self._console.write = console_write
sys.stdout = ConsoleReplacement()
# make sure that we are never waiting for input (e.g. "help()") # make sure that we are never waiting for input (e.g. "help()")
sys.stdin = StringIO.StringIO() 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() self._clear_console()
console_action = self.gui.get_object("ToggleConsoleWindow") console_action = self.gui.get_object("ToggleConsoleWindow")
self.register_gtk_accelerator("console", console_action, None, self.register_gtk_accelerator("console", console_action, None,
...@@ -123,6 +118,12 @@ class GtkConsole(pycam.Plugins.PluginBase): ...@@ -123,6 +118,12 @@ class GtkConsole(pycam.Plugins.PluginBase):
self._console.write(text + os.linesep) self._console.write(text + os.linesep)
# execute command - check if it needs more input # execute command - check if it needs more input
if not self._console.push(text): 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 # scroll down console view to the end of the buffer
view = self.gui.get_object("ConsoleView") view = self.gui.get_object("ConsoleView")
view.scroll_mark_onscreen(self._console_buffer.get_insert()) 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 ...@@ -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/>. along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
""" """
import uuid
# imported later (on demand) # imported later (on demand)
#import gtk #import gtk
...@@ -97,9 +96,11 @@ class Models(pycam.Plugins.ListPluginBase): ...@@ -97,9 +96,11 @@ class Models(pycam.Plugins.ListPluginBase):
self.core.register_namespace("models", self.core.register_namespace("models",
pycam.Plugins.get_filter(self)) pycam.Plugins.get_filter(self))
self.core.set("models", self) self.core.set("models", self)
self.register_state_item("models", self)
return True return True
def teardown(self): def teardown(self):
self.clear_state_items()
self.core.unregister_namespace("models") self.core.unregister_namespace("models")
if self.gui: if self.gui:
self.core.unregister_ui_section("model_handling") self.core.unregister_ui_section("model_handling")
...@@ -210,6 +211,4 @@ class ModelEntity(pycam.Plugins.ObjectWithAttributes): ...@@ -210,6 +211,4 @@ class ModelEntity(pycam.Plugins.ObjectWithAttributes):
def __init__(self, model): def __init__(self, model):
super(ModelEntity, self).__init__("model") super(ModelEntity, self).__init__("model")
self.model = 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): ...@@ -115,7 +115,6 @@ class Processes(pycam.Plugins.ListPluginBase):
self.clear_state_items() self.clear_state_items()
self.core.unregister_namespace("processes") self.core.unregister_namespace("processes")
if self.gui: 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("main", self.gui.get_object("ProcessBox"))
self.core.unregister_ui_section("process_path_parameters") self.core.unregister_ui_section("process_path_parameters")
self.core.unregister_ui("process_parameters", self.core.unregister_ui("process_parameters",
......
...@@ -23,6 +23,7 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>. ...@@ -23,6 +23,7 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
import os import os
import imp import imp
import inspect import inspect
import uuid
# TODO: load these modules only on demand # TODO: load these modules only on demand
import gtk import gtk
import gobject import gobject
...@@ -502,9 +503,9 @@ class ListPluginBase(PluginBase, list): ...@@ -502,9 +503,9 @@ class ListPluginBase(PluginBase, list):
class ObjectWithAttributes(dict): class ObjectWithAttributes(dict):
def __init__(self, key, params=None): def __init__(self, key, params=None):
if params is None: if not params is None:
params = {}
self.update(params) self.update(params)
self["uuid"] = uuid.uuid4()
self.node_key = key self.node_key = key
......
...@@ -42,7 +42,7 @@ def get_xml(item, name=None): ...@@ -42,7 +42,7 @@ def get_xml(item, name=None):
return leaf return leaf
else: else:
leaf = ET.Element(name) leaf = ET.Element(name)
leaf.text = repr(item) leaf.text = str(item)
return leaf return leaf
def parse_xml_dict(item): 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