Back to index

gcompris  8.2.2
Public Member Functions | Public Attributes | Static Public Attributes
electric.Switch2 Class Reference
Inheritance diagram for electric.Switch2:
Inheritance graph
[legend]
Collaboration diagram for electric.Switch2:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def component_click
def component_move
def is_connected
def to_gnucap_res
def to_gnucap
def set_voltage_intensity
def get_rootitem
def move
def show
def hide
def destroy
def get_nodes
def create_wire

Public Attributes

 click_ofset_x
 click_ofset_y
 gnucap_current_resistor
 gnucap_nb_resistor
 value_on
 value_off
 value_top
 value_bottom
 click_item
 component_item_offset_y
 electric
 canvas
 rootitem
 gnucap_name
 gnucap_value
 nodes
 comp_rootitem
 x
 y
 center_x
 center_y
 component_item_offset_x
 component_item
 item_values_x
 item_values_y
 item_values
 voltage
 intensity
 pos_x
 pos_y
 wire

Static Public Attributes

string image = "electric/switch2_on.png"
string icon = "electric/switch2_icon.png"
int counter = 0

Detailed Description

Definition at line 1078 of file electric.py.


Constructor & Destructor Documentation

def electric.Switch2.__init__ (   self,
  electric,
  x,
  y,
  dummy 
)

Definition at line 1082 of file electric.py.

01082 
01083                x, y, dummy):
01084     self.click_ofset_x = 22
01085     self.click_ofset_y = -28
01086     self.gnucap_current_resistor = 1
01087     self.gnucap_nb_resistor = 0
01088     self.value_on  = "0"
01089     self.value_off = "10000k"
01090     self.value_top = self.value_on
01091     self.value_bottom = self.value_off
01092 
01093     super(Switch2, self).__init__(electric,
01094                                    "R",
01095                                    self.value_off,
01096                                    self.image,
01097                                    [Node("electric/connect.png", "C", -15, 0),
01098                                     Node("electric/connect.png", "A", 80, -25),
01099                                     Node("electric/connect.png", "B", 80, 25)])
01100 
01101     # Overide some values
01102     self.item_values.hide()
01103 
01104     self.move(x, y)
01105 
01106     pixmap = gcompris.utils.load_pixmap("electric/switch_click.png")
01107     self.click_item = self.comp_rootitem.add(
01108       gnomecanvas.CanvasPixbuf,
01109       pixbuf = pixmap,
01110       x = self.x + self.click_ofset_x,
01111       y = self.y + self.click_ofset_y,
01112       )
01113     self.click_item.connect("event", self.component_click)
01114     self.show()
01115 


Member Function Documentation

def electric.Switch2.component_click (   self,
  widget,
  event 
)

Definition at line 1117 of file electric.py.

01117 
01118   def component_click(self, widget, event):
01119     if event.state & gtk.gdk.BUTTON1_MASK:
01120       if(self.value_top == self.value_off):
01121         self.value_top = self.value_on
01122         self.value_bottom = self.value_off
01123         self.component_item_offset_y = - 6
01124         pixmap = gcompris.utils.load_pixmap("electric/switch2_on.png")
01125       else:
01126         self.value_top = self.value_off
01127         self.value_bottom = self.value_on
01128         self.component_item_offset_y = 10
01129         pixmap = gcompris.utils.load_pixmap("electric/switch2_off.png")
01130 
01131       self.component_item.set(y = self.y + self.component_item_offset_y)
01132       self.component_item.set(pixbuf = pixmap)
01133       self.electric.run_simulation()
01134 
01135     return False

def electric.Switch2.component_move (   self,
  widget,
  event,
  component 
)

Reimplemented from electric.Component.

Definition at line 1137 of file electric.py.

01137 
01138   def component_move(self, widget, event, component):
01139     super(Switch2, self).component_move(widget, event, component)
01140 
01141     if(self.electric.get_current_tools()=="DEL"):
01142       return True
01143 
01144     self.click_item.set(
01145       x = self.x + self.click_ofset_x,
01146       y = self.y + self.click_ofset_y)
01147 
01148     return True

def electric.Component.create_wire (   self,
  widget,
  event,
  node 
) [inherited]

Definition at line 887 of file electric.py.

00887 
00888     def create_wire(self, widget, event, node):
00889 
00890       if(self.electric.get_current_tools()=="DEL"):
00891         return True
00892 
00893       if event.type == gtk.gdk.BUTTON_PRESS:
00894         if event.button == 1:
00895           bounds = widget.get_bounds()
00896           self.pos_x = (bounds[0]+bounds[2])/2
00897           self.pos_y = (bounds[1]+bounds[3])/2
00898           self.wire = Wire(self.electric, node,
00899                            self.pos_x, self.pos_y, event.x, event.y)
00900           node.add_wire(self.wire)
00901           return True
00902 
00903       if event.type == gtk.gdk.MOTION_NOTIFY:
00904         if event.state & gtk.gdk.BUTTON1_MASK:
00905           self.wire.move_target_node(event.x, event.y)
00906 
00907       if event.type == gtk.gdk.BUTTON_RELEASE:
00908         if event.button == 1:
00909           node_target = None
00910           # Our wire line confuses the get_item_at. Look arround.
00911           for x in range(-10, 11, 5):
00912             target_item = self.canvas.get_item_at(event.x + x, event.y)
00913             if target_item:
00914               node_target = target_item.get_data('node')
00915               if(node_target):
00916                 break
00917 
00918           # Take care not to wire the same component or 2 times the same node
00919           if(not node_target
00920              or node.get_component() == node_target.get_component()
00921              or node_target.has_wire(self.wire)):
00922             node.remove_wire(self.wire, None)
00923             self.wire.destroy()
00924           else:
00925             self.wire.set_target_node(node_target)
00926             node_target.add_wire(self.wire)
00927             self.electric.run_simulation()
00928 
00929           return True
00930 
00931       return False
00932 
00933 # -----------------------------------------------------------------------
00934 # -----------------------------------------------------------------------
00935 # -----------------------------------------------------------------------
00936 #
00937 # Pre defined components
00938 # ----------------------
00939 #
00940 
00941 # ----------------------------------------
00942 # RESISTOR
00943 #
#
def electric.Component.destroy (   self) [inherited]

Definition at line 810 of file electric.py.

00810 
00811     def destroy(self):
00812       try:
00813         # Remove ourself from the list of gnucap aware components
00814         self.electric.components.remove(self)
00815       except:
00816         pass
00817 
00818       for node in self.nodes:
00819         while node.get_wires():
00820           wire = node.get_wires()[0]
00821           node.remove_wire(wire, None)
00822           wire.destroy()
00823 
00824       self.comp_rootitem.destroy()

Here is the caller graph for this function:

def electric.Component.get_nodes (   self) [inherited]

Definition at line 826 of file electric.py.

00826 
00827     def get_nodes(self):
00828       return self.nodes

def electric.Component.get_rootitem (   self) [inherited]

Definition at line 788 of file electric.py.

00788 
00789     def get_rootitem(self):
00790       return self.comp_rootitem

def electric.Component.hide (   self) [inherited]

Definition at line 807 of file electric.py.

00807 
00808     def hide(self):
00809       self.comp_rootitem.hide()

Reimplemented from electric.Component.

Definition at line 1154 of file electric.py.

01154 
01155   def is_connected(self):
01156     count = 0
01157     for node in self.nodes:
01158       if node.get_wires():
01159         count += 1
01160 
01161     if count >= 2:
01162       return True
01163 
01164     return False

def electric.Component.move (   self,
  x,
  y 
) [inherited]

Definition at line 791 of file electric.py.

00791 
00792     def move(self, x, y):
00793       self.x =  x - self.center_x
00794       self.y =  y - self.center_y
00795 
00796       self.item_values.set(x =  self.item_values_x + self.x,
00797                            y =  self.item_values_y + self.y)
00798 
00799       self.component_item.set(x =  self.x + self.component_item_offset_x,
00800                               y =  self.y + self.component_item_offset_y )
00801 
00802       for node in self.nodes:
00803         node.move( self.x,  self.y)

Here is the caller graph for this function:

def electric.Switch2.set_voltage_intensity (   self,
  valid_value,
  voltage,
  intensity 
)

Reimplemented from electric.Component.

Definition at line 1216 of file electric.py.

01216 
01217   def set_voltage_intensity(self, valid_value, voltage, intensity):
01218     # Never show values
01219     self.item_values.hide()
01220 
01221     self.gnucap_current_resistor += 1
01222 
01223     if(self.gnucap_nb_resistor == self.gnucap_current_resistor):
01224       return True
01225     else:
01226       return False
01227 
01228 # ----------------------------------------
01229 # RHEOSTAT
01230 #
#
def electric.Component.show (   self) [inherited]

Definition at line 804 of file electric.py.

00804 
00805     def show(self):
00806       self.comp_rootitem.show()

Here is the caller graph for this function:

def electric.Switch2.to_gnucap (   self,
  model 
)

Reimplemented from electric.Component.

Definition at line 1186 of file electric.py.

01186 
01187   def to_gnucap(self, model):
01188 
01189     gnucap = ["", ""]
01190 
01191     # reset set_voltage_intensity counter
01192     self.gnucap_current_resistor = 0
01193     self.gnucap_nb_resistor = 0
01194 
01195     # top resistor
01196     if self.nodes[0].get_wires() and \
01197        self.nodes[1].get_wires():
01198       gnucap_resp = self.to_gnucap_res(self.gnucap_name + "_top", 0, 1,
01199                                         self.value_top)
01200       gnucap[0] += gnucap_resp[0]
01201       gnucap[1] += gnucap_resp[1]
01202       self.gnucap_nb_resistor += 1
01203 
01204     # bottom resistor
01205     if self.nodes[0].get_wires() and \
01206        self.nodes[2].get_wires():
01207       gnucap_resp = self.to_gnucap_res(self.gnucap_name + "_bot", 0, 2,
01208                                        self.value_bottom)
01209       gnucap[0] += gnucap_resp[0]
01210       gnucap[1] += gnucap_resp[1]
01211       self.gnucap_nb_resistor += 1
01212 
01213     return [gnucap[0], gnucap[1]]

Here is the call graph for this function:

def electric.Switch2.to_gnucap_res (   self,
  gnucap_name,
  node_id1,
  node_id2,
  gnucap_value 
)

Definition at line 1167 of file electric.py.

01167 
01168   def to_gnucap_res(self, gnucap_name, node_id1, node_id2, gnucap_value):
01169     gnucap = gnucap_name
01170     gnucap += " "
01171 
01172     for i in (node_id1, node_id2):
01173       node = self.nodes[i]
01174       if node.get_wires():
01175         gnucap += str(node.get_wires()[0].get_wire_id())
01176 
01177       gnucap += " "
01178 
01179     gnucap += " "
01180     gnucap += str(gnucap_value)
01181     gnucap += "\n"
01182 
01183     return [gnucap, ".print dc + v(%s) i(%s)\n" %(gnucap_name, gnucap_name)]

Here is the caller graph for this function:


Member Data Documentation

Definition at line 718 of file electric.py.

Definition at line 743 of file electric.py.

Definition at line 744 of file electric.py.

Definition at line 1106 of file electric.py.

Definition at line 1083 of file electric.py.

Definition at line 1084 of file electric.py.

Definition at line 732 of file electric.py.

Definition at line 748 of file electric.py.

Definition at line 746 of file electric.py.

Reimplemented from electric.Component.

Definition at line 1122 of file electric.py.

int electric.Component.counter = 0 [static, inherited]

Definition at line 713 of file electric.py.

Definition at line 717 of file electric.py.

Definition at line 1085 of file electric.py.

Definition at line 722 of file electric.py.

Definition at line 1086 of file electric.py.

Reimplemented in electric.Bulb, and electric.Switch.

Definition at line 728 of file electric.py.

string electric.Switch2.icon = "electric/switch2_icon.png" [static]

Definition at line 1080 of file electric.py.

string electric.Switch2.image = "electric/switch2_on.png" [static]

Reimplemented from electric.Component.

Definition at line 1079 of file electric.py.

Reimplemented in electric.Rheostat, and electric.Switch.

Definition at line 779 of file electric.py.

Definition at line 764 of file electric.py.

Reimplemented in electric.Battery, electric.Bulb, electric.Rheostat, electric.Diode, and electric.Resistor.

Definition at line 762 of file electric.py.

Reimplemented in electric.Battery, electric.Bulb, electric.Rheostat, electric.Diode, and electric.Resistor.

Definition at line 763 of file electric.py.

Definition at line 730 of file electric.py.

Definition at line 895 of file electric.py.

Definition at line 896 of file electric.py.

Definition at line 719 of file electric.py.

Definition at line 1090 of file electric.py.

Definition at line 1088 of file electric.py.

Definition at line 1087 of file electric.py.

Definition at line 1089 of file electric.py.

Reimplemented in electric.Rheostat, and electric.Switch.

Definition at line 778 of file electric.py.

Definition at line 897 of file electric.py.

electric.Component.x [inherited]

Definition at line 741 of file electric.py.

electric.Component.y [inherited]

Definition at line 742 of file electric.py.


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