~spud/spud/copy-paste-fix

« back to all changes in this revision

Viewing changes to diamond/diamond/choice.py

  • Committer: Fraser Waters
  • Date: 2011-07-27 10:54:31 UTC
  • mfrom: (416.1.10 spud)
  • Revision ID: fraser.waters08@imperial.ac.uk-20110727105431-6jt3nzvu3ll5jtpz
Factor out handling clipboard for other widgets.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import StringIO
22
22
from lxml import etree
23
23
 
 
24
 
 
25
import gobject
 
26
 
24
27
import tree
25
28
 
26
 
class Choice:
 
29
class Choice(gobject.GObject):
 
30
 
 
31
  __gsignals__ = { "on-set-data" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (str,)),
 
32
                   "on-set-attr"  : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (str, str))}
 
33
 
27
34
  def __init__(self, l, cardinality=''):
 
35
    gobject.GObject.__init__(self)
 
36
 
28
37
    self.l = l
29
38
    if l == []:
30
39
      raise Exception
33
42
    for choice in l:
34
43
      assert choice.__class__ is tree.Tree
35
44
      name = name + choice.name + ":"
 
45
      choice.connect("on-set-data", self._on_set_data)
 
46
      choice.connect("on-set-attr", self._on_set_attr)
 
47
 
36
48
    name = name[:-1]
37
49
    self.name = name
38
50
    self.schemaname = name
40
52
    self.parent = None
41
53
    self.set_default_active()
42
54
 
 
55
  def _on_set_data(self, node, data):
 
56
    self.emit("on-set-data", data)
 
57
 
 
58
  def _on_set_attr(self, node, attr, value):
 
59
    self.emit("on-set-attr", attr, value)
 
60
 
43
61
  def set_default_active(self):
44
62
    self.active = True
45
63
    if self.cardinality == '?' or self.cardinality == '*':
115
133
 
116
134
  def choices(self):
117
135
    return self.l
 
136
 
 
137
  def is_comment(self):
 
138
    return False
 
139
 
 
140
  def get_comment(self):
 
141
    return None
 
142
 
 
143
  def get_display_name(self):
 
144
    """
 
145
    This is a fluidity hack, allowing the name displayed in the treeview on the
 
146
    left to be different to the element name. If it has an attribute name="xxx",
 
147
    element_tag (xxx) is displayed.
 
148
    """
 
149
 
 
150
    return self.get_current_tree().get_display_name()
 
151
 
 
152
  def get_name(self):
 
153
    return self.get_current_tree().get_name()
 
154
 
 
155
  def get_children(self):
 
156
    return [self.get_current_tree()]
 
157
 
 
158
  def get_choices(self):
 
159
    return self.l
 
160
 
 
161
  def is_hidden(self):
 
162
    """
 
163
    Tests whether the supplied choice should be hidden in view.
 
164
    """
 
165
    return False
 
166
 
 
167
  def get_name_path(self, leaf = True):
 
168
    name = self.get_display_name() if leaf else self.get_name()
 
169
 
 
170
    if self.parent is None:
 
171
      return name
 
172
    else:
 
173
 
 
174
      pname = self.parent.get_name_path(False)
 
175
 
 
176
      if name is None:
 
177
        return pname
 
178
      elif pname is None:
 
179
        return name
 
180
      else:
 
181
        return pname + "/" + name
 
182
 
 
183
  def get_mixed_data(self):
 
184
    return self
 
185
 
 
186
  def is_sliceable(self):
 
187
    return self.get_current_tree().is_sliceable()
 
188
 
 
189
  def __str__(self):
 
190
    """
 
191
    Returns the display name of the selected tree.
 
192
    """
 
193
    return self.get_display_name()
 
194
 
 
195
gobject.type_register(Choice)