Commit 0f89dcab authored by sumpfralle's avatar sumpfralle

introduced a "namespace" concept for the console (not fully working)


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1255 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 84ddb0c0
......@@ -154,6 +154,7 @@ class EventCore(pycam.Gui.Settings.Settings):
self.ui_sections = {}
self.chains = {}
self.state_dumps = []
self.namespace = {}
def register_event(self, event, func, *args):
if not event in self.event_handlers:
......@@ -316,8 +317,9 @@ class EventCore(pycam.Gui.Settings.Settings):
parent = root
if match:
for component in chain[:-1]:
if parent.find(component):
parent = parent.find(component)
next_item = parent.find(component)
if not next_item is None:
parent = next_item
else:
item = ET.SubElement(parent, component)
parent = item
......@@ -327,6 +329,20 @@ class EventCore(pycam.Gui.Settings.Settings):
def reset_state(self):
pass
def register_namespace(self, name, value):
if name in self.namespace:
log.info("Trying to register the same key in namespace twice: " + \
str(name))
self.namespace[name] = value
def unregister_namespace(self, name):
if not name in self.namespace:
log.info("Tried to unregister an unknown name from namespace: " + \
str(name))
def get_namespace(self):
return self.namespace
class ProjectGui(object):
......
......@@ -144,10 +144,13 @@ class Bounds(pycam.Plugins.ListPluginBase):
self._event_handlers.append(("bounds-changed", "visual-item-updated"))
self.register_event_handlers(self._event_handlers)
self.register_state_item("bounds-list", self)
self.core.register_namespace("bounds",
pycam.Plugins.get_filter(self))
return True
def teardown(self):
self.clear_state_items()
self.core.unregister_namespace("bounds")
if self.gui:
self.core.unregister_ui("main", self.gui.get_object("BoundsBox"))
self.unregister_gtk_handlers(self._gtk_handlers)
......
......@@ -20,6 +20,7 @@ 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
......@@ -93,10 +94,13 @@ class Models(pycam.Plugins.ListPluginBase):
self.register_model_update(update_model)
# update the model list
self.core.emit_event("model-list-changed")
self.core.register_namespace("models",
pycam.Plugins.get_filter(self))
self.core.set("models", self)
return True
def teardown(self):
self.core.unregister_namespace("models")
if self.gui:
self.core.unregister_ui_section("model_handling")
self.core.unregister_ui("main", self.gui.get_object("ModelBox"))
......@@ -176,6 +180,12 @@ class Models(pycam.Plugins.ListPluginBase):
def get_visible(self):
return [model for model in self if model["visible"]]
def get_by_uuid(self, uuid):
for model in self:
if model["uuid"] == uuid:
return model
return None
def add_model(self, model, name=None, name_template="Model #%d",
color=None):
model_dict = ModelEntity(model)
......@@ -198,6 +208,8 @@ class Models(pycam.Plugins.ListPluginBase):
class ModelEntity(pycam.Plugins.ObjectWithAttributes):
def __init__(self, model):
self.model = model
super(ModelEntity, self).__init__("model")
self.model = model
# this UUID is not connected with model.uuid
self["uuid"] = uuid.uuid4()
......@@ -107,10 +107,13 @@ class Processes(pycam.Plugins.ListPluginBase):
self.register_gtk_handlers(self._gtk_handlers)
self.register_event_handlers(self._event_handlers)
self.register_state_item("processes", self)
self.core.register_namespace("processes",
pycam.Plugins.get_filter(self))
return True
def teardown(self):
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"))
......
......@@ -99,9 +99,12 @@ class Toolpaths(pycam.Plugins.ListPluginBase):
self._trigger_toolpath_time_update()
self._update_widgets()
self.core.set("toolpaths", self)
self.core.register_namespace("toolpaths",
pycam.Plugins.get_filter(self))
return True
def teardown(self):
self.core.unregister_namespace("toolpaths")
if self.gui:
self.core.unregister_ui("main", self.gui.get_object("ToolpathsBox"))
self.unregister_gtk_handlers(self._gtk_handlers)
......
......@@ -127,11 +127,14 @@ class Tools(pycam.Plugins.ListPluginBase):
self._update_widgets()
self._trigger_table_update()
self._tool_switch()
self.core.register_namespace("tools",
pycam.Plugins.get_filter(self))
self.register_state_item("tools", self)
return True
def teardown(self):
self.clear_state_items()
self.core.unregister_namespace("tools")
if self.gui:
self.core.unregister_ui("main", self.gui.get_object("ToolBox"))
self.core.unregister_ui_section("tool_speed")
......
......@@ -498,3 +498,40 @@ class ObjectWithAttributes(dict):
self.update(params)
self.node_key = key
def filter_list(items, *args, **kwargs):
if len(args) > 1:
_log.info("This filter accepts only a single unnamed parameter: " + \
"index(es), but %d parameters were given" % len(args))
return []
elif len(args) == 1:
try:
items = [items[index] for index in args[0]]
except TypeError:
# not iterable
try:
items = [items[args[0]]]
except (IndexError, TypeError):
_log.info("Invalid index requested in filter: %s" % \
str(args[0]))
return []
else:
pass
result = []
for item in items:
for filter_key in kwargs:
try:
if not item[filter_key] == kwargs[filter_key]:
break
except KeyError:
_log.info("Tried to filter an unknown attribute: %s" % \
str(filter_key))
break
else:
# all keys are matching
result.append(item)
return result
def get_filter(items):
return lambda *args, **kwargs: filter_list(items, *args, **kwargs)
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