Back to index

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

List of all members.

Public Member Functions

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

Public Attributes

 item_values_x
 item_values_y
 electric
 canvas
 rootitem
 gnucap_name
 gnucap_value
 nodes
 comp_rootitem
 x
 y
 center_x
 center_y
 component_item_offset_x
 component_item_offset_y
 component_item
 item_values
 voltage
 intensity
 pos_x
 pos_y
 wire

Static Public Attributes

string image = "electric/battery.png"
string icon = "electric/battery_icon.png"
int counter = 0

Detailed Description

Definition at line 1521 of file electric.py.


Constructor & Destructor Documentation

def electric.Battery.__init__ (   self,
  electric,
  x,
  y,
  value 
)

Definition at line 1525 of file electric.py.

01525 
01526                x, y, value):
01527     super(Battery, self).__init__(electric,
01528                                "Vsupply",
01529                                value,
01530                                self.image,
01531                                [Node("electric/connect.png", "A", 6, -35),
01532                                 Node("electric/connect.png", "B", 6, 120)])
01533     # Overide some values
01534     self.item_values_x = 23
01535     self.item_values_y = 70
01536 
01537     self.move(x, y)
01538     self.show()


Member Function Documentation

def electric.Component.component_move (   self,
  widget,
  event,
  component 
) [inherited]

Reimplemented in electric.Bulb, electric.Rheostat, electric.Switch2, and electric.Switch.

Definition at line 873 of file electric.py.

00873 
00874     def component_move(self, widget, event, component):
00875 
00876       if event.state & gtk.gdk.BUTTON1_MASK:
00877         if event.type == gtk.gdk.MOTION_NOTIFY:
00878           if(self.electric.get_current_tools()=="SELECT"):
00879             component.move(event.x, event.y)
00880 
00881         else:
00882           if(self.electric.get_current_tools()=="DEL"):
00883             self.destroy()
00884 
00885       return True

Here is the call graph for this function:

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()

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

Reimplemented in electric.Rheostat, and electric.Switch2.

Definition at line 834 of file electric.py.

00834 
00835     def is_connected(self):
00836 
00837       for node in self.nodes:
00838         if not node.get_wires():
00839           return False
00840 
00841       return True

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.Battery.set_voltage_intensity (   self,
  valid_value,
  voltage,
  intensity 
)

Reimplemented from electric.Component.

Definition at line 1541 of file electric.py.

01541 
01542   def set_voltage_intensity(self, valid_value, voltage, intensity):
01543     super(Battery, self).set_voltage_intensity(valid_value, voltage, intensity)
01544 
01545     if(abs(self.intensity) > 1):
01546       # Short circuit case, set the dead battery icon
01547       self.component_item.set(pixbuf = gcompris.utils.load_pixmap("electric/battery_dead.png"))
01548     else:
01549       self.component_item.set(pixbuf = gcompris.utils.load_pixmap("electric/battery.png"))
01550 
01551     return True
01552 
01553 # ----------------------------------------
01554 # CONNECTION
01555 # (a simple spot to connect wire and make a cute scematic)
#
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.Component.to_gnucap (   self,
  model 
) [inherited]

Reimplemented in electric.Rheostat, electric.Switch2, and electric.Diode.

Definition at line 845 of file electric.py.

00845 
00846     def to_gnucap(self, model):
00847       gnucap = self.gnucap_name
00848 
00849       # No definition, it happens for connection spot
00850       # But in this case, it should not be called at all. it's not in the top level
00851       # components list.
00852       if gnucap == "":
00853         return "* Component ignored\n"
00854 
00855       # ignore component if there are some unconnected node.
00856       for node in self.nodes:
00857         if not node.get_wires():
00858           if debug: print "Component ignored"
00859           return "* Component ignored\n"
00860 
00861       for node in self.nodes:
00862         gnucap += " "
00863         if(node.get_wires()):
00864           gnucap += str(node.get_wires()[0].get_wire_id())
00865 
00866       gnucap += " "
00867       gnucap += str(self.gnucap_value)
00868       gnucap += "\n"
00869       gnucap += model
00870 
00871       return [gnucap, ".print dc + v(%s) i(%s)\n" %(self.gnucap_name, self.gnucap_name)]


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 732 of file electric.py.

Definition at line 748 of file electric.py.

Definition at line 746 of file electric.py.

Reimplemented in electric.Switch2.

Definition at line 747 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 722 of file electric.py.

Reimplemented in electric.Bulb, and electric.Switch.

Definition at line 728 of file electric.py.

string electric.Battery.icon = "electric/battery_icon.png" [static]

Definition at line 1523 of file electric.py.

string electric.Battery.image = "electric/battery.png" [static]

Reimplemented from electric.Component.

Definition at line 1522 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 from electric.Component.

Definition at line 1533 of file electric.py.

Reimplemented from electric.Component.

Definition at line 1534 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.

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: