annotate clients/editor/plugins/objectselector.py @ 211:f10a2e78a0e1

- updated objectedit plugin, should work much better now - removed data records from objectedit plugin (way too buggy & ugly) - removed obsolete plugin data from settings.py NOTE: - the sliders for offset manipulation don't work ATM
author chewie@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 16 Mar 2009 14:40:36 +0000
parents c344836f4210
children 68ae8f4234ca
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
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
3 from pychan import widgets, tools
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
4 import fife
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
5
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
6 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
7 """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
8 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
9 @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
10 @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
11 @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
12 """
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
13 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
14 self.engine = engine
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
15 self.map = map
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
16 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
17 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
18
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
19 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
20
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
21 def buildGui(self):
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
22 # Create the main Window
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
23 self.gui = widgets.Window(title="Object selector")
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
24 hbox = widgets.HBox()
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
25 self.gui.addChild(hbox)
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
26
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
27 # Add the Scrollarea with list of namespaces
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
28 scrollArea = widgets.ScrollArea(size=(200,300))
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
29 hbox.addChild(scrollArea)
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
30 self.namespaces = widgets.ListBox()
198
c344836f4210 * Hopefully fixed the editor's objectselector to work with multiple namespaces again
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 195
diff changeset
31 self.namespaces.capture(self.update_namespace)
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
32 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
33 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
34 scrollArea.addChild(self.namespaces)
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
35
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
36 # This Vbox is used to display the preview images
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
37 self.mainScrollArea = widgets.ScrollArea(size=(200,300))
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
38 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
39 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
40 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
41 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
42 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
43 hbox.addChild(self.mainScrollArea)
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
44
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
45 # This is the preview area
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
46 scrollArea = widgets.ScrollArea(size=(200,300))
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
47 hbox.addChild(scrollArea)
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
48 self.preview = widgets.Icon()
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
49 scrollArea.addChild(self.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
50
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
51 # Add another Hbox to hold the close button
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
52 hbox = widgets.HBox(parent=self.gui)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
53 self.gui.addChild(hbox)
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
54 hbox.addSpacer(widgets.Spacer())
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
55 toggleButton = widgets.Button(text="Toggle Preview Mode")
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
56 toggleButton.capture(self.toggleMode)
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
57 hbox.addChild(toggleButton)
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
58 closeButton = widgets.Button(text="Close")
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
59 closeButton.capture(self.hide)
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
60 hbox.addChild(closeButton)
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
61
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
62 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
63 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
64 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
65 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
66 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
67 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
68 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
69 self.update()
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
70
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
71
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
72 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
73 """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
74 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
75 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
76 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
77 self.objects = widgets.VBox(name='list', size=(200,300))
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
78 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
79
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
80 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
81 """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
82 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
83 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
84 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
85 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
86 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
87 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
88
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
89 def fillTextList(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
90 if self.namespaces.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
91 self.objects.items = [obj.getId() for obj in self.engine.getModel().getObjects(self.namespaces.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
92 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
93 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
94 self.listEntrySelected()
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
95
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
96 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
97 """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
98 if 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
99 obj = self.engine.getModel().getObject(self.objects.selected_item, self.namespaces.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
100 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
101
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
102 def fillPreviewList(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
103 objects = self.engine.getModel().getObjects(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
104 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
105 image = self._getImage(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
106 if image is not 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
107 imagebutton = widgets.ImageButton(up_image=image, down_image=image, hover_image=image)
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
108 imagebutton.capture(tools.callbackWithArguments(self.objectSelected, 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
109 self.objects.addChild(imagebutton)
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
110 self.objects._recursiveResizeToContent()
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
111 self.gui.adaptLayout()
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
112 else:
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
113 print 'No image available for selected object'
198
c344836f4210 * Hopefully fixed the editor's objectselector to work with multiple namespaces again
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 195
diff changeset
114 if len(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
115 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
116
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
117
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
118 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
119 """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
120 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
121 @param obj: fife.Object instance"""
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
122 self.preview.image = self._getImage(obj)
195
13e5be34484e * Fixed a minor bug with the preview picture in the ObjectSelector
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 194
diff changeset
123 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
124 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
125
198
c344836f4210 * Hopefully fixed the editor's objectselector to work with multiple namespaces again
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 195
diff changeset
126 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
127 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
128 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
129 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
130 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
131 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
132 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
133 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
134 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
135
c344836f4210 * Hopefully fixed the editor's objectselector to work with multiple namespaces again
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 195
diff changeset
136 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
137 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
138 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
139 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
140 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
141
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
142 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
143
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
144 def _getImage(self, 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
145 """ Returs an image for the given object.
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
146 @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
147 @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
148 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
149 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
150 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
151 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
152 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
153 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
154
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
155 # 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
156 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
157 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
158 # 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
159 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
160 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
161 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
162 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
163 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
164 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
165 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
166
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
167 # 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
168 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
169 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
170
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
171 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
172
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
173
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
174 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
175 self.update_namespace()
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
176 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
177
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
178 def hide(self):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
179 self.gui.hide()