Commit dafc3b21 authored by Bruno Coudoin's avatar Bruno Coudoin

Added colored wires

parent 4208cfa0
...@@ -11,11 +11,6 @@ ...@@ -11,11 +11,6 @@
# #
# - Modified by jacob berkman <jacob@ximian.com> to install # - Modified by jacob berkman <jacob@ximian.com> to install
# Makefile.in.in and po2tbl.sed.in for use with glib-gettextize # Makefile.in.in and po2tbl.sed.in for use with glib-gettextize
#
# - Modified by Rodney Dawes <dobey@novell.com> for use with intltool
#
# We have the following line for use by intltoolize:
# INTLTOOL_MAKEFILE
GETTEXT_PACKAGE = @GETTEXT_PACKAGE@ GETTEXT_PACKAGE = @GETTEXT_PACKAGE@
PACKAGE = @PACKAGE@ PACKAGE = @PACKAGE@
...@@ -32,13 +27,13 @@ VPATH = @srcdir@ ...@@ -32,13 +27,13 @@ VPATH = @srcdir@
prefix = @prefix@ prefix = @prefix@
exec_prefix = @exec_prefix@ exec_prefix = @exec_prefix@
datadir = @datadir@ datadir = @datadir@
datarootdir = @datarootdir@
libdir = @libdir@ libdir = @libdir@
localedir = $(libdir)/locale localedir = $(libdir)/locale
gnulocaledir = $(datadir)/locale gnulocaledir = $(datadir)/locale
gettextsrcdir = $(datadir)/glib-2.0/gettext/po gettextsrcdir = $(datadir)/glib-2.0/gettext/po
subdir = po subdir = po
install_sh = @install_sh@ install_sh = @install_sh@
mkdir_p = @mkdir_p@
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
INSTALL = @INSTALL@ INSTALL = @INSTALL@
...@@ -66,8 +61,7 @@ SOURCES = ...@@ -66,8 +61,7 @@ SOURCES =
POFILES = @POFILES@ POFILES = @POFILES@
GMOFILES = @GMOFILES@ GMOFILES = @GMOFILES@
DISTFILES = ChangeLog Makefile.in.in POTFILES.in \ DISTFILES = ChangeLog Makefile.in.in POTFILES.in \
$(POFILES) $(SOURCES) $(POFILES) $(GMOFILES) $(SOURCES)
EXTRA_DISTFILES = POTFILES.skip Makevars LINGUAS
POTFILES = \ POTFILES = \
...@@ -83,7 +77,7 @@ INSTOBJEXT = @INSTOBJEXT@ ...@@ -83,7 +77,7 @@ INSTOBJEXT = @INSTOBJEXT@
.po.pox: .po.pox:
$(MAKE) $(GETTEXT_PACKAGE).pot $(MAKE) $(GETTEXT_PACKAGE).pot
$(MSGMERGE) $< $(GETTEXT_PACKAGE).pot -o $*.pox $(MSGMERGE) $< $(top_builddir)/po/$(GETTEXT_PACKAGE).pot -o $*pox
.po.mo: .po.mo:
$(MSGFMT) -o $@ $< $(MSGFMT) -o $@ $<
...@@ -180,7 +174,7 @@ uninstall: ...@@ -180,7 +174,7 @@ uninstall:
rm -f $(DESTDIR)$(gettextsrcdir)/Makefile.in.in; \ rm -f $(DESTDIR)$(gettextsrcdir)/Makefile.in.in; \
fi fi
check: all $(GETTEXT_PACKAGE).pot check: all
dvi info tags TAGS ID: dvi info tags TAGS ID:
...@@ -192,21 +186,16 @@ mostlyclean: ...@@ -192,21 +186,16 @@ mostlyclean:
clean: mostlyclean clean: mostlyclean
distclean: clean distclean: clean
rm -f Makefile Makefile.in POTFILES rm -f Makefile Makefile.in POTFILES *.mo *.msg *.cat *.cat.m
rm -f *.mo *.msg *.cat *.cat.m $(GMOFILES)
maintainer-clean: distclean maintainer-clean: distclean
@echo "This command is intended for maintainers to use;" @echo "This command is intended for maintainers to use;"
@echo "it deletes files that may require special tools to rebuild." @echo "it deletes files that may require special tools to rebuild."
rm -f Makefile.in.in rm -f $(GMOFILES)
distdir = ../$(GETTEXT_PACKAGE)-$(VERSION)/$(subdir) distdir = ../$(GETTEXT_PACKAGE)-$(VERSION)/$(subdir)
dist distdir: $(DISTFILES) dist distdir: $(DISTFILES) $(GETTEXT_PACKAGE).pot
dists="$(DISTFILES)"; \ dists="$(DISTFILES)"; \
extra_dists="$(EXTRA_DISTFILES)"; \
for file in $$extra_dists; do \
test -f $$file && dists="$$dists $$file"; \
done; \
for file in $$dists; do \ for file in $$dists; do \
ln $(srcdir)/$$file $(distdir) 2> /dev/null \ ln $(srcdir)/$$file $(distdir) 2> /dev/null \
|| cp -p $(srcdir)/$$file $(distdir); \ || cp -p $(srcdir)/$$file $(distdir); \
...@@ -243,13 +232,17 @@ update-po: Makefile ...@@ -243,13 +232,17 @@ update-po: Makefile
# and Intltool tags (enclosed in square brackets), and appending a full # and Intltool tags (enclosed in square brackets), and appending a full
# relative path to them # relative path to them
POTFILES: POTFILES.in POTFILES: POTFILES.in
( posrcprefix='$(top_srcdir)/'; \ ( if test 'x$(srcdir)' != 'x.'; then \
posrcprefix='$(top_srcdir)/'; \
else \
posrcprefix="../"; \
fi; \
rm -f $@-t $@ \ rm -f $@-t $@ \
&& (sed -e '/^#/d' \ && (sed -e '/^#/d' \
-e 's/^[[].*] *//' \ -e "s/^\[.*\] +//" \
-e '/^[ ]*$$/d' \ -e '/^[ ]*$$/d' \
-e "s@^@ $$posrcprefix@" $(srcdir)/$@.in \ -e "s@.*@ $$posrcprefix& \\\\@" < $(srcdir)/$@.in \
| sed -e '$$!s/$$/ \\/') > $@-t \ | sed -e '$$s/\\$$//') > $@-t \
&& chmod a-w $@-t \ && chmod a-w $@-t \
&& mv $@-t $@ ) && mv $@-t $@ )
......
...@@ -50,7 +50,8 @@ class Gcompris_electric: ...@@ -50,7 +50,8 @@ class Gcompris_electric:
self.gcomprisBoard.disable_im_context = True self.gcomprisBoard.disable_im_context = True
# These are used to let us restart only after the bonus is displayed. # These are used to let us restart only after the bonus is displayed.
# When the bonus is displayed, it call us first with pause(1) and then with pause(0) # When the bonus is displayed, it call us first with pause(1) and then
# with pause(0)
self.board_paused = 0 self.board_paused = 0
self.gamewon = 0 self.gamewon = 0
...@@ -159,7 +160,8 @@ class Gcompris_electric: ...@@ -159,7 +160,8 @@ class Gcompris_electric:
else: else:
self.entry.show() self.entry.show()
# When the bonus is displayed, it call us first with pause(1) and then with pause(0) # When the bonus is displayed, it call us first with pause(1) and then
# with pause(0)
# the game is won # the game is won
if(pause == 0 and self.gamewon): if(pause == 0 and self.gamewon):
self.increment_level() self.increment_level()
...@@ -228,7 +230,8 @@ class Gcompris_electric: ...@@ -228,7 +230,8 @@ class Gcompris_electric:
def display_game(self): def display_game(self):
# Create our rootitem. We put each canvas item in it so at the end we # Create our rootitem. We put each canvas item in it so at the end we
# only have to kill it. The canvas deletes all the items it contains automaticaly. # only have to kill it. The canvas deletes all the items it contains
# automaticaly.
self.rootitem = self.gcomprisBoard.canvas.root().add( self.rootitem = self.gcomprisBoard.canvas.root().add(
gnome.canvas.CanvasGroup, gnome.canvas.CanvasGroup,
x=0.0, x=0.0,
...@@ -239,52 +242,29 @@ class Gcompris_electric: ...@@ -239,52 +242,29 @@ class Gcompris_electric:
def create_components(self): def create_components(self):
# Bulb # Bulb
a = Node("electric/connect.png", "A", -15, 150) self.components.append(Bulb(self.gcomprisBoard.canvas, self.rootitem,
b = Node("electric/connect.png", "B", 85, 150) 400, 200))
bulb = Component(self.gcomprisBoard.canvas, self.rootitem, self.components.append(Bulb(self.gcomprisBoard.canvas, self.rootitem,
"R1", "1k", 540, 200))
"electric/bulb.png", [a, b])
bulb.move(400, 200)
bulb.show()
self.components.append(bulb)
# Battery
a = Node("electric/connect.png", "A", 11, -35)
b = Node("electric/connect.png", "B", 11, 150)
battery = Component(self.gcomprisBoard.canvas, self.rootitem,
"Vsupply1", "10",
"electric/battery.png", [a, b])
battery.move(100, 200)
battery.show()
self.components.append(battery)
# Battery
a = Node("electric/connect.png", "A", 11, -35)
b = Node("electric/connect.png", "B", 11, 150)
battery2 = Component(self.gcomprisBoard.canvas, self.rootitem,
"Vsupply2", "10",
"electric/battery.png", [a, b])
battery2.move(150, 200)
battery2.show()
self.components.append(battery2)
# Resistor # Resistor
a = Node("electric/connect.png", "A", -30, -5) self.components.append(Resistor(self.gcomprisBoard.canvas, self.rootitem,
b = Node("electric/connect.png", "B", 130, -5) 150, 400))
resistor = Component(self.gcomprisBoard.canvas, self.rootitem,
"R2", "1k",
"electric/resistor.png", [b, a])
resistor.move(150, 400) # Variator
resistor.show() self.components.append(Variator(self.gcomprisBoard.canvas, self.rootitem,
self.components.append(resistor) 700, 200))
# Battery
self.components.append(Battery(self.gcomprisBoard.canvas, self.rootitem,
100, 200))
self.components.append(Battery(self.gcomprisBoard.canvas, self.rootitem,
160, 200))
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
...@@ -295,7 +275,17 @@ class Wire: ...@@ -295,7 +275,17 @@ class Wire:
# Wire ID 0 is a dummy wire, we start at 1 # Wire ID 0 is a dummy wire, we start at 1
counter = 1 counter = 1
connection = {} connection = {}
colors = [ 0xFF00FFFFL,
0x55001FFFL,
0x55005FFFL,
0x550099FFL,
0x5566FFFFL,
0x55FFFFFFL,
0x00FFFFFFL,
0x55FF00FFL,
0x056666FFL,
0x660000FFL]
def __init__(self, rootitem, source_node, x1, y1, x2, y2): def __init__(self, rootitem, source_node, x1, y1, x2, y2):
self.rootitem = rootitem self.rootitem = rootitem
self.source_node = source_node self.source_node = source_node
...@@ -307,7 +297,7 @@ class Wire: ...@@ -307,7 +297,7 @@ class Wire:
self.wire_item = self.rootitem.add( self.wire_item = self.rootitem.add(
gnome.canvas.CanvasLine, gnome.canvas.CanvasLine,
points=( self.x1, self.y1, self.x2, self.y2), points=( self.x1, self.y1, self.x2, self.y2),
fill_color_rgba = 0xCC1111FFL, fill_color_rgba = Wire.colors[Wire.counter % len(Wire.colors)],
width_units=5.0 width_units=5.0
) )
self.wire_item.connect("event", self.delete_wire, self) self.wire_item.connect("event", self.delete_wire, self)
...@@ -320,7 +310,8 @@ class Wire: ...@@ -320,7 +310,8 @@ class Wire:
wire_id = node.get_wires()[0].get_wire_id() wire_id = node.get_wires()[0].get_wire_id()
print "Node already connected to %d (self.wire_id=%d)" %(wire_id, self.wire_id) print "Node already connected to %d (self.wire_id=%d)" %(wire_id, self.wire_id)
if self.wire_id >= 0: if self.wire_id >= 0:
# This node was already connected elsewhere, reset it to use our wire_id # This node was already connected elsewhere, reset it to use our
# wire_id
for wire in node.get_wires(): for wire in node.get_wires():
print " Was connected to %d" %(wire.get_wire_id(),) print " Was connected to %d" %(wire.get_wire_id(),)
if wire.get_wire_id() != self.wire_id: if wire.get_wire_id() != self.wire_id:
...@@ -347,6 +338,8 @@ class Wire: ...@@ -347,6 +338,8 @@ class Wire:
self.target_node.renumber_wire(self, id) self.target_node.renumber_wire(self, id)
if(self.source_node): if(self.source_node):
self.source_node.renumber_wire(self, id) self.source_node.renumber_wire(self, id)
self.wire_item.set(fill_color_rgba = Wire.colors[Wire.counter % len(Wire.colors)])
def get_wire_id(self): def get_wire_id(self):
return self.wire_id return self.wire_id
...@@ -355,7 +348,8 @@ class Wire: ...@@ -355,7 +348,8 @@ class Wire:
self.wire_item.destroy() self.wire_item.destroy()
self.wire_id = -1 self.wire_id = -1
self.source_node.remove_wire(self, None) self.source_node.remove_wire(self, None)
self.target_node.remove_wire(self, Wire.counter) if self.target_node:
self.target_node.remove_wire(self, Wire.counter)
Wire.counter += 1 Wire.counter += 1
self.source_node = None self.source_node = None
self.target_node = None self.target_node = None
...@@ -365,7 +359,8 @@ class Wire: ...@@ -365,7 +359,8 @@ class Wire:
self.target_node = node self.target_node = node
self._add_connection(node) self._add_connection(node)
# Move wire. In fact, the attached component are moved and THEY move the wire # Move wire. In fact, the attached component are moved and THEY
# move the wire
def move_all_wire(self, x, y): def move_all_wire(self, x, y):
if(self.source_node and self.target_node): if(self.source_node and self.target_node):
source_component = self.source_node.get_component() source_component = self.source_node.get_component()
...@@ -462,7 +457,8 @@ class Node: ...@@ -462,7 +457,8 @@ class Node:
def get_wires(self): def get_wires(self):
return(self.wires) return(self.wires)
# Has wire, return True if the given wire is already connected to this node # Has wire, return True if the given wire is already connected
# to this node
def has_wire(self, wire): def has_wire(self, wire):
try: try:
if(self.wires.index(wire)): if(self.wires.index(wire)):
...@@ -486,13 +482,15 @@ class Node: ...@@ -486,13 +482,15 @@ class Node:
# nodes is a list of class Node object # nodes is a list of class Node object
class Component: class Component(object):
counter = 0
def __init__(self, canvas, rootitem, def __init__(self, canvas, rootitem,
gnucap_name, gnucap_value, gnucap_name, gnucap_value,
image, nodes): image, nodes):
self.canvas = canvas self.canvas = canvas
self.rootitem = rootitem self.rootitem = rootitem
self.gnucap_name = gnucap_name self.gnucap_name = gnucap_name + str(Component.counter)
Component.counter += 1
self.gnucap_value = gnucap_value self.gnucap_value = gnucap_value
self.image = image self.image = image
self.nodes = nodes self.nodes = nodes
...@@ -617,11 +615,12 @@ class Component: ...@@ -617,11 +615,12 @@ class Component:
# Our wire line confuses the get_item_at. Look arround. # Our wire line confuses the get_item_at. Look arround.
for x in range(-10, 11, 5): for x in range(-10, 11, 5):
target_item = self.canvas.get_item_at(event.x + x, event.y) target_item = self.canvas.get_item_at(event.x + x, event.y)
node_target = target_item.get_data('node') if target_item:
if(node_target): node_target = target_item.get_data('node')
break if(node_target):
break
# Take care not to wire the same component or 2 times the same node # Take care not to wire the same component or 2 times the same # node
if(not node_target if(not node_target
or node.get_component() == node_target.get_component() or node.get_component() == node_target.get_component()
or node_target.has_wire(self.wire)): or node_target.has_wire(self.wire)):
...@@ -635,4 +634,72 @@ class Component: ...@@ -635,4 +634,72 @@ class Component:
return False return False
# -----------------------------------------------------------------------
# -----------------------------------------------------------------------
# -----------------------------------------------------------------------
#
# Pre defined components
# ----------------------
#
class Resistor(Component):
def __init__(self, canvas, rootitem,
x, y):
super(Resistor, self).__init__(canvas,
rootitem,
"R",
"1k",
"electric/resistor.png",
[Node("electric/connect.png", "A", -30, -5),
Node("electric/connect.png", "B", 130, -5)])
self.move(x, y)
self.show()
class Variator(Component):
def __init__(self, canvas, rootitem,
x, y):
super(Variator, self).__init__(canvas,
rootitem,
"R",
"10k",
"electric/resistor_v.png",
[Node("electric/connect.png", "A", -3, -15),
Node("electric/connect.png", "B", 40, 47),
Node("electric/connect.png", "C", -3, 110)])
self.move(x, y)
self.show()
class Bulb(Component):
def __init__(self, canvas, rootitem,
x, y):
super(Bulb, self).__init__(canvas,
rootitem,
"R",
"1k",
"electric/bulb.png",
[Node("electric/connect.png", "A", -15, 150),
Node("electric/connect.png", "B", 85, 150)])
self.move(x, y)
self.show()
# Change the pixmap depending on the real power in the Bulb
def set_voltage_intensity(self, voltage, intensity):
super(Bulb, self).set_voltage_intensity(voltage, intensity)
class Battery(Component):
def __init__(self, canvas, rootitem,
x, y):
super(Battery, self).__init__(canvas,
rootitem,
"Vsupply",
"10",
"electric/battery.png",
[Node("electric/connect.png", "A", 11, -35),
Node("electric/connect.png", "B", 11, 150)])
self.move(x, y)
self.show()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment