Back to index

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

List of all members.

Public Member Functions

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

Public Attributes

 internal_resistor
 item_values_x
 item_values_y
 is_blown
 power_max
 resistor_blown
 gnucap_value
 electric
 canvas
 rootitem
 gnucap_name
 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/bulb1.png"
string icon = "electric/bulb_icon.png"
int counter = 0

Detailed Description

Definition at line 1447 of file electric.py.


Constructor & Destructor Documentation

def electric.Bulb.__init__ (   self,
  electric,
  x,
  y,
  power_max 
)

Definition at line 1451 of file electric.py.

01451 
01452                x, y, power_max):
01453     self.internal_resistor = 1000
01454     super(Bulb, self).__init__(electric,
01455                                "R",
01456                                self.internal_resistor,
01457                                self.image,
01458                                [Node("electric/connect.png", "A", 7, 170),
01459                                 Node("electric/connect.png", "B", 85, 170)])
01460     # Overide some values
01461     self.item_values_x = 55
01462     self.item_values_y = 80
01463     self.item_values.set(fill_color="red")
01464 
01465     # Specific Bulb values
01466     self.is_blown = False
01467     self.move(x, y)
01468     self.show()
01469     self.power_max = power_max
01470     self.resistor_blown = 100000000


Member Function Documentation

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

Reimplemented from electric.Component.

Definition at line 1499 of file electric.py.

01499 
01500   def component_move(self, widget, event, component):
01501     # If the Bulb is blown and we get a click repair it
01502     # If the bulb is not blown, you can blown it by right clicking on it
01503     if (event.state & gtk.gdk.BUTTON1_MASK) and self.electric.get_current_tools()=="SELECT":
01504       if self.is_blown:
01505         self.is_blown = False
01506         self.gnucap_value = self.internal_resistor
01507         self.electric.run_simulation()
01508 
01509     elif (event.state & gtk.gdk.BUTTON3_MASK) and self.electric.get_current_tools()=="SELECT":
01510       if not self.is_blown:
01511         # Blown us with arbitrate high value
01512         self.set_voltage_intensity(True, 100, 10)
01513 
01514     return super(Bulb, self).component_move(widget, event, component)
01515 
01516 
01517 
01518 # ----------------------------------------
01519 # BATTERY
01520 #
#

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

Reimplemented from electric.Component.

Definition at line 1474 of file electric.py.

01474 
01475   def set_voltage_intensity(self, valid_value, voltage, intensity):
01476 
01477     super(Bulb, self).set_voltage_intensity(valid_value, voltage, intensity)
01478 
01479     # If the Bulb is blown, do not update it anymore
01480     if self.is_blown:
01481       return True
01482 
01483     power = abs(voltage * intensity)
01484     image_index = min((power * 10) /  self.power_max + 1, 11)
01485     pixmap = gcompris.utils.load_pixmap("electric/bulb%d.png" %(image_index,))
01486     if debug: print "Power = %f (Max=%f) Image index = %d" %(power, self.power_max, image_index)
01487     self.component_item.set(pixbuf = pixmap)
01488 
01489     # If the Bulb is blown, we have to change it's internal
01490     # Resistor value to infinite and ask for a circuit recalc
01491     if image_index == 11:
01492       self.gnucap_value = self.resistor_blown
01493       self.electric.run_simulation()
01494       self.is_blown = True
01495 
01496     return True

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 from electric.Component.

Definition at line 1491 of file electric.py.

string electric.Bulb.icon = "electric/bulb_icon.png" [static]

Definition at line 1449 of file electric.py.

string electric.Bulb.image = "electric/bulb1.png" [static]

Reimplemented from electric.Component.

Definition at line 1448 of file electric.py.

Reimplemented in electric.Rheostat, and electric.Switch.

Definition at line 779 of file electric.py.

Definition at line 1452 of file electric.py.

Definition at line 1465 of file electric.py.

Definition at line 764 of file electric.py.

Reimplemented from electric.Component.

Definition at line 1460 of file electric.py.

Reimplemented from electric.Component.

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

Definition at line 1469 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: