~sjdv1982/hivesystem/trunk

« back to all changes in this revision

Viewing changes to hiveguilib/PQt/PGenerator.py

  • Committer: Sjoerd de Vries
  • Date: 2014-06-09 10:19:38 UTC
  • mfrom: (182.1.43 hive-view)
  • Revision ID: sjdv1982@gmail.com-20140609101938-7ji5g0buo09r0se6
merged with hive-view branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
      del params2[kk]
35
35
  callback(params2)
36
36
 
37
 
  
 
37
def viewupdate(m,con,*args):  
 
38
  status = m._status(con)
 
39
  if hasattr(m, "_old_status") and status == m._old_status: return
 
40
  if status == "Status: OK" and not hasattr(m, "_old_status"):
 
41
    pass
 
42
  else:
 
43
    print(status)
 
44
  m._old_status = status  
 
45
 
 
46
 
38
47
def PGenerator(paramnames, paramtypelist, paramvalues, 
39
 
  update_callback, buttons = []
 
48
  update_callback, buttons = [], form_manipulators = []
40
49
 ):
41
50
  global loader
42
51
  if loader is None: loader = QUiLoader()
50
59
      paramnames2 = [p if p != k else k + "_" for p in paramnames2]
51
60
 
52
61
  params = list(zip(paramnames2, paramtypelist))
53
 
  #print("PARAMS", params)
54
62
  typetree = spyder.formtools.generate_typetree(params,typemap)
55
 
  #print("TYPETREE", typetree)
56
63
  form = spyder.core.spyderform(typetree)  
57
 
  #print("SUBFORM", form.type_, form.type_.__dict__)
58
 
  """
59
 
  #option 1: add the current values as defaults to the form (doesn't work well)
60
 
  for pname,pvalue in paramvalues.items():
61
 
    pname2 = pname
62
 
    if pname in reserved: pname2 = pname + "_"
63
 
    if pvalue is not None:
64
 
      form._members[pname2].value = pvalue
65
 
  """    
66
64
  for subform in form._members.values():
67
65
    if subform.arraycount:
68
66
      subform.length = 10
69
67
  for buttonname, buttoncallback in buttons:
70
 
    form.add_button(buttonname, "after")
71
 
       
 
68
    form.add_button(buttonname, "before")
 
69
  
 
70
  for form_manipulator in form_manipulators: 
 
71
    ret = form_manipulator(form)
 
72
    if ret is not None: form = ret
 
73
    
72
74
  m = model(typetree)
73
75
  con = controller(form, m)  
74
76
  
110
112
  #listen for model updates
111
113
  con._listen()
112
114
  
113
 
  #set the current values into the model
114
 
  for pname,pvalue in paramvalues.items():
115
 
    #print("PARAMV", pname, pvalue)
116
 
    pname2 = pname
117
 
    if pname in reserved: pname2 = pname + "_"
118
 
    if pvalue is not None:
119
 
      getattr(con,pname2)._set(pvalue)
 
115
  if not len(paramvalues):
 
116
    #if there are no current param values, load the form defaults into the model
 
117
    con._sync_from_view()
 
118
  else:  
 
119
    #else, set the current values into the model
 
120
    for pname,pvalue in paramvalues.items():
 
121
      pname2 = pname
 
122
      if pname in reserved: pname2 = pname + "_"
 
123
      if pvalue is not None:
 
124
        getattr(m,pname2)._set(pvalue)
120
125
  
121
126
  #synchronize
122
127
  con._sync_to_view()
123
 
  con._sync_from_view() 
124
128
  
125
129
  for pname in paramnames:
126
130
    pname2 = pname
144
148
  if contains_reserved: up = functools.partial(remap_reserved, update_callback)
145
149
  m._listen(up)
146
150
  
 
151
  con._sync_from_view()
 
152
  v.listen(functools.partial(viewupdate, m, con))
 
153
 
147
154
  return parwidget, con