Skip to content

Commit

Permalink
GitHub #283: GUI owns params; push only changes that we made
Browse files Browse the repository at this point in the history
  • Loading branch information
bgribble committed Dec 6, 2016
1 parent b6d6e02 commit 841fbfb
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 82 deletions.
10 changes: 2 additions & 8 deletions mfp/builtins/plot.py
Expand Up @@ -66,11 +66,6 @@ def draw_complete(self):
def grab(self):
MFPApp().gui_command.command(self.obj_id, "grab", None)

def conf(self, **kwargs):
for k, v in kwargs.items():
self.gui_params[k] = v
if self.gui_created:
MFPApp().gui_command.configure(self.obj_id, self.gui_params)

class Scatter (Processor):
doc_tooltip_obj = "Scatter plot for non-signal data points"
Expand Down Expand Up @@ -164,13 +159,12 @@ def clear(self, inlet=0):
def style(self, **kwargs):
'''Set style parameters for a curve'''
inlet = str(kwargs.get('inlet', 0))
style = self.gui_params.setdefault('style', {})
style = self.gui_params.get('style', {})
instyle = style.setdefault(inlet, {})
for k, v in kwargs.items():
if k != 'inlet':
instyle[k] = v
if self.gui_created:
MFPApp().gui_command.configure(self.obj_id, self.gui_params)
self.conf(style=style)
return True

def bounds(self, x_min, y_min, x_max, y_max):
Expand Down
9 changes: 2 additions & 7 deletions mfp/builtins/sendrcv.py
Expand Up @@ -128,9 +128,7 @@ def _connect(self, dest_name, dest_inlet, wait=True):
log.warning("[send] can't find dest object and not still looking")

self.init_args = '"%s",%s' % (self.dest_name, self.dest_inlet)
self.gui_params["label_text"] = self._mkdispname()
if self.gui_created:
MFPApp().gui_command.configure(self.obj_id, self.gui_params)
self.conf(label_text=self._mkdispname())

if self.inlets[0] is not Uninit:
self.trigger()
Expand Down Expand Up @@ -323,11 +321,8 @@ def trigger(self):
self.init_args = '"%s",%s' % (name, port)
self.src_name = name
self.src_outlet = port
self.gui_params["label_text"] = self._mkdispname()

self.conf(label_text = self._mkdispname())
self._connect(self.src_name, self.src_outlet)
if self.gui_created:
MFPApp().gui_command.configure(self.obj_id, self.gui_params)
self.inlets[1] = Uninit

if self.src_name and self.src_obj is None:
Expand Down
14 changes: 2 additions & 12 deletions mfp/builtins/var.py
Expand Up @@ -75,18 +75,9 @@ def trigger(self):
self.inlets[0] = Uninit
if (do_update and self.gui_params.get("update_required")
and ('value' not in self.gui_params or self.gui_params['value'] != self.value)):
self.gui_params['value'] = self.value

if self.gui_created:
MFPApp().gui_command.configure(self.obj_id, self.gui_params)
self.conf(value=self.value)
return True

def conf(self, **kwargs):
for k, v in kwargs.items():
self.gui_params[k] = v
if self.gui_created and self.gui_params.get("update_required"):
MFPApp().gui_command.configure(self.obj_id, self.gui_params)

def save(self):
base_dict = Processor.save(self)
if self.init_type != "message":
Expand Down Expand Up @@ -134,8 +125,7 @@ def trigger(self):

if do_update and self.gui_params.get("update_required"):
self.gui_params['value'] = self.value
if self.gui_created:
MFPApp().gui_command.configure(self.obj_id, self.gui_params)
self.conf(value=self.value)

def save(self):
return Processor.save(self)
Expand Down
11 changes: 7 additions & 4 deletions mfp/gui/patch_element.py
Expand Up @@ -274,14 +274,17 @@ def create(self, obj_type, init_args):

return self.obj_id

def send_params(self, **extras):
if self.obj_id is None:
return

def synced_params(self):
prms = {}
for k in self.param_list:
prms[k] = getattr(self, k)
return prms

def send_params(self, **extras):
if self.obj_id is None:
return

prms = self.synced_params()
for k, v in extras.items():
prms[k] = v

Expand Down
7 changes: 5 additions & 2 deletions mfp/gui/patch_info.py
Expand Up @@ -35,9 +35,12 @@ def has_scope(self, scope_name):
# FIXME - needs scopes for objects in scopes-not-default-for-layers
return scope_name in [l.scope for l in self.layers]

def send_params(self, **extras):
prms = dict(display_type=self.display_type, name=self.obj_name,
def synced_params(self):
return dict(display_type=self.display_type, name=self.obj_name,
layers=[(l.name, l.scope) for l in self.layers])

def send_params(self, **extras):
prms = self.synced_params()
for k, v in extras.items():
prms[k] = v
if self.obj_id is not None:
Expand Down
14 changes: 10 additions & 4 deletions mfp/gui_command.py
Expand Up @@ -60,15 +60,21 @@ def _command(self, obj_id, action, args):
obj.command(action, args)

@rpcwrap
def configure(self, obj_id, params):
def configure(self, obj_id, params=None, **kwparams):
from .gui_main import MFPGUI
MFPGUI().clutter_do(lambda: self._configure(obj_id, params))
MFPGUI().clutter_do(lambda: self._configure(obj_id, params, kwparams))
return True

def _configure(self, obj_id, params):
def _configure(self, obj_id, params, kwparams):
from .gui_main import MFPGUI
obj = MFPGUI().recall(obj_id)
obj.configure(params)
if params is not None:
obj.configure(params)
else:
prms = obj.synced_params()
for k, v in kwparams.items():
prms[k] = v
obj.configure(prms)

@rpcwrap
def create(self, obj_type, obj_args, obj_id, parent_id, params):
Expand Down
30 changes: 12 additions & 18 deletions mfp/patch.py
Expand Up @@ -455,9 +455,6 @@ def _run_onload(self, objects):

self.update_export_bounds()

if self.gui_created:
MFPApp().gui_command.configure(self.obj_id, self.gui_params)

if MFPApp().gui_command:
MFPApp().gui_command.load_complete()
return True
Expand Down Expand Up @@ -494,21 +491,18 @@ def update_export_bounds(self):
if max_y is None or (y+h > max_y):
max_y = y+h

if None in (min_x, min_y, max_x, max_y):
for p in ("export_x", "export_y", "export_w", "export_h"):
if p in self.gui_params:
del self.gui_params[p]
else:
self.gui_params["export_x"] = min_x
self.gui_params["export_y"] = min_y
self.gui_params["export_w"] = max_x - min_x + 2
self.gui_params["export_h"] = max_y - min_y + 2

# kludge
self.gui_params["width"] = max(self.gui_params.get('width'),
self.gui_params.get('export_w') or 0)
self.gui_params["height"] = max(self.gui_params.get('height'),
(self.gui_params.get('export_h') or 0) + 20)
x = y = w = h = None
if None not in (min_x, min_y, max_x, max_y):
x = min_x
y = min_y
w = max_x - min_x + 2
h = max_y - min_y + 2

self.conf(export_x=x, export_y=y, export_w=w, export_h=h,
width=max(self.gui_params.get('width'),
self.gui_params.get('export_w') or 0),
height=max(self.gui_params.get('height'),
(self.gui_params.get('export_h') or 0) + 20))

def create_export_gui(self):
from .mfp_app import MFPApp
Expand Down
2 changes: 0 additions & 2 deletions mfp/patch_clonescope.py
Expand Up @@ -146,8 +146,6 @@ def clonescope(self, scopename, num_copies, **kwargs):
srcobj.gui_params["value"] = srcobj.value

self.update_export_bounds()
if self.gui_created:
MFPApp().gui_command.configure(self.obj_id, self.gui_params)

if not MFPApp().no_onload:
self.task_nibbler.add_task(
Expand Down
33 changes: 8 additions & 25 deletions mfp/processor.py
Expand Up @@ -242,11 +242,8 @@ def assign(self, patch, scope, name):
self.name = name
self.patch = None

self.gui_params["name"] = self.name
self.gui_params["scope"] = self.scope.name
self.conf(name=self.name, scope=self.scope.name)
self.osc_init()
if self.gui_created:
MFPApp().gui_command.configure(self.obj_id, self.gui_params)
return self.name

def rename(self, new_name):
Expand Down Expand Up @@ -417,11 +414,7 @@ def dsp_init(self, proc_name, **params):
else:
log.warning("[dsp_init] No DSP context in %s (%s)",
self.name, proc_name)

self.gui_params['dsp_inlets'] = self.dsp_inlets
self.gui_params['dsp_outlets'] = self.dsp_outlets
if self.gui_created:
MFPApp().gui_command.configure(self.obj_id, self.gui_params)
self.conf(dsp_inlets=self.dsp_inlets, dsp_outlets=self.dsp_outlets)

def dsp_inlet(self, inlet):
return (self.dsp_obj, self.dsp_inlets.index(inlet))
Expand Down Expand Up @@ -512,11 +505,7 @@ def resize(self, inlets, outlets):
self.connections_out[outlets:] = []
self.outlet_order = range(len(self.outlets))

self.gui_params['num_inlets'] = inlets
self.gui_params['num_outlets'] = outlets

if self.gui_created:
MFPApp().gui_command.configure(self.obj_id, self.gui_params)
self.conf(num_inlets=inlets, num_outlets=outlets)

def connect(self, outlet, target, inlet, show_gui=True):
from .mfp_app import MFPApp
Expand Down Expand Up @@ -713,8 +702,6 @@ def reset_counts(self):
self.error_info = {}
self.count_trigger = 0
self.set_tag("errorcount", self.count_errors)
if self.gui_created:
MFPApp().gui_command.configure(self.obj_id, self.gui_params)

def error(self, msg=None, tb=None):
from .mfp_app import MFPApp
Expand Down Expand Up @@ -764,20 +751,16 @@ def conf(self, **kwargs):
for k, v in kwargs.items():
self.gui_params[k] = v
if self.gui_created:
MFPApp().gui_command.configure(self.obj_id, self.gui_params)
MFPApp().gui_command.configure(self.obj_id, **kwargs)

def set_tag(self, tag, value):
from .mfp_app import MFPApp
self.tags[tag] = value
self.gui_params["tags"] = self.tags
if self.gui_created:
MFPApp().gui_command.configure(self.obj_id, self.gui_params)
self.conf(tags=self.tags)

def set_style(self, tag, value):
from .mfp_app import MFPApp
self.gui_params["style"][tag] = value
if self.gui_created:
MFPApp().gui_command.configure(self.obj_id, self.gui_params)
oldstyle = self.gui_params.get('style', {})
oldstyle[tag] = value
self.conf(style=oldstyle)

def mark_ready(self):
self.status = Processor.READY
Expand Down

0 comments on commit 841fbfb

Please sign in to comment.