annotate clients/editor/plugins/objectselector.py @ 231:c62ed457e954

Case-insensitive multi-word search
author cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
date Sat, 21 Mar 2009 23:26:09 +0000
parents 664d7c2530e4
children 45c63a621366
rev   line source
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
1 # coding: utf-8
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
2
229
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
3 import pychan
225
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
4 from pychan import widgets, tools, attrs, internal
229
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
5 from pychan.tools import callbackWithArguments
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
6 import fife
225
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
7 from fife import Color
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
8
224
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
9 # TODO:
229
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
10 # - Better event handling
225
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
11 # - Label background color can't be set
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
12
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
13 _DEFAULT_BASE_COLOR = internal.DEFAULT_STYLE['default']['base_color']
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
14 _DEFAULT_SELECTION_COLOR = internal.DEFAULT_STYLE['default']['selection_color']
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
15 _DEFAULT_COLOR_STEP = Color(10, 10, 10)
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
16
224
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
17 class ObjectIcon(widgets.VBox):
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
18 """ The ObjectIcon is used to represent the object in the object selector.
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
19 """
225
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
20 ATTRIBUTES = widgets.VBox.ATTRIBUTES + [ attrs.Attr("text"), attrs.Attr("image"), attrs.BoolAttr("selected") ]
224
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
21
225
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
22 def __init__(self,callback,**kwargs):
227
d642169490f7 * Happy birthday, LinuxDonald! *
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 225
diff changeset
23 super(ObjectIcon,self).__init__(**kwargs)
224
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
24
225
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
25 self.callback = callback
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
26
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
27 self.capture(self._mouseEntered, "mouseEntered")
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
28 self.capture(self._mouseExited, "mouseExited")
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
29 self.capture(self._mouseClicked, "mouseClicked")
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
30
224
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
31 vbox = widgets.VBox(padding=3)
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
32
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
33 # Icon
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
34 self.icon = widgets.Icon(**kwargs)
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
35 self.addChild(self.icon)
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
36
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
37 # Label
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
38 hbox = widgets.HBox(padding=1)
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
39 self.addChild(hbox)
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
40 self.label = widgets.Label(**kwargs)
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
41 hbox.addChild(self.label)
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
42
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
43 def _setText(self, text):
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
44 self.label.text = text
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
45
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
46 def _getText(self):
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
47 return self.label.text
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
48 text = property(_getText, _setText)
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
49
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
50 def _setImage(self, image):
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
51 self.icon.image = image
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
52
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
53 def _getImage(self):
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
54 return self.icon.image
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
55 image = property(_getImage, _setImage)
225
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
56
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
57 def _setSelected(self, enabled):
227
d642169490f7 * Happy birthday, LinuxDonald! *
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 225
diff changeset
58 if isinstance(self.parent, ObjectIconList):
d642169490f7 * Happy birthday, LinuxDonald! *
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 225
diff changeset
59 if enabled == True:
d642169490f7 * Happy birthday, LinuxDonald! *
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 225
diff changeset
60 self.parent.selected_item = self
d642169490f7 * Happy birthday, LinuxDonald! *
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 225
diff changeset
61 else:
d642169490f7 * Happy birthday, LinuxDonald! *
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 225
diff changeset
62 if self.selected:
d642169490f7 * Happy birthday, LinuxDonald! *
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 225
diff changeset
63 self.parent.selected_item = None
225
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
64
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
65 # + Color(0,0,0) to force variable copy
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
66 if self.selected:
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
67 self.base_color = _DEFAULT_SELECTION_COLOR + Color(0,0,0)
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
68 else:
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
69 self.base_color = _DEFAULT_BASE_COLOR + Color(0,0,0)
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
70
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
71 def _isSelected(self):
227
d642169490f7 * Happy birthday, LinuxDonald! *
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 225
diff changeset
72 if isinstance(self.parent, ObjectIconList):
d642169490f7 * Happy birthday, LinuxDonald! *
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 225
diff changeset
73 return self == self.parent.selected_item
d642169490f7 * Happy birthday, LinuxDonald! *
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 225
diff changeset
74 return False
225
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
75 selected = property(_isSelected, _setSelected)
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
76
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
77 #--- Event handling ---#
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
78 def _mouseEntered(self, event):
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
79 self.base_color += _DEFAULT_COLOR_STEP
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
80
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
81 def _mouseExited(self, event):
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
82 self.base_color -= _DEFAULT_COLOR_STEP
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
83
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
84 def _mouseClicked(self, event):
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
85 self.selected = True
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
86 self.callback()
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
87
227
d642169490f7 * Happy birthday, LinuxDonald! *
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 225
diff changeset
88 class ObjectIconList(widgets.VBox):
229
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
89 ATTRIBUTES = widgets.VBox.ATTRIBUTES
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
90
227
d642169490f7 * Happy birthday, LinuxDonald! *
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 225
diff changeset
91 def __init__(self,**kwargs):
d642169490f7 * Happy birthday, LinuxDonald! *
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 225
diff changeset
92 super(ObjectIconList, self).__init__(max_size=(5000,500000), **kwargs)
d642169490f7 * Happy birthday, LinuxDonald! *
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 225
diff changeset
93 self.base_color = self.background_color
d642169490f7 * Happy birthday, LinuxDonald! *
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 225
diff changeset
94
d642169490f7 * Happy birthday, LinuxDonald! *
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 225
diff changeset
95 # TODO: Pychan doesn't support keyevents for nonfocusable widgets, yet
229
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
96 #self.capture(self._keyPressed, "keyPressed")
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
97 #self.capture(self._keyPressed, "keyReleased")
227
d642169490f7 * Happy birthday, LinuxDonald! *
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 225
diff changeset
98 self._selectedItem = None
d642169490f7 * Happy birthday, LinuxDonald! *
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 225
diff changeset
99
229
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
100 #def _keyPressed(self, event):
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
101 #print "KeyEvent", event
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
102
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
103 def clear(self):
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
104 count = 0
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
105 for c in reversed(self.children):
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
106 self.removeChild(c)
227
d642169490f7 * Happy birthday, LinuxDonald! *
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 225
diff changeset
107
d642169490f7 * Happy birthday, LinuxDonald! *
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 225
diff changeset
108 def _setSelectedItem(self, item):
d642169490f7 * Happy birthday, LinuxDonald! *
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 225
diff changeset
109 if isinstance(item, ObjectIcon) or item is None:
d642169490f7 * Happy birthday, LinuxDonald! *
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 225
diff changeset
110 if self._selectedItem is not None:
d642169490f7 * Happy birthday, LinuxDonald! *
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 225
diff changeset
111 tmp = self._selectedItem
d642169490f7 * Happy birthday, LinuxDonald! *
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 225
diff changeset
112 self._selectedItem = item
d642169490f7 * Happy birthday, LinuxDonald! *
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 225
diff changeset
113 tmp.selected = False
d642169490f7 * Happy birthday, LinuxDonald! *
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 225
diff changeset
114 else:
229
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
115 self._selectedItem = item
227
d642169490f7 * Happy birthday, LinuxDonald! *
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 225
diff changeset
116
d642169490f7 * Happy birthday, LinuxDonald! *
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 225
diff changeset
117 def _getSelectedItem(self):
d642169490f7 * Happy birthday, LinuxDonald! *
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 225
diff changeset
118 return self._selectedItem
d642169490f7 * Happy birthday, LinuxDonald! *
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 225
diff changeset
119 selected_item = property(_getSelectedItem, _setSelectedItem)
225
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
120
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
121 class ObjectSelector(object):
192
bec4b69ad83a * Redid the editor's ObjectSelector to display previews for all objects instead of only 1 preview + paths/filenames
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 71
diff changeset
122 """The ObjectSelector class offers a gui Widget that let's you select the object you
bec4b69ad83a * Redid the editor's ObjectSelector to display previews for all objects instead of only 1 preview + paths/filenames
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 71
diff changeset
123 wish to use to in the editor.
bec4b69ad83a * Redid the editor's ObjectSelector to display previews for all objects instead of only 1 preview + paths/filenames
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 71
diff changeset
124 @param engine: fife instance
bec4b69ad83a * Redid the editor's ObjectSelector to display previews for all objects instead of only 1 preview + paths/filenames
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 71
diff changeset
125 @param map: fife.Map instance containing your map
bec4b69ad83a * Redid the editor's ObjectSelector to display previews for all objects instead of only 1 preview + paths/filenames
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 71
diff changeset
126 @param selectNotify: callback function used to tell the editor you selected an object.
bec4b69ad83a * Redid the editor's ObjectSelector to display previews for all objects instead of only 1 preview + paths/filenames
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 71
diff changeset
127 """
bec4b69ad83a * Redid the editor's ObjectSelector to display previews for all objects instead of only 1 preview + paths/filenames
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 71
diff changeset
128 def __init__(self, engine, map, selectNotify):
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
129 self.engine = engine
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
130 self.map = map
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
131 self.notify = selectNotify
194
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
132 self.mode = 'list' # Other mode is 'preview'
192
bec4b69ad83a * Redid the editor's ObjectSelector to display previews for all objects instead of only 1 preview + paths/filenames
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 71
diff changeset
133
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
134 self.buildGui()
192
bec4b69ad83a * Redid the editor's ObjectSelector to display previews for all objects instead of only 1 preview + paths/filenames
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 71
diff changeset
135
229
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
136
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
137 def buildGui(self):
229
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
138 self.gui = pychan.loadXML('gui/objectselector.xml')
192
bec4b69ad83a * Redid the editor's ObjectSelector to display previews for all objects instead of only 1 preview + paths/filenames
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 71
diff changeset
139
229
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
140 # Add search field
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
141 self._searchfield = self.gui.findChild(name="searchField")
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
142 self._searchfield.capture(self._search)
230
664d7c2530e4 Incremental search for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 229
diff changeset
143 self._searchfield.capture(self._search, "keyPressed")
229
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
144 self.gui.findChild(name="searchButton").capture(self._search)
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
145
217
68ae8f4234ca * More compact ObjectSelector dialog
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 198
diff changeset
146 # Add the drop down with list of namespaces
229
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
147 self.namespaces = self.gui.findChild(name="namespaceDropdown")
192
bec4b69ad83a * Redid the editor's ObjectSelector to display previews for all objects instead of only 1 preview + paths/filenames
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 71
diff changeset
148 self.namespaces.items = self.engine.getModel().getNamespaces()
bec4b69ad83a * Redid the editor's ObjectSelector to display previews for all objects instead of only 1 preview + paths/filenames
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 71
diff changeset
149 self.namespaces.selected = 0
bec4b69ad83a * Redid the editor's ObjectSelector to display previews for all objects instead of only 1 preview + paths/filenames
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 71
diff changeset
150
224
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
151 # TODO: Replace with SelectionEvent, once pychan supports it
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
152 self.namespaces.capture(self.update_namespace, "action")
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
153 self.namespaces.capture(self.update_namespace, "mouseWheelMovedUp")
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
154 self.namespaces.capture(self.update_namespace, "mouseWheelMovedDown")
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
155 self.namespaces.capture(self.update_namespace, "keyReleased")
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
156
229
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
157 # Object list
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
158 self.mainScrollArea = self.gui.findChild(name="mainScrollArea")
194
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
159 self.objects = None
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
160 if self.mode == 'list':
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
161 self.setTextList()
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
162 else: # Assuming self.mode is 'preview'
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
163 self.setImageList()
229
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
164
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
165 # Action buttons
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
166 self.gui.findChild(name="toggleModeButton").capture(self.toggleMode)
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
167 self.gui.findChild(name="closeButton").capture(self.hide)
194
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
168
229
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
169 # Preview area
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
170 self.gui.findChild(name="previewScrollArea").background_color = self.gui.base_color
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
171 self.preview = self.gui.findChild(name="previewIcon")
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
172
217
68ae8f4234ca * More compact ObjectSelector dialog
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 198
diff changeset
173
194
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
174 def toggleMode(self):
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
175 if self.mode == 'list':
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
176 self.setImageList()
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
177 self.mode = 'preview'
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
178 elif self.mode == 'preview':
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
179 self.setTextList()
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
180 self.mode = 'list'
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
181 self.update()
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
182
194
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
183
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
184 def setImageList(self):
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
185 """Sets the mainScrollArea to contain a Vbox that can be used to fill in
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
186 preview Images"""
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
187 if self.objects is not None:
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
188 self.mainScrollArea.removeChild(self.objects)
227
d642169490f7 * Happy birthday, LinuxDonald! *
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 225
diff changeset
189 self.objects = ObjectIconList(name='list', size=(200,1000))
224
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
190 self.objects.base_color = self.mainScrollArea.background_color
194
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
191 self.mainScrollArea.addChild(self.objects)
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
192
194
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
193 def setTextList(self):
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
194 """Sets the mainScrollArea to contain a List that can be used to fill in
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
195 Object names/paths"""
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
196 if self.objects is not None:
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
197 self.mainScrollArea.removeChild(self.objects)
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
198 self.objects = widgets.ListBox(name='list')
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
199 self.objects.capture(self.listEntrySelected)
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
200 self.mainScrollArea.addChild(self.objects)
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
201
229
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
202 def _search(self):
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
203 self.search(self._searchfield.text)
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
204
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
205 def search(self, str):
231
c62ed457e954 Case-insensitive multi-word search
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 230
diff changeset
206 results = []
c62ed457e954 Case-insensitive multi-word search
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 230
diff changeset
207
c62ed457e954 Case-insensitive multi-word search
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 230
diff changeset
208 # Format search terms
c62ed457e954 Case-insensitive multi-word search
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 230
diff changeset
209 terms = [term.lower() for term in str.split()]
c62ed457e954 Case-insensitive multi-word search
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 230
diff changeset
210
c62ed457e954 Case-insensitive multi-word search
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 230
diff changeset
211 # Search
c62ed457e954 Case-insensitive multi-word search
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 230
diff changeset
212 if len(terms) > 0:
c62ed457e954 Case-insensitive multi-word search
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 230
diff changeset
213 namespaces = self.engine.getModel().getNamespaces()
c62ed457e954 Case-insensitive multi-word search
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 230
diff changeset
214 for namesp in namespaces:
c62ed457e954 Case-insensitive multi-word search
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 230
diff changeset
215 objects = self.engine.getModel().getObjects(namesp)
c62ed457e954 Case-insensitive multi-word search
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 230
diff changeset
216 for obj in objects:
c62ed457e954 Case-insensitive multi-word search
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 230
diff changeset
217 doAppend = True
c62ed457e954 Case-insensitive multi-word search
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 230
diff changeset
218 for term in terms:
c62ed457e954 Case-insensitive multi-word search
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 230
diff changeset
219 if obj.getId().lower().find(term) < 0:
c62ed457e954 Case-insensitive multi-word search
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 230
diff changeset
220 doAppend = False
c62ed457e954 Case-insensitive multi-word search
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 230
diff changeset
221 break
c62ed457e954 Case-insensitive multi-word search
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 230
diff changeset
222 if doAppend:
c62ed457e954 Case-insensitive multi-word search
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 230
diff changeset
223 results.append(obj)
c62ed457e954 Case-insensitive multi-word search
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 230
diff changeset
224 else:
c62ed457e954 Case-insensitive multi-word search
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 230
diff changeset
225 results = None
229
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
226
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
227 if self.mode == 'list':
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
228 self.fillTextList(results)
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
229 elif self.mode == 'preview':
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
230 self.fillPreviewList(results)
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
231
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
232 def fillTextList(self, objects=None):
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
233 if objects is None:
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
234 objects = self.engine.getModel().getObjects(self.namespaces.selected_item)
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
235
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
236 class _ListItem:
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
237 def __init__( self, name, namespace ):
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
238 self.name = name
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
239 self.namespace = namespace
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
240 def __str__( self ):
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
241 return self.name
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
242
194
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
243 if self.namespaces.selected_item:
229
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
244 self.objects.items = [_ListItem(obj.getId(), obj.getNamespace()) for obj in objects]
194
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
245 if not self.objects.selected_item:
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
246 self.objects.selected = 0
198
c344836f4210 * Hopefully fixed the editor's objectselector to work with multiple namespaces again
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 195
diff changeset
247 self.listEntrySelected()
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
248
194
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
249 def listEntrySelected(self):
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
250 """This function is used as callback for the TextList."""
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
251 if self.objects.selected_item:
229
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
252 object_id = self.objects.selected_item.name
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
253 namespace = self.objects.selected_item.namespace
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
254 obj = self.engine.getModel().getObject(object_id, namespace)
194
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
255 self.objectSelected(obj)
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
256
229
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
257 def fillPreviewList(self, objects=None):
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
258 self.objects.clear()
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
259
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
260 if objects is None:
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
261 objects = self.engine.getModel().getObjects(self.namespaces.selected_item)
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
262
198
c344836f4210 * Hopefully fixed the editor's objectselector to work with multiple namespaces again
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 195
diff changeset
263 for obj in objects:
194
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
264 image = self._getImage(obj)
224
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
265 if image is None:
192
bec4b69ad83a * Redid the editor's ObjectSelector to display previews for all objects instead of only 1 preview + paths/filenames
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 71
diff changeset
266 print 'No image available for selected object'
224
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
267 image = ""
225
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
268
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
269 callback = tools.callbackWithArguments(self.objectSelected, obj)
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
270 icon = ObjectIcon(callback=callback, image=image, text=obj.getId())
224
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
271 self.objects.addChild(icon)
567863be0abc * First version of previewmode icons in ObjectSelector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 217
diff changeset
272
198
c344836f4210 * Hopefully fixed the editor's objectselector to work with multiple namespaces again
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 195
diff changeset
273 if len(objects)>0:
225
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
274 objects[0].selected = True
198
c344836f4210 * Hopefully fixed the editor's objectselector to work with multiple namespaces again
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 195
diff changeset
275 self.objectSelected(objects[0])
c344836f4210 * Hopefully fixed the editor's objectselector to work with multiple namespaces again
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 195
diff changeset
276
192
bec4b69ad83a * Redid the editor's ObjectSelector to display previews for all objects instead of only 1 preview + paths/filenames
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 71
diff changeset
277
bec4b69ad83a * Redid the editor's ObjectSelector to display previews for all objects instead of only 1 preview + paths/filenames
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 71
diff changeset
278 def objectSelected(self, obj):
bec4b69ad83a * Redid the editor's ObjectSelector to display previews for all objects instead of only 1 preview + paths/filenames
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 71
diff changeset
279 """This is used as callback function to notify the editor that a new object has
bec4b69ad83a * Redid the editor's ObjectSelector to display previews for all objects instead of only 1 preview + paths/filenames
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 71
diff changeset
280 been selected.
bec4b69ad83a * Redid the editor's ObjectSelector to display previews for all objects instead of only 1 preview + paths/filenames
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 71
diff changeset
281 @param obj: fife.Object instance"""
225
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
282
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
283 # Set preview image
194
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
284 self.preview.image = self._getImage(obj)
217
68ae8f4234ca * More compact ObjectSelector dialog
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 198
diff changeset
285 height = self.preview.image.getHeight();
68ae8f4234ca * More compact ObjectSelector dialog
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 198
diff changeset
286 if height > 200: height = 200
68ae8f4234ca * More compact ObjectSelector dialog
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 198
diff changeset
287 self.preview._getParent()._setHeight(height)
225
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
288
195
13e5be34484e * Fixed a minor bug with the preview picture in the ObjectSelector
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 194
diff changeset
289 self.gui.adaptLayout()
192
bec4b69ad83a * Redid the editor's ObjectSelector to display previews for all objects instead of only 1 preview + paths/filenames
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 71
diff changeset
290 self.notify(obj)
bec4b69ad83a * Redid the editor's ObjectSelector to display previews for all objects instead of only 1 preview + paths/filenames
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 71
diff changeset
291
225
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
292 self.objects.adaptLayout()
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
293 self.gui.adaptLayout()
1beb7a3692f4 Implemented selection and hover highlighting for ObjectItems
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 224
diff changeset
294
198
c344836f4210 * Hopefully fixed the editor's objectselector to work with multiple namespaces again
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 195
diff changeset
295 def update_namespace(self):
194
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
296 self.namespaces.items = self.engine.getModel().getNamespaces()
198
c344836f4210 * Hopefully fixed the editor's objectselector to work with multiple namespaces again
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 195
diff changeset
297 if not self.namespaces.selected_item:
c344836f4210 * Hopefully fixed the editor's objectselector to work with multiple namespaces again
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 195
diff changeset
298 self.namespaces.selected = 0
c344836f4210 * Hopefully fixed the editor's objectselector to work with multiple namespaces again
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 195
diff changeset
299 if self.mode == 'list':
c344836f4210 * Hopefully fixed the editor's objectselector to work with multiple namespaces again
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 195
diff changeset
300 self.setTextList()
c344836f4210 * Hopefully fixed the editor's objectselector to work with multiple namespaces again
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 195
diff changeset
301 elif self.mode == 'preview':
c344836f4210 * Hopefully fixed the editor's objectselector to work with multiple namespaces again
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 195
diff changeset
302 self.setImageList()
c344836f4210 * Hopefully fixed the editor's objectselector to work with multiple namespaces again
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 195
diff changeset
303 self.update()
c344836f4210 * Hopefully fixed the editor's objectselector to work with multiple namespaces again
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 195
diff changeset
304
c344836f4210 * Hopefully fixed the editor's objectselector to work with multiple namespaces again
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 195
diff changeset
305 def update(self):
194
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
306 if self.mode == 'list':
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
307 self.fillTextList()
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
308 elif self.mode == 'preview':
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
309 self.fillPreviewList()
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
310
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
311 self.mainScrollArea.resizeToContent()
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
312
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
313 def _getImage(self, obj):
229
9a2cd4c46a61 * Search functionality for object selector
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 227
diff changeset
314 """ Returns an image for the given object.
194
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
315 @param: fife.Object for which an image is to be returned
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
316 @return: fife.GuiImage"""
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
317 visual = None
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
318 try:
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
319 visual = obj.get2dGfxVisual()
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
320 except:
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
321 print 'Visual Selection created for type without a visual?'
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
322 raise
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
323
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
324 # Try to find a usable image
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
325 index = visual.getStaticImageIndexByAngle(0)
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
326 image = None
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
327 # if no static image available, try default action
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
328 if index == -1:
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
329 action = obj.getDefaultAction()
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
330 if action:
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
331 animation_id = action.get2dGfxVisual().getAnimationIndexByAngle(0)
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
332 animation = self.engine.getAnimationPool().getAnimation(animation_id)
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
333 image = animation.getFrameByTimestamp(0)
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
334 index = image.getPoolId()
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
335
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
336 # Construct the new GuiImage that is to be returned
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
337 if index != -1:
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
338 image = fife.GuiImage(index, self.engine.getImagePool())
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
339
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
340 return image
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
341
9631a2958851 * Object selector can now be toggled to use either the old list format or show preview images.
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 192
diff changeset
342
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
343 def show(self):
198
c344836f4210 * Hopefully fixed the editor's objectselector to work with multiple namespaces again
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 195
diff changeset
344 self.update_namespace()
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
345 self.gui.show()
192
bec4b69ad83a * Redid the editor's ObjectSelector to display previews for all objects instead of only 1 preview + paths/filenames
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 71
diff changeset
346
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
347 def hide(self):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
348 self.gui.hide()