/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/UI/selection.py
ViewVC logotype

Annotation of /branches/WIP-pyshapelib-bramz/Thuban/UI/selection.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 535 - (hide annotations)
Fri Mar 14 20:42:18 2003 UTC (21 years, 11 months ago) by bh
Original Path: trunk/thuban/Thuban/UI/selection.py
File MIME type: text/x-python
File size: 5624 byte(s)
Implement multiple selected shapes

* Thuban/UI/selection.py: New module with a class to represent the
selection.

* Thuban/UI/messages.py (SELECTED_TABLE, SELECTED_MAP): Remove
these unused messages

* Thuban/UI/application.py (ThubanApplication.OnInit)
(ThubanApplication.OnExit, ThubanApplication.SetSession): The
interactor is gone now.
(ThubanApplication.CreateMainWindow): There is no interactor
anymore so we pass None as the interactor argument for now for
compatibility.

* Thuban/UI/view.py (MapCanvas.delegated_messages)
(MapCanvas.Subscribe, MapCanvas.Unsubscribe): In Subscribe and
Unsubscribe, delegate messages according to the delegated_messages
class variable.
(MapCanvas.__getattr__, MapCanvas.delegated_methods): Get some
attributes from instance variables as described with the
delegated_methods class variable.
(MapCanvas.__init__): New instance variable selection holding the
current selection
(MapCanvas.do_redraw): Deal with multiple selected shapes. Simply
pass them on to the renderer
(MapCanvas.SetMap): Clear the selection when a different map is
selected.
(MapCanvas.shape_selected): Simple force a complete redraw. The
selection class now takes care of only issueing SHAPES_SELECTED
messages when the set of selected shapes actually does change.
(MapCanvas.SelectShapeAt): The selection is now managed in
self.selection

* Thuban/UI/mainwindow.py (MainWindow.delegated_messages)
(MainWindow.Subscribe, MainWindow.Unsubscribe): In Subscribe and
Unsubscribe, delegate messages according to the delegated_messages
class variable.
(MainWindow.delegated_methods, MainWindow.__getattr__): Get some
attributes from instance variables as described with the
delegated_methods class variable.
(MainWindow.__init__): The interactor as ivar is gone. The
parameter is still there for compatibility. The selection messages
now come from the canvas.
(MainWindow.current_layer, MainWindow.has_selected_layer):
Delegate to the the canvas.
(MainWindow.LayerShowTable, MainWindow.Classify)
(MainWindow.identify_view_on_demand): The dialogs don't need the
interactor parameter anymore.

* Thuban/UI/tableview.py (TableFrame.__init__)
(LayerTableFrame.__init__, LayerTableFrame.OnClose)
(LayerTableFrame.row_selected): The interactor is gone. It's job
from the dialog's point of view is now done by the mainwindow,
i.e. the parent. Subscribe to SHAPES_SELECTED instead
of SELECTED_SHAPE

* Thuban/UI/dialogs.py (NonModalDialog.__init__): The interactor
is gone. It's job from the dialog's point of view is now done by
the mainwindow, i.e. the parent.

* Thuban/UI/classifier.py (Classifier.__init__): The interactor is
gone. It's job from the dialog's point of view is now done by the
mainwindow, i.e. the parent.

* Thuban/UI/tree.py (SessionTreeView.__init__): The interactor is
gone. It's job from the dialog's point of view is now done by the
mainwindow, i.e. the parent.
(SessionTreeCtrl.__init__): New parameter mainwindow which is
stored as self.mainwindow. The mainwindow is need so that the tree
can still subscribe to the selection messages.
(SessionTreeCtrl.__init__, SessionTreeCtrl.unsubscribe_all)
(SessionTreeCtrl.update_tree, SessionTreeCtrl.OnSelChanged): The
selection is now accessible through the mainwindow. Subscribe to
SHAPES_SELECTED instead of SELECTED_SHAPE

* Thuban/UI/identifyview.py (IdentifyView.__init__): Use the
SHAPES_SELECTED message now.
(IdentifyView.selected_shape): Now subscribed to SHAPES_SELECTED,
so deal with multiple shapes
(IdentifyView.__init__, IdentifyView.OnClose): The interactor is
gone. It's job from the dialog's point of view is now done by the
mainwindow, i.e. the parent.

* Thuban/UI/renderer.py (ScreenRenderer.RenderMap): Rename the
selected_shape parameter and ivar to selected_shapes. It's now a
list of shape ids.
(MapRenderer.draw_label_layer): Deal with multiple selected
shapes. Rearrange the code a bit so that the setup and shape type
distinctions are only executed once.

1 bh 535 # Copyright (c) 2001, 2003 by Intevation GmbH
2     # Authors:
3     # Bernhard Herzog <[email protected]>
4     #
5     # This program is free software under the GPL (>=v2)
6     # Read the file COPYING coming with Thuban for details.
7    
8     """
9     Selection handling
10     """
11    
12     __version__ = "$Revision$"
13     # $Source$
14     # $Id$
15    
16     from Thuban.Lib.connector import Publisher
17    
18     from messages import LAYER_SELECTED, SHAPES_SELECTED
19    
20    
21     class Selection(Publisher):
22    
23     """Manage the selection
24    
25     The selection consists of a list of shape ids and the layer that
26     contains those shapes.
27    
28     Messages issued by the selection:
29    
30     LAYER_SELECTED -- A different layer has been selected or there was a
31     layer selected and the selection has been cleared.
32    
33     Arguments: The newly selected layer or None if no
34     layer is selected.
35    
36     SHAPES_SELECTED -- The set of selected shapes has changed.
37    
38     Arguments: The newly selected layer or None if no
39     layer is selected and a list with ids of the
40     selected shapes. The list is empty if no shapes
41     are selected.
42     """
43    
44     def __init__(self):
45     """Initialize the selection
46    
47     Initially nothing is selected so the selected layer is None and
48     the list of selected shapes is empty.
49     """
50     self.layer = None
51     self.shapes = []
52    
53     def issue_messages(self, issue_layer, issue_shape):
54     """Internal: Issue SHAPES_SELECTED and LAYER_SELECTED messages
55    
56     If the issue_layer argument is true, ussue a LAYER_SELECTED
57     message. If issue_shape is true issue a SHAPES_SELECTED message.
58     """
59     if issue_layer:
60     self.issue(LAYER_SELECTED, self.layer)
61     if issue_shape:
62     self.issue(SHAPES_SELECTED, self.layer, self.SelectedShapes())
63    
64     def ClearSelection(self):
65     """Unselect the currently selected shapes if any.
66    
67     If there was a layer selected before the call, send a
68     LAYER_SELECTED message. If there were selected shapes before the
69     call, send a SHAPES_SELECTED message as well.
70     """
71     issue_layer = self.layer is not None
72     issue_shape = len(self.shapes) > 0
73    
74     self.layer = None
75     self.shapes = []
76     self.issue_messages(issue_layer, issue_shape)
77    
78     def SelectedLayer(self):
79     """Return the selected layer. If no layer is selected return None"""
80     return self.layer
81    
82     def HasSelectedLayer(self):
83     """Return true iff a layer is currently selected"""
84     return self.layer is not None
85    
86     def SelectedShapes(self):
87     """Return the ids of the selected shapes as a list.
88    
89     The list is sorted in ascending order. If no shapes are selected
90     the list is empty.
91     """
92     return self.shapes
93    
94     def SelectLayer(self, layer):
95     """Select the given layer.
96    
97     If the layer is the currently selected layer, do nothing.
98     Ortherwise, issue a LAYER_SELECTED message and if there were
99     shapes selected preciously issue a SHAPES_SELECTED message as
100     well.
101     """
102     if self.layer is not layer:
103     self.layer = layer
104     issue_shape = len(self.shapes) > 0
105     self.shapes = []
106     self.issue_messages(1, issue_shape)
107    
108     def SelectShapes(self, layer, shapes, add = 0):
109     """Select the shapes given in the list shapes in the given layer.
110    
111     If the optional keyword parameter add is true, add the selected
112     shapes to the currently selected shapes if layer is the already
113     selected layer if any. If add is false (the default) make the
114     shapes in shapes the selected shapes.
115    
116     If a different layer is selected afterwards issue a
117     LAYER_SELECTED message. If the set of selected shapes has
118     changed afterwards issue a SHAPES_SELECTED message.
119     """
120     # Turn the shapes explicitly into a list. This main purpose
121     # is that we get a mutable sequence that we can modify in place.
122     shapes = list(shapes)
123     shapes.sort()
124    
125     if self.layer is not layer:
126     # If the layer is differen we can ignore the add parameter
127     # and we have to issue both messages.
128     self.layer = layer
129     self.shapes = shapes
130     issue_layer = issue_shape = 1
131     else:
132     # If the layer is differen we have to merge the ids if add
133     # is true, and we won't have to issue the LAYER_SELECTED
134     # message.
135     issue_layer = 0
136     if add:
137     # Merge the ids by creating a dict with the ids in
138     # self.shapes and in shapes as the keys. The use the sorted
139     # keys of the dict as the new shapes list.
140     set = {}
141     for i in self.shapes:
142     set[i] = 1
143     for i in shapes:
144     set[i] = 1
145     shapes = set.keys()
146     shapes.sort()
147     if self.shapes != shapes:
148     self.shapes = shapes
149     issue_shape = 1
150     else:
151     issue_shape = 0
152    
153     self.issue_messages(issue_layer, issue_shape)
154    
155     def AddShapes(self, layer, shapes):
156     """Add the shapes on layer to the selection.
157    
158     If the layer is the already selected layer, add the shape ids in
159     shapes to the already selected shapes.
160    
161     If the layer is not the already selected layer, make the layer
162     and shapes the selected layer and shapes.
163     """
164     self.SelectShapes(layer, shapes)

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26