Back to index

gcompris  8.2.2
Public Member Functions | Public Attributes
electric.Selector Class Reference

List of all members.

Public Member Functions

def __init__
def component_click

Public Attributes

 electric
 rootitem
 x
 y
 init_coord
 offset_x
 offset_y

Detailed Description

Definition at line 1577 of file electric.py.


Constructor & Destructor Documentation

def electric.Selector.__init__ (   self,
  electric,
  components_class 
)

Definition at line 1578 of file electric.py.

01578 
01579     def __init__(self, electric, components_class):
01580       self.electric = electric
01581       self.rootitem = electric.rootitem
01582 
01583       self.rootitem.add(
01584         gnomecanvas.CanvasPixbuf,
01585         pixbuf = gcompris.utils.load_pixmap(gcompris.skin.image_to_skin("draw/tool-selector.png")),
01586         x=5,
01587         y=5.0,
01588         width=107.0,
01589         height=517.0,
01590         width_set=True,
01591         height_set=True
01592         )
01593 
01594       self.x = 15
01595       self.y = 60
01596 
01597       index_y = 10
01598       gap     = 20
01599       self.init_coord = {}
01600       self.offset_x = self.offset_y = 0
01601 
01602       for component_class in components_class:
01603         pixmap = gcompris.utils.load_pixmap(component_class[0].icon)
01604         item = self.rootitem.add(
01605           gnomecanvas.CanvasPixbuf,
01606           pixbuf = pixmap,
01607           x = self.x,
01608           y = self.y + index_y,
01609           )
01610         # Save the original coord to set it back once dropped
01611         self.init_coord[component_class[0]] = (self.x, self.y + index_y)
01612         index_y += pixmap.get_height() + gap
01613 
01614         item.connect("event", self.component_click, component_class)
01615 


Member Function Documentation

def electric.Selector.component_click (   self,
  widget,
  event,
  component_class 
)

Definition at line 1617 of file electric.py.

01617 
01618     def component_click(self, widget, event, component_class):
01619 
01620       if (event.state & gtk.gdk.BUTTON1_MASK
01621           and self.electric.get_current_tools()=="DEL"):
01622         # Switch to select mode
01623         self.electric.assign_tool(1)
01624 
01625       if event.type == gtk.gdk.MOTION_NOTIFY:
01626         if event.state & gtk.gdk.BUTTON1_MASK:
01627           # Save the click to image offset
01628           if self.offset_x == 0:
01629             bounds = widget.get_bounds()
01630             self.offset_x = (event.x - bounds[0])
01631             self.offset_y = (event.y - bounds[1])
01632 
01633           widget.set(x = event.x - self.offset_x,
01634                      y = event.y - self.offset_y)
01635 
01636       if event.type == gtk.gdk.BUTTON_RELEASE:
01637         if event.button == 1:
01638           bounds = widget.get_bounds()
01639           component_class[0](self.electric,
01640                              event.x - self.offset_x + (bounds[2]-bounds[0])/2,
01641                              event.y - self.offset_y + (bounds[3]-bounds[1])/2,
01642                              component_class[1])
01643 
01644           widget.set(x = self.init_coord[component_class[0]][0],
01645                      y = self.init_coord[component_class[0]][1])
01646 
01647           self.offset_x = self.offset_y = 0
01648 
01649         return True
01650 


Member Data Documentation

Definition at line 1579 of file electric.py.

Definition at line 1598 of file electric.py.

Definition at line 1599 of file electric.py.

Definition at line 1599 of file electric.py.

Definition at line 1580 of file electric.py.

Definition at line 1593 of file electric.py.

Definition at line 1594 of file electric.py.


The documentation for this class was generated from the following file: