PyDVT.ViewSelect (version 1.1.0, 08/11/2002)
index
/mntdirect/_bliss/users/gobbo/PyDVT/PyDVT/ViewSelect.py

ViewSelect.py
Base class for mouse/keyboard event based data selection over View objects

 
Classes
            
ViewSelect
ViewSelectDefault

 
class ViewSelect
      ViewSelect objects implement data selection over View objects
through mouse and keyboard events. 
ViewSelect object can be linked only to one Data object, but to
multiple views.
ViewSelect receives  mouse, keyboard and DataChange events, and
calls a callback function to inform application when a selection
happens.
Derived classes implement its functionality by overriding event
methods, drawing over views and calling the selection callback.
 
SetSelection method sets the selection dictionary, redraws all views
and trigger selection callback. If derived classes implement drawing
of the final selection based in the selection dictionary,
application can set selection by code by calling SetSelection.
 
The callback receive as a parameter the ViewSelect object that
generated the event. The selection is read with GetSelection
method, that returns a dictionary. The keys for this dictionary
can be different for each derived class.
 
 
 
Interface:
===========================
    __init__
    ConnectView
    DisconnectView
    SetSelection
    GetSelection        
    RemoveSelection
    GetViewList
    Enable
    Disable
    DisableKeyboard
    EnableKeyboard
    RemoveSelectionInDataChange
    Erase
    Update
    SetPen
    SetBrush
    GetData
    Destroy
 
Overridables:
===========================
    DataChanged
 
Virtuals:
===========================    
    KeyPress
    Motion
    PressMotion
    Press
    DoubleClick
    Release
    EraseView
    DrawView
    GetType
 
 
Internal Events:
===========================
    Receives:
        "DataChange"
        "DeleteEvent"
        "ButtonPressMotion"
        "ButtonRelease"
        "ButtonPress"
        "DoubleClick"
        "Motion"
        "KeyPress"
        "ImageChange"
 
  
ConnectView(self, view, mode=1)
Connects a view to the ViewSelect object
Parameters:
view: the view object
mode: INPUT_OUTPUT - ViewSelect object both draws itself on the View and
      receives its mouse events
      OUTPUT - ViewSelect object draws itself on the view but does not
      receive its mouse events
DataChanged(self, par)
Overridable: default implementation just verifies flag set by RemoveSelectionInDataChange
Destroy(self, source=None)
Cleanup.
As event handlers and callbacks, by keeping a reference to other
objects, avoid them to be destroyed (and freed from memory), the
Destroy method has to be explicitly called for ViewSelect objects
before they get out of scope.
I had tried to use weak references in order not to need this method,
but this generated many other troubles (like impossibility to define
selections locally, difficult control of the destruction sequence,
not interceptable error mesassages...).
Disable(self)
Makes ViewSelect object stop ansering mouse envents of the connected
views, but keeps the selection on screen, if any.
(this "freezes" the selection)
DisableKeyboard(self)
Disables answer to keyboard events
DisconnectView(self, view)
Disonnects a view from the ViewSelect object
Parameters:
View: the view object
DoubleClick(self, pos)
Virtual: Mouse double click event
Parameter:
pos: coordinates, as sent by GetPosition of the View object
     that generated the event
DrawView(self, view)
Virtual: Implements the drawing code
Parameter:
view: view object on which perform the operation
Enable(self)
Makes ViewSelect object restart ansering mouse envents of the connected
views, without changing the selection (if any).
EnableKeyboard(self)
Enables answer to keyboard events
Erase(self, view='ALL')
Erases the drawing of a SelectView object
Parameters:
view:   if "ALL", erases all views
        if a view instance, erases only this one
EraseView(self, view)
Virtual: Implements the erasing code
Parameter:
view: view object on which perform the operation
GetData(self)
Returns linked Data object (None if no linked Data)
GetSelection(self)
Returns selection dictionary ({} if no selection in done)
GetType(self)
Virtual: Return a string identifying the type of selection
GetViewList(self)
Returns list of connected views
KeyPress(self, key, flags)
Virtual: Keyboard event
Parameter:
Motion(self, pos)
Virtual: Mouse move event
Parameter:
pos: coordinates, as sent by GetPosition of the View object
     that generated the event
NotifySelection(self)
Press(self, pos)
Virtual: Mouse press event
Parameter:
pos: coordinates, as sent by GetPosition of the View object
     that generated the event
PressMotion(self, pos)
Virtual: Mouse motion while button pressed event
Parameter:
pos: coordinates, as sent by GetPosition of the View object
     that generated the event
Release(self, pos)
Virtual: Mouse release event
Parameter:
pos: coordinates, as sent by GetPosition of the View object
     that generated the event
RemoveSelection(self)
Clears the selection (if done) and erases from all views.
The ViewSelect object is still active.
RemoveSelectionInDataChange(self, remove=0)
Sets flags that controls if ViewSelect is removed or not in a
DataChange event.
The default implementation of DataChanged works based on this flags.
If DataChanged is overriden this method may not work.
Parameters:
remove: if non-zero selection is removed in a DataChange event.
    Default: selection is not removed
SetBrush(self, brush)
Changes default brush
Parameters:
brush: Brush object
SetPen(self, pen)
Changes default pen
Parameters:
pen: Pen object
SetSelection(self, selection)
Sets Selection dictionary, redraws and call callback function.
Parameters:
selection: dictionary with selection data
Update(self, view='ALL')
Updates the drawing of a SelectView object
Parameters:
view:   if "ALL", updates all views
        if a view instance, updates only this one
_ViewSelect__CheckViews = __CheckViews(self)
_ViewSelect__DoubleClick = __DoubleClick(self, (source, pos))
_ViewSelect__KeyPress = __KeyPress(self, (source, key, flags))
_ViewSelect__Motion = __Motion(self, (source, pos))
_ViewSelect__Press = __Press(self, (source, pos))
_ViewSelect__PressMotion = __PressMotion(self, (source, pos))
_ViewSelect__Release = __Release(self, (source, pos))
__init__(self, data=None, callback=None)
Constructor
Parameters:
data: the Data or Selection object the ViewSelect will be linked to.
      there's no direct interaction to the data object, all ViewSelect operations are
      made through the View object. The base class just registers "DataChange"
      and "DeleteEvent" events
callback: callback function for the selection event

 
class ViewSelectDefault(ViewSelect)
      ViewSelect derived class, also virtual, that adds some functionality,
(which are similar to the default ViewSelect objects)
assuming that the grafical contents of the SelectView object are
stored in the dictionary self.ViewList, and are composed by only one
canvas object for the selection ("SelectDraw", in the dictionary) and
one canvas object for the intermediate drawing ("TempDraw", in the
dictionary). ViewSelectDefault assumes also selection drawing based
in the key "BoundingRect" in the selection dictionary.
Derived classes shall implement DrawSelection, DrawTemp, and the mouse
events (Motion,PressMotion,Press,Release) that are necessary.
By using SetSelectionPos (instead of SetSelection) the key "BoundingRect"
is fixed in the selection dictionary. It's a tuple ((x0,y0]), (x1,y1))
with bounding rect of selection.
 
  
ConnectView(self, view, mode=1) from ViewSelect
DataChanged(self, par) from ViewSelect
Destroy(self, source=None) from ViewSelect
Disable(self) from ViewSelect
DisableKeyboard(self) from ViewSelect
DisconnectView(self, view) from ViewSelect
DoubleClick(self, pos) from ViewSelect
DrawSelection(self, view)
Derived classes draw selection and store its reference in
self.ViewList[view]["SelectDraw"]
DrawTemp(self, view, mouse_position)
Derived classes draw intermediate drawing and store its reference in
self.ViewList[view]["TempDraw"]
DrawView(self, view)
Virtual: See ViewSelect
Enable(self) from ViewSelect
EnableKeyboard(self) from ViewSelect
Erase(self, view='ALL') from ViewSelect
EraseSelection(self, view)
Erases the canvas object for the selection
EraseTemp(self, view)
Erases the canvas object for the intermediate drawing
EraseView(self, view)
Virtual: See ViewSelect
GetData(self) from ViewSelect
GetSelection(self) from ViewSelect
GetType(self) from ViewSelect
GetViewList(self) from ViewSelect
KeyPress(self, key, flags) from ViewSelect
Motion(self, pos) from ViewSelect
NotifySelection(self) from ViewSelect
Press(self, pos) from ViewSelect
PressMotion(self, pos) from ViewSelect
Release(self, pos) from ViewSelect
RemoveSelection(self) from ViewSelect
RemoveSelectionInDataChange(self, remove=0) from ViewSelect
SetBrush(self, brush) from ViewSelect
SetPen(self, pen) from ViewSelect
SetSelection(self, selection) from ViewSelect
SetSelectionPos(self, bounding_rect)
Updates selection with new bounding rectangle.
Redraws and call callback function.
Parameters:
    bounding_rect: value put to "BoundingRect" key in Selection dictionary
Update(self, view='ALL') from ViewSelect
_ViewSelect__CheckViews = __CheckViews(self) from ViewSelect
_ViewSelect__DoubleClick = __DoubleClick(self, (source, pos)) from ViewSelect
_ViewSelect__KeyPress = __KeyPress(self, (source, key, flags)) from ViewSelect
_ViewSelect__Motion = __Motion(self, (source, pos)) from ViewSelect
_ViewSelect__Press = __Press(self, (source, pos)) from ViewSelect
_ViewSelect__PressMotion = __PressMotion(self, (source, pos)) from ViewSelect
_ViewSelect__Release = __Release(self, (source, pos)) from ViewSelect
__init__(self, data=None, callback=None) from ViewSelect

 
Author
             Alexandre Gobbo (gobbo@esrf.fr)