Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog15
-rw-r--r--boards/writing_tutor/anim_pen.gifbin4808 -> 0 bytes
-rw-r--r--boards/writing_tutor/anim_pen.txt1
-rw-r--r--boards/writing_tutor/drop.pngbin3162 -> 0 bytes
-rw-r--r--boards/writing_tutor/image_match/@kruh.pngbin5830 -> 0 bytes
-rw-r--r--boards/writing_tutor/image_match/@obdlznik.pngbin1720 -> 0 bytes
-rw-r--r--boards/writing_tutor/image_match/@stvorec.pngbin3022 -> 0 bytes
-rw-r--r--boards/writing_tutor/image_match/@trojuholnik.pngbin5720 -> 0 bytes
-rw-r--r--boards/writing_tutor/image_match/a.pngbin9561 -> 0 bytes
-rw-r--r--boards/writing_tutor/image_match/b.pngbin7808 -> 0 bytes
-rw-r--r--boards/writing_tutor/image_match/c.pngbin3427 -> 0 bytes
-rw-r--r--boards/writing_tutor/image_match/d.pngbin6829 -> 0 bytes
-rw-r--r--boards/writing_tutor/image_match/g.pngbin12231 -> 0 bytes
-rw-r--r--boards/writing_tutor/image_match/h.pngbin9275 -> 0 bytes
-rw-r--r--boards/writing_tutor/image_match/j.pngbin4409 -> 0 bytes
-rw-r--r--boards/writing_tutor/image_match/l.pngbin13548 -> 0 bytes
-rw-r--r--boards/writing_tutor/image_match/m.pngbin8271 -> 0 bytes
-rw-r--r--boards/writing_tutor/image_match/r.pngbin10825 -> 0 bytes
-rw-r--r--boards/writing_tutor/image_match/s.pngbin5765 -> 0 bytes
-rw-r--r--boards/writing_tutor/image_match/t.pngbin11637 -> 0 bytes
-rw-r--r--boards/writing_tutor/image_match/z.pngbin7124 -> 0 bytes
-rw-r--r--boards/writing_tutor/notepad.pngbin20759 -> 0 bytes
-rw-r--r--boards/writing_tutor/pattern_admin_bg.pngbin5524 -> 0 bytes
-rw-r--r--boards/writing_tutor/tablet_active.pngbin1485 -> 0 bytes
-rw-r--r--boards/writing_tutor/tablet_inactive.pngbin604 -> 0 bytes
-rw-r--r--boards/writing_tutor/wood_oak.pngbin717203 -> 0 bytes
-rw-r--r--boards/writing_tutor/wood_pine.pngbin573500 -> 0 bytes
-rw-r--r--boards/writing_tutor_image_match.xml.in18
-rw-r--r--boards/writing_tutor_missing_match.xml.in20
-rw-r--r--boards/writing_tutor_pattern_admin.xml.in18
-rw-r--r--boards/writing_tutor_template_match.xml.in18
-rw-r--r--src/boards/python/writing_tutor_common.py164
-rw-r--r--src/boards/python/writing_tutor_image_match.py749
-rw-r--r--src/boards/python/writing_tutor_missing_match.py734
-rw-r--r--src/boards/python/writing_tutor_pattern_admin.py773
-rw-r--r--src/boards/python/writing_tutor_template_match.py734
36 files changed, 15 insertions, 3229 deletions
diff --git a/ChangeLog b/ChangeLog
index 98d6c23..a2679d7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2008-05-12 Bruno coudoin <bruno.coudoin@free.fr>
+
+ Removed non functional writing tutor activity to make room.
+
+ * boards/writing_tutor/anim_pen.txt:
+ * boards/writing_tutor_image_match.xml.in:
+ * boards/writing_tutor_missing_match.xml.in:
+ * boards/writing_tutor_pattern_admin.xml.in:
+ * boards/writing_tutor_template_match.xml.in:
+ * src/boards/python/writing_tutor_common.py:
+ * src/boards/python/writing_tutor_image_match.py:
+ * src/boards/python/writing_tutor_missing_match.py:
+ * src/boards/python/writing_tutor_pattern_admin.py:
+ * src/boards/python/writing_tutor_template_match.py:
+
2008-05-06 Bruno coudoin <bruno.coudoin@free.fr>
Fixed bug531709]
diff --git a/boards/writing_tutor/anim_pen.gif b/boards/writing_tutor/anim_pen.gif
deleted file mode 100644
index 8596c77..0000000
--- a/boards/writing_tutor/anim_pen.gif
+++ /dev/null
Binary files differ
diff --git a/boards/writing_tutor/anim_pen.txt b/boards/writing_tutor/anim_pen.txt
deleted file mode 100644
index 2328afc..0000000
--- a/boards/writing_tutor/anim_pen.txt
+++ /dev/null
@@ -1 +0,0 @@
-writing_tutor/anim_pen.gif
diff --git a/boards/writing_tutor/drop.png b/boards/writing_tutor/drop.png
deleted file mode 100644
index c29a2dd..0000000
--- a/boards/writing_tutor/drop.png
+++ /dev/null
Binary files differ
diff --git a/boards/writing_tutor/image_match/@kruh.png b/boards/writing_tutor/image_match/@kruh.png
deleted file mode 100644
index c34ad44..0000000
--- a/boards/writing_tutor/image_match/@kruh.png
+++ /dev/null
Binary files differ
diff --git a/boards/writing_tutor/image_match/@obdlznik.png b/boards/writing_tutor/image_match/@obdlznik.png
deleted file mode 100644
index eccdf28..0000000
--- a/boards/writing_tutor/image_match/@obdlznik.png
+++ /dev/null
Binary files differ
diff --git a/boards/writing_tutor/image_match/@stvorec.png b/boards/writing_tutor/image_match/@stvorec.png
deleted file mode 100644
index 7b7ce17..0000000
--- a/boards/writing_tutor/image_match/@stvorec.png
+++ /dev/null
Binary files differ
diff --git a/boards/writing_tutor/image_match/@trojuholnik.png b/boards/writing_tutor/image_match/@trojuholnik.png
deleted file mode 100644
index bfd40ad..0000000
--- a/boards/writing_tutor/image_match/@trojuholnik.png
+++ /dev/null
Binary files differ
diff --git a/boards/writing_tutor/image_match/a.png b/boards/writing_tutor/image_match/a.png
deleted file mode 100644
index d6098f1..0000000
--- a/boards/writing_tutor/image_match/a.png
+++ /dev/null
Binary files differ
diff --git a/boards/writing_tutor/image_match/b.png b/boards/writing_tutor/image_match/b.png
deleted file mode 100644
index c4ea259..0000000
--- a/boards/writing_tutor/image_match/b.png
+++ /dev/null
Binary files differ
diff --git a/boards/writing_tutor/image_match/c.png b/boards/writing_tutor/image_match/c.png
deleted file mode 100644
index 158ff5e..0000000
--- a/boards/writing_tutor/image_match/c.png
+++ /dev/null
Binary files differ
diff --git a/boards/writing_tutor/image_match/d.png b/boards/writing_tutor/image_match/d.png
deleted file mode 100644
index 5f5debd..0000000
--- a/boards/writing_tutor/image_match/d.png
+++ /dev/null
Binary files differ
diff --git a/boards/writing_tutor/image_match/g.png b/boards/writing_tutor/image_match/g.png
deleted file mode 100644
index a4d3831..0000000
--- a/boards/writing_tutor/image_match/g.png
+++ /dev/null
Binary files differ
diff --git a/boards/writing_tutor/image_match/h.png b/boards/writing_tutor/image_match/h.png
deleted file mode 100644
index 10afda8..0000000
--- a/boards/writing_tutor/image_match/h.png
+++ /dev/null
Binary files differ
diff --git a/boards/writing_tutor/image_match/j.png b/boards/writing_tutor/image_match/j.png
deleted file mode 100644
index 6e5122a..0000000
--- a/boards/writing_tutor/image_match/j.png
+++ /dev/null
Binary files differ
diff --git a/boards/writing_tutor/image_match/l.png b/boards/writing_tutor/image_match/l.png
deleted file mode 100644
index c1a6df2..0000000
--- a/boards/writing_tutor/image_match/l.png
+++ /dev/null
Binary files differ
diff --git a/boards/writing_tutor/image_match/m.png b/boards/writing_tutor/image_match/m.png
deleted file mode 100644
index 42b59ef..0000000
--- a/boards/writing_tutor/image_match/m.png
+++ /dev/null
Binary files differ
diff --git a/boards/writing_tutor/image_match/r.png b/boards/writing_tutor/image_match/r.png
deleted file mode 100644
index 402bf83..0000000
--- a/boards/writing_tutor/image_match/r.png
+++ /dev/null
Binary files differ
diff --git a/boards/writing_tutor/image_match/s.png b/boards/writing_tutor/image_match/s.png
deleted file mode 100644
index aa0bd32..0000000
--- a/boards/writing_tutor/image_match/s.png
+++ /dev/null
Binary files differ
diff --git a/boards/writing_tutor/image_match/t.png b/boards/writing_tutor/image_match/t.png
deleted file mode 100644
index 3b9bcd2..0000000
--- a/boards/writing_tutor/image_match/t.png
+++ /dev/null
Binary files differ
diff --git a/boards/writing_tutor/image_match/z.png b/boards/writing_tutor/image_match/z.png
deleted file mode 100644
index 71524f2..0000000
--- a/boards/writing_tutor/image_match/z.png
+++ /dev/null
Binary files differ
diff --git a/boards/writing_tutor/notepad.png b/boards/writing_tutor/notepad.png
deleted file mode 100644
index f06a9e6..0000000
--- a/boards/writing_tutor/notepad.png
+++ /dev/null
Binary files differ
diff --git a/boards/writing_tutor/pattern_admin_bg.png b/boards/writing_tutor/pattern_admin_bg.png
deleted file mode 100644
index 424fbdd..0000000
--- a/boards/writing_tutor/pattern_admin_bg.png
+++ /dev/null
Binary files differ
diff --git a/boards/writing_tutor/tablet_active.png b/boards/writing_tutor/tablet_active.png
deleted file mode 100644
index 3c668bf..0000000
--- a/boards/writing_tutor/tablet_active.png
+++ /dev/null
Binary files differ
diff --git a/boards/writing_tutor/tablet_inactive.png b/boards/writing_tutor/tablet_inactive.png
deleted file mode 100644
index b6333a5..0000000
--- a/boards/writing_tutor/tablet_inactive.png
+++ /dev/null
Binary files differ
diff --git a/boards/writing_tutor/wood_oak.png b/boards/writing_tutor/wood_oak.png
deleted file mode 100644
index 0dd6c14..0000000
--- a/boards/writing_tutor/wood_oak.png
+++ /dev/null
Binary files differ
diff --git a/boards/writing_tutor/wood_pine.png b/boards/writing_tutor/wood_pine.png
deleted file mode 100644
index e08826a..0000000
--- a/boards/writing_tutor/wood_pine.png
+++ /dev/null
Binary files differ
diff --git a/boards/writing_tutor_image_match.xml.in b/boards/writing_tutor_image_match.xml.in
deleted file mode 100644
index 7005d59..0000000
--- a/boards/writing_tutor_image_match.xml.in
+++ /dev/null
@@ -1,18 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<GCompris>
- <Board
- name="writing_tutor_image_match"
- type="python:writing_tutor_image_match"
- section="/experimental/writing_tutor"
- icon="boardicons/writing_tutor_image_match.png"
- difficulty="1"
- mode="normal"
- author="Jozef Cerven (jcmail80@gmail.com)"
- boarddir="tutor">
- <title>TBD</title>
- <description>TBD</description>
- <prerequisite>TBD</prerequisite>
- <goal></goal>
- <manual></manual>
- </Board>
-</GCompris>
diff --git a/boards/writing_tutor_missing_match.xml.in b/boards/writing_tutor_missing_match.xml.in
deleted file mode 100644
index e089bd1..0000000
--- a/boards/writing_tutor_missing_match.xml.in
+++ /dev/null
@@ -1,20 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<GCompris>
- <Board
- name="writing_tutor_missing_match"
- type="python:writing_tutor_missing_match"
- section="/experimental/writing_tutor"
- icon="boardicons/writing_tutor_missing_match.png"
- difficulty="1"
- mode="normal"
- author="Jozef Cerven (jcmail80@gmail.com)"
- boarddir="tutor">
- <title>Dopĺňanie chýbajúceho písmena</title>
- <description>Úlohou je uhádnuť chýbajúce
-písmenko,a správne ho napísať</description>
- <prerequisite>2. trieda na ZŠ</prerequisite>
- <goal>Uhádnuť a správne napísať chýbajúce písmeno/tvar.</goal>
- <manual>V ľavej časti sa zobrazí slovo, v ktorom chýba niektoré písmenko, ktoré treba uhádnuť, a potom ho správne napísať. Keď ho už máme napísané, stlačíme ruku v spodnom paneli.
- </manual>
- </Board>
-</GCompris>
diff --git a/boards/writing_tutor_pattern_admin.xml.in b/boards/writing_tutor_pattern_admin.xml.in
deleted file mode 100644
index ad7f9dc..0000000
--- a/boards/writing_tutor_pattern_admin.xml.in
+++ /dev/null
@@ -1,18 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<GCompris>
- <Board
- name="writing_tutor_pattern_admin"
- type="python:writing_tutor_pattern_admin"
- section="/experimental/writing_tutor"
- icon="boardicons/writing_tutor_pattern_admin.png"
- difficulty="1"
- mode="normal"
- author="Jozef Cerven (jcmail80@gmail.com)"
- boarddir="tutor">
- <_title>TBD</_title>
- <_description>TBD</_description>
- <_prerequisite></_prerequisite>
- <_goal></_goal>
- <_manual></_manual>
- </Board>
-</GCompris>
diff --git a/boards/writing_tutor_template_match.xml.in b/boards/writing_tutor_template_match.xml.in
deleted file mode 100644
index 10d221f..0000000
--- a/boards/writing_tutor_template_match.xml.in
+++ /dev/null
@@ -1,18 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<GCompris>
- <Board
- name="writing_tutor_template_match"
- type="python:writing_tutor_template_match"
- section="/experimental/writing_tutor"
- icon="boardicons/writing_tutor_template_match.png"
- difficulty="1"
- mode="normal"
- author="Jozef Cerven (jcmail80@gmail.com)"
- boarddir="tutor">
- <_title>TBD</_title>
- <_description>TBD</_description>
- <_prerequisite></_prerequisite>
- <_goal></_goal>
- <_manual></_manual>
- </Board>
-</GCompris>
diff --git a/src/boards/python/writing_tutor_common.py b/src/boards/python/writing_tutor_common.py
deleted file mode 100644
index 49a4e19..0000000
--- a/src/boards/python/writing_tutor_common.py
+++ /dev/null
@@ -1,164 +0,0 @@
-# gcompris/tutor/common.py - Writing Tutor project
-#
-# Author: Jozef Cerven, 5mi, (c) 2006/2007
-# FACULTY OF MATHEMATICS, PHYSICS AND INFORMATICS COMENIUS UNIVERSITY BRATISLAVA, Informatics Teaching and Basic of Informatics department
-# http://www.edi.fmph.uniba.sk
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, see <http://www.gnu.org/licenses/>.
-#
-
-import gnomecanvas
-import gcompris
-import gcompris.utils
-import gcompris.bonus
-import gcompris.skin
-import gcompris.anim
-import gcompris.sound
-import gcompris.admin
-import gcompris.score
-import gtk
-import gtk.gdk
-import random
-import pango
-import time
-import os
-import socket
-import fcntl
-import struct
-import re
-import glob
-import string
-import time
-
-
-
-
-# BEGIN OF class GtkInputDialog ************************************
-class GtkInputDialog:
-
- inputd = None
-
- def __init__(self, Gcompris_template_match_instance):
-
- self.gd_instance = Gcompris_template_match_instance
-
- self.inputd = gtk.InputDialog()
- self.inputd.move((gcompris.BOARD_WIDTH)/2, (gcompris.BOARD_HEIGHT)/2) # !
- self.inputd.connect("enable-device", self.clb_enable_device)
- self.inputd.connect("disable-device", self.clb_disable_device)
- self.inputd.connect("response", self.clb_close_dialog, None)
- self.inputd.run()
-
- def clb_close_dialog(self, inputdialog, deviceid, x=None):
- self.inputd.hide()
-
-
- def clb_enable_device(self, inputdialog, deviceid, x=None):
- print "clb_enable_device", deviceid.name
-
- if (deviceid.source == gtk.gdk.SOURCE_PEN) and (deviceid.mode == gtk.gdk.MODE_SCREEN or deviceid.mode == gtk.gdk.MODE_WINDOW):
- self.gd_instance.set_tablet_indicator(1)
-
- self.clb_close_dialog(inputdialog, deviceid)
-
- def clb_disable_device(self, inputdialog, deviceid, x=None):
- print "clb_disable_device", deviceid.name
-
- if (deviceid.source == gtk.gdk.SOURCE_PEN):
- self.gd_instance.set_tablet_indicator(0)
-
- self.clb_close_dialog(inputdialog, deviceid)
-
-# END OF class GtkInputDialog ************************************
-
-
-
-def draw_guiding_lines(_pixmap, _area, _pattern, _right, _color='SlateGrey'):
- """
- Description:
- Paint guiding lines according to type of shape (lower, upper, digit, script,...)
-
- Arguments:
- _pixmap -- gtk.gdk.Pixmap
- _area -- gtk.DrawingArea
- _pattern -- pattern to be written
- _color -- foreground color of lines, color string specified in the X11 rgb.txt
- """
-
- left = 60
- right = _right
- top = 60
- bottom = 450
-
- colormap = _area.get_colormap()
- _color_ = colormap.alloc_color(_color)
-
- gc_solid = _pixmap.new_gc()
- gc_solid.copy(_area.get_style().black_gc)
- gc_solid.set_foreground(_color_)
- gc_solid.set_line_attributes(2, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_BUTT, gtk.gdk.JOIN_MITER)
-
- gc_dash = _pixmap.new_gc()
- gc_dash.copy(gc_solid)
- gc_dash.set_foreground(_color_)
- gc_dash.set_line_attributes(1, gtk.gdk.LINE_ON_OFF_DASH, gtk.gdk.CAP_BUTT, gtk.gdk.JOIN_MITER)
-
- _pixmap.draw_line(gc_dash, left, top, right, top) # top line
- _pixmap.draw_line(gc_dash, left, bottom, right, bottom) # bottom line
-
-
- if _pattern[0] == '_': # tlacene pismena..(in english?)
- _pixmap.draw_line(gc_solid, left, top+40, right, top+40) # top1 line
- if _pattern[1] in ['a','b','c','d','e','f','h','i','k','l','m','n','o','r','s','t','u','v','z']:
- _pixmap.draw_line(gc_dash, left, 200, right, 200)
- _pixmap.draw_line(gc_solid, left, bottom-40, right, bottom-40)
- elif _pattern[1] in ['g','p']:
- _pixmap.draw_line(gc_dash, left, 320, right, 320)
- _pixmap.draw_line(gc_solid, left, bottom-40, right, bottom-40)
- elif _pattern[1] in ['j']:
- _pixmap.draw_line(gc_dash, left, 210, right, 210)
- _pixmap.draw_line(gc_solid, left, bottom-50, right, bottom-50)
- elif _pattern[1] in ['A','B','E','F','G','H','J','K','P','R',]:
- _pixmap.draw_line(gc_dash, left, 260, right, 260)
- _pixmap.draw_line(gc_solid, left, bottom-40, right, bottom-40)
- elif _pattern[1] in ['C','D','I','L','M','N','O','S','T','U','V','Z']:
- _pixmap.draw_line(gc_dash, left, 200, right, 200)
- _pixmap.draw_line(gc_solid, left, bottom-40, right, bottom-40)
-
-
- elif _pattern[0] == '@': # geometric shapes
- pass
-
- else: # pisane pismena male aj velke, a cislice 0-9
- _pixmap.draw_line(gc_solid, left, top+40, right, top+40) # top1 line
- if _pattern[0] not in ['f','g','G','j','J','p']:
- _pixmap.draw_line(gc_dash, left, 240, right, 240)
- _pixmap.draw_line(gc_solid, left, bottom-40, right, bottom-40)
- else:
- _pixmap.draw_line(gc_dash, left, 210, right, 210)
- _pixmap.draw_line(gc_solid, left, bottom-110, right, bottom-110)
-
-
-
-
-
-def get_ip_address(ifname):
- try:
- s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
- return socket.inet_ntoa(fcntl.ioctl(s.fileno(), 0x8915, struct.pack('256s', ifname[:15]))[20:24])
- except:
- return "127.0.0.1"
-
-
-
diff --git a/src/boards/python/writing_tutor_image_match.py b/src/boards/python/writing_tutor_image_match.py
deleted file mode 100644
index 29614a5..0000000
--- a/src/boards/python/writing_tutor_image_match.py
+++ /dev/null
@@ -1,749 +0,0 @@
-# gcompris/tutor/image_match.py - Writing Tutor project
-#
-# Author: Jozef Cerven, 5mi, (c) 2006/2007
-# FACULTY OF MATHEMATICS, PHYSICS AND INFORMATICS COMENIUS UNIVERSITY BRATISLAVA, Informatics Teaching and Basic of Informatics department
-# http://www.edi.fmph.uniba.sk
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, see <http://www.gnu.org/licenses/>.
-#
-
-
-import gnomecanvas
-import gcompris
-import gcompris.utils
-import gcompris.bonus
-import gcompris.skin
-import gcompris.anim
-import gcompris.sound
-import gcompris.admin
-import gcompris.score
-import gtk
-import gtk.gdk
-import random
-import pango
-import time
-import os
-import socket
-import fcntl
-import struct
-import re
-import glob
-import string
-import time
-
-
-#import gobject
-from gcompris import gcompris_gettext as _
-
-from writing_tutor_common import *
-
-import DTW.dtw
-
-
-_global_rootitem = None # for config dialog
-_global_tablet_indicator= None
-
-
-
-
-
-# BEGIN OF class Gcompris_image_match ************************************
-class Gcompris_writing_tutor_image_match:
-
- _ap = None
- ap = None
- _sb = None
- sb = None
-
- rootitem = None
- board_paused = 0
-
- save_path = None
- sequence = None
- pattern = None
- pattern_image = None
- show_template = 100*[None] # if show_template[0]==1: show_template in level 1
-
- area = None
- notepad_area = None
- label = None
- won_level = 0
-
- dat_filename = None
- pixmap = None # drawing area pixmap
- filename = None
- file_handle = None
- writing_status = None
- last_written_point_index = None
- motions_count = None
- points = [None] * 2000
- cas_start = None
- button_pixbuf = None
-
- def __init__(self, gcomprisBoard):
- self.gcomprisBoard = gcomprisBoard
-
- _notepad_width = 485
- _notepad_height = 485
-
- #self.notepad_area = ((gcompris.BOARD_WIDTH/2 - _notepad_width/2), 20, _notepad_width, _notepad_height) # centered
- self.notepad_area = (280, 10, _notepad_width, _notepad_height)
-
-
-
- def start(self):
- global _global_rootitem
-
- self.window = self.gcomprisBoard.canvas.get_toplevel()
-
- self.config_dict = self.init_config()
- self.config_dict.update(gcompris.get_board_conf())
-
- self.save_path = self.config_dict['save_path']
- self.sequence = self.config_dict['image_match_sequence']
-
- self.parse_sequence()
-
- self.gcomprisBoard.level=1
- self.gcomprisBoard.maxlevel=len(self.sequence)
- self.gcomprisBoard.sublevel=1
- self.gcomprisBoard.number_of_sublevel = len(self.sequence[self.gcomprisBoard.level-1])
-
-
- _pixmap = gcompris.utils.load_pixmap(gcompris.skin.image_to_skin("button_reload.png"))
- if(_pixmap):
- gcompris.bar_set_repeat_icon(_pixmap)
- gcompris.bar_set(gcompris.BAR_LEVEL|gcompris.BAR_OK|gcompris.BAR_REPEAT_ICON|gcompris.BAR_CONFIG)
- else:
- gcompris.bar_set(gcompris.BAR_LEVEL|gcompris.BAR_OK|gcompris.BAR_REPEAT|gcompris.BAR_CONFIG)
-
-
- #gcompris.set_background(self.rootitem, gcompris.skin.image_to_skin("gcompris-bg.jpg"))
- gcompris.set_background(self.rootitem, "writing_tutor/wood_pine.png")
-
-
- # 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.
- self.rootitem = self.gcomprisBoard.canvas.root().add(gnomecanvas.CanvasGroup, x=0.0, y=0.0)
- _global_rootitem = self.rootitem
-
-
- # show tablet indicator icon
-
- _t_active = 0
- _devices = gtk.gdk.devices_list()
- for _d in _devices:
- if _d.source == gtk.gdk.SOURCE_PEN:
- _t_active = 1
- if _d.mode == gtk.gdk.MODE_DISABLED: # if tablet is disabled
- _d.set_mode(gtk.gdk.MODE_SCREEN) # enable it (first in sequence)
- break
- else: # already enabled..
- break
-
- if _t_active == 1:
- self.set_tablet_indicator(1)
- else:
- self.set_tablet_indicator(0)
-
-
- self.set_level(1)
-
-
-
-
- def recreate_drawing_area(self):
-
- # BEGIN OF drawing_area ************************************
-
- if self.area != None:
- self.area.destroy()
-
- self.area = gtk.DrawingArea()
-
- # Signals used to handle backing pixmap
- self.area.connect("expose_event", self.expose_event)
- self.area.connect("configure_event", self.configure_event)
-
- # Event signals
- self.area.connect("motion_notify_event", self.motion_notify_event)
- #area.connect("button_press_event", self.button_press_event)
-
- self.area.set_events(gtk.gdk.EXPOSURE_MASK | gtk.gdk.LEAVE_NOTIFY_MASK | gtk.gdk.BUTTON_PRESS_MASK
- | gtk.gdk.POINTER_MOTION_MASK | gtk.gdk.PROXIMITY_IN | gtk.gdk.PROXIMITY_OUT_MASK)
-
- # The following call enables tracking and processing of extension
- # events for the drawing area
- #self.area.set_extension_events(gtk.gdk.EXTENSION_EVENTS_CURSOR)
- self.area.set_extension_events(gtk.gdk.EXTENSION_EVENTS_ALL)
-
- self.rootitem.add(gnomecanvas.CanvasWidget, widget=self.area, x=self.notepad_area[0], y=self.notepad_area[1],
- width=self.notepad_area[2], height=self.notepad_area[3])
-
- self.area.show()
- # END OF drawing_area ************************************
-
- #print "recreate_drawing_area()"
-
-
-
- def start_2(self, recreate="yes"):
-
- self.pattern = self.sequence[self.gcomprisBoard.level-1][self.gcomprisBoard.sublevel-1]
- gcompris.score.set(self.gcomprisBoard.sublevel)
- self.draw_image(30, 150, self.pattern)
- self.won_level = 0
-
- if recreate == "yes":
- self.recreate_drawing_area()
-
- if self.show_template[self.gcomprisBoard.level-1] == 1: # level with "show_template"
- predlohy_dir = self.save_path + "/writing_tutor/predlohy/" + self.pattern + "/"
- if not os.path.exists(predlohy_dir):
- print "%s DOES NOT EXISTS!", predlohy_dir
- else:
- arglist = []
- os.path.walk(predlohy_dir,self.walk_callback,arglist)
-
- ip = get_ip_address('eth0') # eth0
- datum = time.strftime('%d.%m.%Y_%X').replace('/','.')
- filename1 = self.save_path + "/writing_tutor/predloha_test/" + self.pattern
- self.filename = filename1 + "/" + ip + "__" + datum + ".dat"
- # musi existovat cesta => adresare!
- if not os.path.exists(filename1):
- os.makedirs(filename1)
-
- self.file_handle = open(self.filename,"w")
-
- self.show_pen_animation(1)
-
-
-
-
- def walk_callback(self, arg, dirname, fnames ):
- global area
-
- # print "dirname: ", dirname
- if len(fnames) < 1:
- print "walk_callback: len(fnames)<1 !! : ", len(fnames)
-
- for _filename in fnames:
- if os.path.getsize(dirname+_filename) > 0:
- # print "df: ", dirname , _filename
- _filehandle = open(dirname + _filename, "r")
- for line in _filehandle:
- l = line.split()
- #print "x=",l[0]," y=",l[1], " pressure=", l[2]
- self.draw_brush(self.area, float(l[0]), float(l[1]), float(l[2]),'predloha')
- time.sleep(0.010)
- _filehandle.close()
- break # berieme len prvu predlohu v adresari
-
-
-
- # BEGIN OF drawing_area HANDLERS ************************************
- # Create a new backing pixmap of the appropriate size
- def configure_event(self, widget, event):
- x, y, width, height = widget.get_allocation()
- self.pixmap = gtk.gdk.Pixmap(widget.window, width, height)
- #self.pixmap.draw_rectangle(widget.get_style().white_gc, True, 0, 0, width, height)
-
- #pixbuf = gcompris.utils.load_pixmap("boardicons/notepad.png")
- tmp = self.gcomprisBoard.filename.split("/")
- _file = tmp[len(tmp)-1]
- tmp.remove(_file)
- _board_dir = "/".join(tmp)
-
- pixbuf = gtk.gdk.pixbuf_new_from_file(_board_dir + "/writing_tutor/wood_pine.png") # transparent png
- self.pixmap.draw_pixbuf(widget.get_style().fg_gc[gtk.STATE_NORMAL], pixbuf, 0, 0, 0, 0, width, height)
- pixbuf = gtk.gdk.pixbuf_new_from_file(_board_dir + "/writing_tutor/notepad.png") # transparent png
- self.pixmap.draw_pixbuf(widget.get_style().fg_gc[gtk.STATE_NORMAL], pixbuf, 0, 0, 0, 0, width, height)
-
- draw_guiding_lines(self.pixmap, self.area, self.pattern, 450)
-
- return True
-
-
- # Redraw the screen from the backing pixmap
- def expose_event(self, widget, event):
- x , y, width, height = event.area
- widget.window.draw_drawable(widget.get_style().fg_gc[gtk.STATE_NORMAL], self.pixmap, x, y, x, y, width, height)
- return False
-
-
- def draw_brush(self, widget, x, y, pressure, _type='vzorka'):
-
- colormap = self.area.get_colormap()
- if _type == 'predloha':
- color = colormap.alloc_color(86*256, 153*256, 215*256) # slabo modra
- rect = (int(x-4*pressure), int(y-4*pressure), int(8*pressure), int(8*pressure))
- else:
- color = colormap.alloc_color(97*256, 105*256, 141*256) # tmavo seda
- rect = (int(x-5*pressure), int(y-5*pressure), int(10*pressure), int(10*pressure))
-
-
- gc = self.area.get_style().fg_gc[gtk.STATE_NORMAL]
- gc.foreground = color
-
- self.pixmap.draw_rectangle(widget.get_style().fg_gc[gtk.STATE_NORMAL], True, rect[0], rect[1], rect[2], rect[3])
- widget.window.draw_drawable(widget.get_style().fg_gc[gtk.STATE_NORMAL], self.pixmap, rect[0], rect[1], rect[0], rect[1], rect[2], rect[3])
-
- while gtk.events_pending(): gtk.main_iteration() # refreshing widget
-
- # nastavim naspat ciernu
- color = colormap.alloc_color(0,0,0) # slabo modra
- gc = self.area.get_style().fg_gc[gtk.STATE_NORMAL]
- gc.foreground = color
-
-
-
- def motion_notify_event(self, widget, event):
- #if not self.can_write: #!!
- # return True
- # is_hint => mys
- if event.is_hint:
- x, y, state = event.window.get_pointer()
- pressure = 0.0
- x_tilt = 0.0
- y_tilt = 0.0
- else: # pero tabletu
- state = event.state
- x = event.get_axis(gtk.gdk.AXIS_X)
- y = event.get_axis(gtk.gdk.AXIS_Y)
- pressure = event.get_axis(gtk.gdk.AXIS_PRESSURE)
- x_tilt = event.get_axis(gtk.gdk.AXIS_XTILT) # musi to podporovat tablet,napr "Wacom Intuos"
- if x_tilt == None:
- x_tilt = 0.0
- y_tilt = event.get_axis(gtk.gdk.AXIS_YTILT)
- if y_tilt == None:
- y_tilt = 0.0
-
- #wheel = event.get_axis(gtk.gdk.AXIS_WHEEL) #?
- #print "x=",x," y=",y," pressure=",pressure, " x_tilt=", x_tilt," y_tilt=",y_tilt
-
-
- if (not (x >= 10 and x <= 485 and y >= 10 and y<= 485)): #if not in drawing_area_rect:
- if self.writing_status == 1:
- self.writing_status = None
- return True
-
-
- if state & gtk.gdk.BUTTON1_MASK and self.pixmap != None:
-
- if event.is_hint:
- pressure = 1.0
- if pressure == None:
- pressure = 1.0
-
- if self.writing_status == None and pressure > 0.0:
- self.show_pen_animation(0)
- self.writing_status = 1 # zacal som pisat pismeno/zaznamenavat udaje
- self.motions_count = 1
- self.cas_start = time.time() # pri zaciatku pisania pismena sa poznaci cas
-
-
-
- if pressure > 0.0:
- self.draw_brush(widget, x, y, pressure)
- self.last_written_point_index = self.motions_count
-
- if self.writing_status == 1:
- #points[motions_count] = str(int(x)) + " " + str(int(y)) + " " + str(int(pressure)) + "\n"
- self.points[self.motions_count] = str(float(x)) + " " + str(float(y)) + " " + str(pressure) + " " + str(x_tilt) + " " + str(y_tilt) + " " + str((time.time()-self.cas_start)*1000.0) + "\n"
- #print "points[",motions_count,"]=", points[motions_count]
- self.motions_count = self.motions_count + 1
-
- return True
-
-
-
- # END OF drawing_area HANDLERS ************************************
-
-
-
- #def onBoard(self, x, y):
- # return x >= 0 and x < self.width and y >= 0 and y < self.height
-
-
-
- def draw_image(self, x, y, _pattern):
- _pixmap = gcompris.utils.load_pixmap("writing_tutor/image_match/" + self.pattern + ".png")
-
- if self.pattern_image != None:
- self.pattern_image.destroy()
-
- self.pattern_image = self.rootitem.add(gnomecanvas.CanvasPixbuf, pixbuf = _pixmap, x = 20, y = 150)
- self.pattern_image.show()
-
-
-
- def end(self):
- #gcompris.sound.reopen()
-
- if self.rootitem != None:
- self.rootitem.destroy()
- self.rootitem = None
- gcompris.score.end()
- pass
-
-
- def get_datfiles_list(self, _pattern):
-
- dat_list = glob.glob(self.save_path + "/writing_tutor/predlohy/" + _pattern + "/*.dat")
- res_dat_list = []
- for _file in dat_list:
- if os.stat(_file).st_size > 0:
- res_dat_list.append(_file) # v zozname necha len neprazdne subory
-
- return res_dat_list
-
-
- def _remove_empty_list_item(self, _list):
- if '' in _list:
- _list.remove('')
-
- return _list
-
-
- def parse_sequence(self):
- """ parse sequence string into levels and sublevels """
- # sequence:
- # a|b|@kruh$ - $ :level separator
- # x|@tvar
-
- _sequence = re.sub(r'\s', '', self.sequence) # remove white spaces
- _sequence = _sequence.split("$") # divide into levels (this activity has 2 levels)
- _sequence = self._remove_empty_list_item(_sequence) # remove empty level string if extsts
- self.sequence = []
-
-
- tmp = self.gcomprisBoard.filename.split("/")
- _file = tmp[len(tmp)-1]
- tmp.remove(_file)
- _board_dir = "/".join(tmp)
-
- _level = 0
- for _s in _sequence: # for each level (should be max 2)
- _s_tmp = _s
- _dat_list = self._remove_empty_list_item(_s_tmp.split("|"))
- _non_empty_dat_list = _dat_list[:]
- for s in _dat_list: # for each pattern in level
- if s != '*':
- img_path = _board_dir + "/writing_tutor/image_match/" + s + ".png"
- if (len(self.get_datfiles_list(s)) < 1) or (not os.path.exists(img_path)): # iba ak existuju .dat subor predlohy a obrazok
- _non_empty_dat_list.remove(s)
-
- if _non_empty_dat_list.count('*') > 0:
- _non_empty_dat_list.remove('*')
- self.show_template[_level] = 1
- else:
- self.show_template[_level] = 0
-
- _level += 1
-
- if len(_non_empty_dat_list) > 0:
- self.sequence.append(_non_empty_dat_list)
-
-
-
-
-
- # Called by gcompris when the user click on the level icon
- def set_level(self, level):
- #print "set_level: level=",level
-
- if self.gcomprisBoard.sublevel-1 == self.gcomprisBoard.number_of_sublevel and self.gcomprisBoard.level == self.gcomprisBoard.maxlevel:
- gcompris.bonus.board_finished(gcompris.bonus.FINISHED_RANDOM)
- self.won_level = 1
- return
-
- self.gcomprisBoard.level=level
- self.gcomprisBoard.sublevel=1
- self.gcomprisBoard.number_of_sublevel = len(self.sequence[self.gcomprisBoard.level-1])
- gcompris.bar_set_level(self.gcomprisBoard) # nastavi kocku na cislo levelu
-
- gcompris.score.start(gcompris.score.STYLE_NOTE, 10, 50, len(self.sequence[self.gcomprisBoard.level-1]))
-
- self.start_2("yes")
-
-
-
- def increment_level(self):
- self.gcomprisBoard.sublevel += 1
- if self.gcomprisBoard.sublevel > self.gcomprisBoard.number_of_sublevel:
- self.set_level(self.gcomprisBoard.level % self.gcomprisBoard.maxlevel + 1)
- else:
- self.start_2("yes")
-
-
- # stlacenie "ruky"
- def ok(self):
-
- self.writing_status = None
-
- # zapise do suboru vsetky body od prveho prilozenia pera, az po posledny napisany bod..
-
- if self.last_written_point_index != None: # if something was written...
- for i in range(self.last_written_point_index):
- self.file_handle.write(self.points[i+1])
-
- self.file_handle.close()
-
- self.show_sablier_animation(1)
-
- _dtw = DTW.dtw.DTW(self.save_path, self.pattern)
- dtw_res = _dtw.dtw(self.filename, 1)
- print "ok: dtw_res=", str(dtw_res)
-
- self.show_sablier_animation(0)
-
- if self.pattern[0] == '@':
- limit = 13
- else:
- limit = 9
-
- if self.show_template[self.gcomprisBoard.level-1] == 1:
- limit = 5
-
- if dtw_res < limit:
- gcompris.bonus.display(gcompris.bonus.WIN, gcompris.bonus.RANDOM)
- self.won_level = 1
- else:
- gcompris.bonus.display(gcompris.bonus.LOOSE, gcompris.bonus.RANDOM)
- self.won_level = 1
-
- else: # none was written
- gcompris.bonus.display(gcompris.bonus.LOOSE, gcompris.bonus.RANDOM)
- self.won_level = 1
-
-
- self.last_written_point_index = None
-
-
-
-
-
-
- def key_press(self, keyval, commit_str, preedit_str):
- return False
-
- def repeat(self):
- print "repeat"
- self.start_2("yes")
-
-
-
- def pause(self, pause): # called after config dialog, help, bonus
- print "pause"
-
- self.board_paused = pause
-
- if(pause):
- self.area.hide()
- self.show_pen_animation(0)
- if self.label != None:
- self.label.hide()
- else:
- self.area.show()
- if self.won_level:
- # if we are paused, then unpaused it means that they beat the sublevel
- self.increment_level()
- else:
- self.set_level(self.gcomprisBoard.level)
-
- ## There is a problem with GTK widgets, they are not covered by the help, We hide/show them here
- #if(pause):
- # self.area.hide()
- #else:
- # self.area.show()
- # self.repeat()
-
-
- return
-
-
-
- def config(self):
- print "Config"
- pass
-
- def config_stop(self):
- print "config_stop", self
- pass
-
-
-
-
- def show_pen_animation(self, show):
- if show == 0:
- if self.ap != None:
- self.ap.gnomecanvas.hide()
- else:
- if self.ap == None:
- self._ap = gcompris.anim.Animation("writing_tutor/anim_pen.txt")
- self.ap = gcompris.anim.CanvasItem(self._ap, self.rootitem)
- self.ap.gnomecanvas.set(x=80, y=gcompris.BOARD_HEIGHT - 70)
- self.ap.setState(0)
- self.ap.gnomecanvas.show()
- else:
- self.ap.gnomecanvas.show()
-
-
- def show_sablier_animation(self, show):
- if show == 0:
- if self.sb != None:
- self.sb.gnomecanvas.hide()
- else:
- if self.sb == None:
- self._sb = gcompris.anim.Animation("connect4/sablier.txt")
- self.sb = gcompris.anim.CanvasItem(self._sb, self.rootitem)
- self.sb.gnomecanvas.set(x=40, y= gcompris.BOARD_HEIGHT - 230)
- self.sb.setState(0)
- self.sb.gnomecanvas.show()
- else:
- self.sb.gnomecanvas.show()
-
-
-
-
-
- def set_tablet_indicator(self, tablet_status):
- """
- Description:
- Set tablet indicator icon
-
- Arguments:
- tablet_status -- 1 or 0 indicating status of tablet device (enabled or disabled)
- """
- global _global_rootitem
- global _global_tablet_indicator
-
- #print "set_tablet_indicator(", tablet_status, ")"
-
- if tablet_status == 1:
- _pixmap = gcompris.utils.load_pixmap("writing_tutor/tablet_active.png")
- else:
- _pixmap = gcompris.utils.load_pixmap("writing_tutor/tablet_inactive.png")
-
- if _global_tablet_indicator != None:
- _global_tablet_indicator.destroy()
-
- _global_tablet_indicator = _global_rootitem.add(gnomecanvas.CanvasPixbuf, pixbuf = _pixmap, x = 10, y = gcompris.BOARD_HEIGHT -50)
- _global_tablet_indicator.show()
-
-
-
- def config_start(self, profile):
- print "config_start"
- global _global_rootitem
-
-
- # show only tablet configuration. save_path, sequence only in admin mode
- if _global_rootitem != None: # not in admin mode
- dlg = GtkInputDialog(self)
- return
-
- self.configure_profile = profile
-
- self.config_dict = self.init_config()
- self.config_dict.update(gcompris.get_conf(profile, self.gcomprisBoard))
-
- self.main_vbox = gcompris.configuration_window (\
- _('Hra <b>%s</b> - nastavenie pre profil <b>%s</b>') % ('Tutor', profile.name), self.save_config)
-
- gcompris.separator()
- self.button = gtk.Button("Nastavenie tabletu...")
- self.button.connect("clicked", self.input_dlg_callback)
- self.button.show()
- self.main_vbox.pack_start(self.button, False, False, 0)
- gcompris.separator()
-
- # !! ak je v admin mode, tak nemoze nastavovat tablet...
- if _global_rootitem == None: # in admin mode
- self.button.set_state(gtk.STATE_INSENSITIVE)
-
-
- gcompris.textview(_('Adresar, kde sa budu ukladat vzorky/predlohy: '), 'save_path', 'desc', self.config_dict['save_path'],
- self.validate_callback)
- gcompris.separator()
-
- gcompris.textview(_('Postupnosti tvarov pre testovanie: '), 'image_match_sequence', 'desc', self.config_dict['image_match_sequence'], self.validate_callback)
- gcompris.separator()
-
-
- def validate_callback(self, key, value, z):
- #print "validate_callback: key=", key, ", value=", value, ", z=", z
-
- if key == 'save_path':
- if not os.path.exists(value):
- return False
- if key == 'sequence':
- pass
-
- return True
-
-
- def input_dlg_callback(self, table):
- dlg = GtkInputDialog()
-
-
- def dummy_enter_callback(self, widget, _entry):
- pass
-
- def clb_dummy(self, x=None):
- pass
-
- def save_config(self, table):
- print "save_config: table=", table
- global _global_rootitem
-
- if table == None:
- return
-
- for key,value in table.iteritems():
- gcompris.set_board_conf(self.configure_profile, self.gcomprisBoard, key, value) # save config to db
-
- if _global_rootitem != None:
- self.start_2("no")
-
-
- def configuration(self, value, init):
- if self.config_dict.has_key(value):
- return eval(self.config_dict[value])
- else:
- return init
-
-
- def init_config(self):
- default_config_dict = { 'save_path' : gcompris.get_properties().user_dir ,
- 'image_match_sequence' : 'a|b|g $ @kruh|@stvorec'
- }
- return default_config_dict
-
- # sequence format:
-
- #a|b|c|d $ 1. level
- #@kruh $ 2. level
-
-
-
-# END OF class Gcompris_image_match ************************************
-
-
-
-
-def stop_board():
- gcompris.bonus.board_finished(gcompris.bonus.FINISHED_RANDOM)
-
-
diff --git a/src/boards/python/writing_tutor_missing_match.py b/src/boards/python/writing_tutor_missing_match.py
deleted file mode 100644
index 7169911..0000000
--- a/src/boards/python/writing_tutor_missing_match.py
+++ /dev/null
@@ -1,734 +0,0 @@
-# gcompris/tutor/missing_match.py - Writing Tutor project
-#
-# Author: Jozef Cerven, 5mi, (c) 2006/2007
-# FACULTY OF MATHEMATICS, PHYSICS AND INFORMATICS COMENIUS UNIVERSITY BRATISLAVA, Informatics Teaching and Basic of Informatics department
-# http://www.edi.fmph.uniba.sk
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, see <http://www.gnu.org/licenses/>.
-#
-
-
-
-import gnomecanvas
-import gcompris
-import gcompris.utils
-import gcompris.bonus
-import gcompris.skin
-import gcompris.anim
-import gcompris.sound
-import gcompris.admin
-import gcompris.score
-import gtk
-import gtk.gdk
-import random
-import pango
-import time
-import os
-import socket
-import fcntl
-import struct
-import re
-import glob
-import string
-import time
-
-
-#import gobject
-from gcompris import gcompris_gettext as _
-
-from writing_tutor_common import *
-
-import DTW.dtw
-
-
-_global_rootitem = None # for config dialog
-_global_tablet_indicator= None
-
-
-
-
-
-# BEGIN OF class Gcompris_missing_match ************************************
-class Gcompris_writing_tutor_missing_match:
-
- _ap = None
- ap = None
- _sb = None
- sb = None
-
- rootitem = None
- board_paused = 0
-
- save_path = None
- sequence = None
- pattern = None # eg 'a'
- word = None # eg: c_r
- show_template = 100*[None] # if show_template[0]==1: show_template in level 1
-
- area = None
- notepad_area = None
- label = None
- won_level = 0
-
- dat_filename = None
- pixmap = None # drawing area pixmap
- filename = None
- file_handle = None
- writing_status = None
- last_written_point_index = None
- motions_count = None
- points = [None] * 2000
- cas_start = None
- button_pixbuf = None
-
- def __init__(self, gcomprisBoard):
- self.gcomprisBoard = gcomprisBoard
-
- _notepad_width = 485
- _notepad_height = 485
-
- #self.notepad_area = ((gcompris.BOARD_WIDTH/2 - _notepad_width/2), 20, _notepad_width, _notepad_height) # centered
- self.notepad_area = (280, 10, _notepad_width, _notepad_height)
-
-
-
- def start(self):
- global _global_rootitem
-
- self.window = self.gcomprisBoard.canvas.get_toplevel()
-
- self.config_dict = self.init_config()
- self.config_dict.update(gcompris.get_board_conf())
-
- self.save_path = self.config_dict['save_path']
- self.sequence = self.config_dict['missing_match_sequence']
-
- self.parse_sequence()
-
- self.gcomprisBoard.level=1
- self.gcomprisBoard.maxlevel=len(self.sequence)
- self.gcomprisBoard.sublevel=1
- self.gcomprisBoard.number_of_sublevel = len(self.sequence[self.gcomprisBoard.level-1])
-
-
- _pixmap = gcompris.utils.load_pixmap(gcompris.skin.image_to_skin("button_reload.png"))
- if(_pixmap):
- gcompris.bar_set_repeat_icon(_pixmap)
- gcompris.bar_set(gcompris.BAR_LEVEL|gcompris.BAR_OK|gcompris.BAR_REPEAT_ICON|gcompris.BAR_CONFIG)
- else:
- gcompris.bar_set(gcompris.BAR_LEVEL|gcompris.BAR_OK|gcompris.BAR_REPEAT|gcompris.BAR_CONFIG)
-
-
- #gcompris.set_background(self.rootitem, gcompris.skin.image_to_skin("gcompris-bg.jpg"))
- gcompris.set_background(self.rootitem, "writing_tutor/wood_pine.png")
-
-
- # 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.
- self.rootitem = self.gcomprisBoard.canvas.root().add(gnomecanvas.CanvasGroup, x=0.0, y=0.0)
- _global_rootitem = self.rootitem
-
-
- # show tablet indicator icon
-
- _t_active = 0
- _devices = gtk.gdk.devices_list()
- for _d in _devices:
- if _d.source == gtk.gdk.SOURCE_PEN:
- _t_active = 1
- if _d.mode == gtk.gdk.MODE_DISABLED: # if tablet is disabled
- _d.set_mode(gtk.gdk.MODE_SCREEN) # enable it (first in sequence)
- break
- else: # already enabled..
- break
-
- if _t_active == 1:
- self.set_tablet_indicator(1)
- else:
- self.set_tablet_indicator(0)
-
-
- self.set_level(1)
-
-
-
-
- def recreate_drawing_area(self):
-
- # BEGIN OF drawing_area ************************************
-
- if self.area != None:
- self.area.destroy()
-
- self.area = gtk.DrawingArea()
-
- # Signals used to handle backing pixmap
- self.area.connect("expose_event", self.expose_event)
- self.area.connect("configure_event", self.configure_event)
-
- # Event signals
- self.area.connect("motion_notify_event", self.motion_notify_event)
- #area.connect("button_press_event", self.button_press_event)
-
- self.area.set_events(gtk.gdk.EXPOSURE_MASK | gtk.gdk.LEAVE_NOTIFY_MASK | gtk.gdk.BUTTON_PRESS_MASK
- | gtk.gdk.POINTER_MOTION_MASK | gtk.gdk.PROXIMITY_IN | gtk.gdk.PROXIMITY_OUT_MASK)
-
- # The following call enables tracking and processing of extension
- # events for the drawing area
- #self.area.set_extension_events(gtk.gdk.EXTENSION_EVENTS_CURSOR)
- self.area.set_extension_events(gtk.gdk.EXTENSION_EVENTS_ALL)
-
- self.rootitem.add(gnomecanvas.CanvasWidget, widget=self.area, x=self.notepad_area[0], y=self.notepad_area[1],
- width=self.notepad_area[2], height=self.notepad_area[3])
-
- self.area.show()
- # END OF drawing_area ************************************
-
- #print "recreate_drawing_area()"
-
-
-
- def start_2(self, recreate="yes"):
-
- self.word = self.sequence[self.gcomprisBoard.level-1][self.gcomprisBoard.sublevel-1].split('&')[0]
- self.pattern = self.sequence[self.gcomprisBoard.level-1][self.gcomprisBoard.sublevel-1].split('&')[1]
- gcompris.score.set(self.gcomprisBoard.sublevel)
- self.won_level = 0
-
- if recreate == "yes":
- self.recreate_drawing_area()
-
- self.draw_text(140, 150, self.word)
-
- if self.show_template[self.gcomprisBoard.level-1] == 1: # level with "show_template"
- predlohy_dir = self.save_path + "/writing_tutor/predlohy/" + self.pattern + "/"
- if not os.path.exists(predlohy_dir):
- print "%s DOES NOT EXISTS!", predlohy_dir
- else:
- arglist = []
- os.path.walk(predlohy_dir,self.walk_callback,arglist)
-
- ip = get_ip_address('eth0') # eth0
- datum = time.strftime('%d.%m.%Y_%X').replace('/','.')
- filename1 = self.save_path + "/writing_tutor/predloha_test/" + self.pattern
- self.filename = filename1 + "/" + ip + "__" + datum + ".dat"
- # musi existovat cesta => adresare!
- if not os.path.exists(filename1):
- os.makedirs(filename1)
-
- self.file_handle = open(self.filename,"w")
-
- self.show_pen_animation(1)
-
-
-
-
- def walk_callback(self, arg, dirname, fnames ):
- global area
-
- # print "dirname: ", dirname
- if len(fnames) < 1:
- print "walk_callback: len(fnames)<1 !! : ", len(fnames)
-
- for _filename in fnames:
- if os.path.getsize(dirname+_filename) > 0:
- # print "df: ", dirname , _filename
- _filehandle = open(dirname + _filename, "r")
- for line in _filehandle:
- l = line.split()
- #print "x=",l[0]," y=",l[1], " pressure=", l[2]
- self.draw_brush(self.area, float(l[0]), float(l[1]), float(l[2]),'predloha')
- time.sleep(0.010)
- _filehandle.close()
- break # berieme len prvu predlohu v adresari
-
-
-
- # BEGIN OF drawing_area HANDLERS ************************************
- # Create a new backing pixmap of the appropriate size
- def configure_event(self, widget, event):
- x, y, width, height = widget.get_allocation()
- self.pixmap = gtk.gdk.Pixmap(widget.window, width, height)
- #self.pixmap.draw_rectangle(widget.get_style().white_gc, True, 0, 0, width, height)
-
- #pixbuf = gcompris.utils.load_pixmap("boardicons/notepad.png")
- tmp = self.gcomprisBoard.filename.split("/")
- _file = tmp[len(tmp)-1]
- tmp.remove(_file)
- _board_dir = "/".join(tmp)
-
- pixbuf = gtk.gdk.pixbuf_new_from_file(_board_dir + "/writing_tutor/wood_pine.png") # transparent png
- self.pixmap.draw_pixbuf(widget.get_style().fg_gc[gtk.STATE_NORMAL], pixbuf, 0, 0, 0, 0, width, height)
- pixbuf = gtk.gdk.pixbuf_new_from_file(_board_dir + "/writing_tutor/notepad.png") # transparent png
- self.pixmap.draw_pixbuf(widget.get_style().fg_gc[gtk.STATE_NORMAL], pixbuf, 0, 0, 0, 0, width, height)
-
- draw_guiding_lines(self.pixmap, self.area, self.pattern, 450)
-
- return True
-
-
- # Redraw the screen from the backing pixmap
- def expose_event(self, widget, event):
- x , y, width, height = event.area
- widget.window.draw_drawable(widget.get_style().fg_gc[gtk.STATE_NORMAL], self.pixmap, x, y, x, y, width, height)
- return False
-
-
- def draw_brush(self, widget, x, y, pressure, _type='vzorka'):
-
- colormap = self.area.get_colormap()
- if _type == 'predloha':
- color = colormap.alloc_color(86*256, 153*256, 215*256) # slabo modra
- rect = (int(x-4*pressure), int(y-4*pressure), int(8*pressure), int(8*pressure))
- else:
- color = colormap.alloc_color(97*256, 105*256, 141*256) # tmavo seda
- rect = (int(x-5*pressure), int(y-5*pressure), int(10*pressure), int(10*pressure))
-
-
- gc = self.area.get_style().fg_gc[gtk.STATE_NORMAL]
- gc.foreground = color
-
- self.pixmap.draw_rectangle(widget.get_style().fg_gc[gtk.STATE_NORMAL], True, rect[0], rect[1], rect[2], rect[3])
- widget.window.draw_drawable(widget.get_style().fg_gc[gtk.STATE_NORMAL], self.pixmap, rect[0], rect[1], rect[0], rect[1], rect[2], rect[3])
-
- while gtk.events_pending(): gtk.main_iteration() # refreshing widget
-
- # nastavim naspat ciernu
- color = colormap.alloc_color(0,0,0) # slabo modra
- gc = self.area.get_style().fg_gc[gtk.STATE_NORMAL]
- gc.foreground = color
-
-
-
- def motion_notify_event(self, widget, event):
- #if not self.can_write: #!!
- # return True
- # is_hint => mys
- if event.is_hint:
- x, y, state = event.window.get_pointer()
- pressure = 0.0
- x_tilt = 0.0
- y_tilt = 0.0
- else: # pero tabletu
- state = event.state
- x = event.get_axis(gtk.gdk.AXIS_X)
- y = event.get_axis(gtk.gdk.AXIS_Y)
- pressure = event.get_axis(gtk.gdk.AXIS_PRESSURE)
- x_tilt = event.get_axis(gtk.gdk.AXIS_XTILT) # musi to podporovat tablet,napr "Wacom Intuos"
- if x_tilt == None:
- x_tilt = 0.0
- y_tilt = event.get_axis(gtk.gdk.AXIS_YTILT)
- if y_tilt == None:
- y_tilt = 0.0
-
- #wheel = event.get_axis(gtk.gdk.AXIS_WHEEL) #?
- #print "x=",x," y=",y," pressure=",pressure, " x_tilt=", x_tilt," y_tilt=",y_tilt
-
-
- if (not (x >= 10 and x <= 485 and y >= 10 and y<= 485)): #if not in drawing_area_rect:
- if self.writing_status == 1:
- self.writing_status = None
- return True
-
-
- if state & gtk.gdk.BUTTON1_MASK and self.pixmap != None:
-
- if event.is_hint:
- pressure = 1.0
- if pressure == None:
- pressure = 1.0
-
- if self.writing_status == None and pressure > 0.0:
- self.show_pen_animation(0)
- self.writing_status = 1 # zacal som pisat pismeno/zaznamenavat udaje
- self.motions_count = 1
- self.cas_start = time.time() # pri zaciatku pisania pismena sa poznaci cas
-
-
-
- if pressure > 0.0:
- self.draw_brush(widget, x, y, pressure)
- self.last_written_point_index = self.motions_count
-
- if self.writing_status == 1:
- #points[motions_count] = str(int(x)) + " " + str(int(y)) + " " + str(int(pressure)) + "\n"
- self.points[self.motions_count] = str(float(x)) + " " + str(float(y)) + " " + str(pressure) + " " + str(x_tilt) + " " + str(y_tilt) + " " + str((time.time()-self.cas_start)*1000.0) + "\n"
- #print "points[",motions_count,"]=", points[motions_count]
- self.motions_count = self.motions_count + 1
-
- return True
-
-
-
- # END OF drawing_area HANDLERS ************************************
-
-
-
- def end(self):
- #gcompris.sound.reopen()
-
- if self.rootitem != None:
- self.rootitem.destroy()
- self.rootitem = None
- gcompris.score.end()
- pass
-
-
- def get_datfiles_list(self, _pattern):
-
- dat_list = glob.glob(self.save_path + "/writing_tutor/predlohy/" + _pattern + "/*.dat")
- res_dat_list = []
- for _file in dat_list:
- if os.stat(_file).st_size > 0:
- res_dat_list.append(_file) # v zozname necha len neprazdne subory
-
- return res_dat_list
-
-
- def _remove_empty_list_item(self, _list):
- if '' in _list:
- _list.remove('')
-
- return _list
-
-
- def parse_sequence(self):
- """ parse sequence string into levels and sublevels """
-
- # sequence format:
- #a_to&a|p_ro&e|okn_&o$ | - item separator, $ - level separator, &a - "a" is missing
-
- _sequence = re.sub(r'\s', '', self.sequence) # remove white spaces
- _sequence = _sequence.split("$") # divide into levels (this activity has 2 levels)
- _sequence = self._remove_empty_list_item(_sequence) # remove empty level string if extsts
- self.sequence = []
-
-
- _level = 0
- for _s in _sequence: # for each level (should be max 2)
- _s_tmp = _s
- _dat_list = self._remove_empty_list_item(_s_tmp.split("|"))
- _non_empty_dat_list = _dat_list[:]
- for s in _dat_list: # for each pattern in level
- if s != '*':
- _missing_pattern = s.split('&')[1]
- if len(self.get_datfiles_list(_missing_pattern)) < 1: # iba ak existuju .dat subor predlohy
- _non_empty_dat_list.remove(s)
-
- if _non_empty_dat_list.count('*') > 0:
- _non_empty_dat_list.remove('*')
- self.show_template[_level] = 1
- else:
- self.show_template[_level] = 0
-
- _level += 1
-
- if len(_non_empty_dat_list) > 0:
- self.sequence.append(_non_empty_dat_list)
-
-
-
- # Called by gcompris when the user click on the level icon
- def set_level(self, level):
- #print "set_level: level=",level
-
- if self.gcomprisBoard.sublevel-1 == self.gcomprisBoard.number_of_sublevel and self.gcomprisBoard.level == self.gcomprisBoard.maxlevel:
- gcompris.bonus.board_finished(gcompris.bonus.FINISHED_RANDOM)
- self.won_level = 1
- return
-
- self.gcomprisBoard.level=level
- self.gcomprisBoard.sublevel=1
- self.gcomprisBoard.number_of_sublevel = len(self.sequence[self.gcomprisBoard.level-1])
- gcompris.bar_set_level(self.gcomprisBoard) # nastavi kocku na cislo levelu
-
- gcompris.score.start(gcompris.score.STYLE_NOTE, 10, 50, len(self.sequence[self.gcomprisBoard.level-1]))
-
- self.start_2("yes")
-
-
-
- def increment_level(self):
- self.gcomprisBoard.sublevel += 1
- if self.gcomprisBoard.sublevel > self.gcomprisBoard.number_of_sublevel:
- self.set_level(self.gcomprisBoard.level % self.gcomprisBoard.maxlevel + 1)
- else:
- self.start_2("yes")
-
-
- # stlacenie "ruky"
- def ok(self):
-
- self.writing_status = None
-
- # zapise do suboru vsetky body od prveho prilozenia pera, az po posledny napisany bod..
-
- if self.last_written_point_index != None: # if something was written...
- for i in range(self.last_written_point_index):
- self.file_handle.write(self.points[i+1])
-
- self.file_handle.close()
-
- self.show_sablier_animation(1)
-
- _dtw = DTW.dtw.DTW(self.save_path, self.pattern)
- dtw_res = _dtw.dtw(self.filename, 1)
- print "ok: dtw_res=", str(dtw_res)
-
- self.show_sablier_animation(0)
-
- if self.show_template[self.gcomprisBoard.level-1] == 1:
- limit = 5
- else:
- limit = 9
-
- if dtw_res < limit:
- gcompris.bonus.display(gcompris.bonus.WIN, gcompris.bonus.RANDOM)
- self.won_level = 1
- else:
- gcompris.bonus.display(gcompris.bonus.LOOSE, gcompris.bonus.RANDOM)
- self.won_level = 1
-
- else: # none was written
- gcompris.bonus.display(gcompris.bonus.LOOSE, gcompris.bonus.RANDOM)
- self.won_level = 1
-
-
- self.last_written_point_index = None
-
-
-
-
-
-
- def key_press(self, keyval, commit_str, preedit_str):
- return False
-
- def repeat(self):
- #print "repeat"
- self.start_2("yes")
-
-
-
- def pause(self, pause): # called after config dialog, help, bonus
- #print "pause"
-
- self.board_paused = pause
-
- if(pause):
- self.area.hide()
- self.show_pen_animation(0)
- if self.label != None:
- self.label.hide()
- else:
- self.area.show()
- if self.won_level:
- # if we are paused, then unpaused it means that they beat the sublevel
- self.increment_level()
- else:
- self.set_level(self.gcomprisBoard.level)
-
- ## There is a problem with GTK widgets, they are not covered by the help, We hide/show them here
- #if(pause):
- # self.area.hide()
- #else:
- # self.area.show()
- # self.repeat()
-
-
- return
-
-
-
- def config(self):
- print "Config"
- pass
-
- def config_stop(self):
- print "config_stop", self
- pass
-
-
-
-
- def show_pen_animation(self, show):
- if show == 0:
- if self.ap != None:
- self.ap.gnomecanvas.hide()
- else:
- if self.ap == None:
- self._ap = gcompris.anim.Animation("writing_tutor/anim_pen.txt")
- self.ap = gcompris.anim.CanvasItem(self._ap, self.rootitem)
- self.ap.gnomecanvas.set(x=80, y=gcompris.BOARD_HEIGHT - 70)
- self.ap.setState(0)
- self.ap.gnomecanvas.show()
- else:
- self.ap.gnomecanvas.show()
-
-
- def show_sablier_animation(self, show):
- if show == 0:
- if self.sb != None:
- self.sb.gnomecanvas.hide()
- else:
- if self.sb == None:
- self._sb = gcompris.anim.Animation("connect4/sablier.txt")
- self.sb = gcompris.anim.CanvasItem(self._sb, self.rootitem)
- self.sb.gnomecanvas.set(x=40, y= gcompris.BOARD_HEIGHT - 300)
- self.sb.setState(0)
- self.sb.gnomecanvas.show()
- else:
- self.sb.gnomecanvas.show()
-
-
- def draw_text(self, x, y, text, color='blue'):
- if self.label != None:
- self.label.destroy()
-
- self.label = self.rootitem.add(gnomecanvas.CanvasText, x=x, y=y, text=text, fill_color="dark blue", font='sans bold 45', )
-
- #self.label = self.rootitem.add(gnomecanvas.CanvasText, x= x, y= y, text= text, fill_color="black",
- # font=gcompris.skin.get_font("gcompris/board/huge bold"), )
-
-
- def set_tablet_indicator(self, tablet_status):
- """
- Description:
- Set tablet indicator icon
-
- Arguments:
- tablet_status -- 1 or 0 indicating status of tablet device (enabled or disabled)
- """
- global _global_rootitem
- global _global_tablet_indicator
-
- #print "set_tablet_indicator(", tablet_status, ")"
-
- if tablet_status == 1:
- _pixmap = gcompris.utils.load_pixmap("writing_tutor/tablet_active.png")
- else:
- _pixmap = gcompris.utils.load_pixmap("writing_tutor/tablet_inactive.png")
-
- if _global_tablet_indicator != None:
- _global_tablet_indicator.destroy()
-
- _global_tablet_indicator = _global_rootitem.add(gnomecanvas.CanvasPixbuf, pixbuf = _pixmap, x = 10, y = gcompris.BOARD_HEIGHT -50)
- _global_tablet_indicator.show()
-
-
-
- def config_start(self, profile):
- print "config_start"
- global _global_rootitem
-
-
- # show only tablet configuration. save_path, sequence only in admin mode
- if _global_rootitem != None: # not in admin mode
- dlg = GtkInputDialog(self)
- return
-
- self.configure_profile = profile
-
- self.config_dict = self.init_config()
- self.config_dict.update(gcompris.get_conf(profile, self.gcomprisBoard))
-
- self.main_vbox = gcompris.configuration_window (\
- _('Hra <b>%s</b> - nastavenie pre profil <b>%s</b>') % ('Tutor', profile.name), self.save_config)
-
- gcompris.separator()
- self.button = gtk.Button("Nastavenie tabletu...")
- self.button.connect("clicked", self.input_dlg_callback)
- self.button.show()
- self.main_vbox.pack_start(self.button, False, False, 0)
- gcompris.separator()
-
- # !! ak je v admin mode, tak nemoze nastavovat tablet...
- if _global_rootitem == None: # in admin mode
- self.button.set_state(gtk.STATE_INSENSITIVE)
-
-
- gcompris.textview(_('Adresar, kde sa budu ukladat vzorky/predlohy: '), 'save_path', 'desc', self.config_dict['save_path'],
- self.validate_callback)
- gcompris.separator()
-
- gcompris.textview(_('Postupnosti tvarov pre testovanie: '), 'missing_match_sequence', 'desc', self.config_dict['missing_match_sequence'], self.validate_callback)
- gcompris.separator()
-
-
- def validate_callback(self, key, value, z):
- #print "validate_callback: key=", key, ", value=", value, ", z=", z
-
- if key == 'save_path':
- if not os.path.exists(value):
- return False
- if key == 'sequence':
- pass
-
- return True
-
-
- def input_dlg_callback(self, table):
- dlg = GtkInputDialog()
-
-
- def dummy_enter_callback(self, widget, _entry):
- pass
-
- def clb_dummy(self, x=None):
- pass
-
- def save_config(self, table):
- print "save_config: table=", table
- global _global_rootitem
-
- if table == None:
- return
-
- for key,value in table.iteritems():
- gcompris.set_board_conf(self.configure_profile, self.gcomprisBoard, key, value) # save config to db
-
- if _global_rootitem != None:
- self.start_2("no")
-
-
- def configuration(self, value, init):
- if self.config_dict.has_key(value):
- return eval(self.config_dict[value])
- else:
- return init
-
-
- def init_config(self):
- default_config_dict = { 'save_path' : gcompris.get_properties().user_dir,
- 'missing_match_sequence' : 'a_to&u|p_ro&e|okn_&o|gum_&a|_ambus&b$1+1=_&2|8-2=_&6|7-5=_&2'
- }
- return default_config_dict
-
- # sequence format:
-
- #a_to&a|p_ro&u|okn_&o$ 1. level
- #a_to&a|p_ro&u|okn_&o$ 2. level..
-
-
-
-
-# END OF class Gcompris_missing_match ************************************
-
-
-
-
-def stop_board():
- gcompris.bonus.board_finished(gcompris.bonus.FINISHED_RANDOM)
-
-
diff --git a/src/boards/python/writing_tutor_pattern_admin.py b/src/boards/python/writing_tutor_pattern_admin.py
deleted file mode 100644
index 39403c5..0000000
--- a/src/boards/python/writing_tutor_pattern_admin.py
+++ /dev/null
@@ -1,773 +0,0 @@
-# gcompris/tutor/pattern_admin.py -
-#
-# Author: Jozef Cerven, 5mi, (c) 2006/2007
-# FACULTY OF MATHEMATICS, PHYSICS AND INFORMATICS COMENIUS UNIVERSITY BRATISLAVA, Informatics Teaching and Basic of Informatics department
-# http://www.edi.fmph.uniba.sk
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, see <http://www.gnu.org/licenses/>.
-#
-
-
-
-import gnomecanvas
-import gcompris
-import gcompris.utils
-import gcompris.bonus
-import gcompris.skin
-import gcompris.anim
-import gcompris.sound
-import gcompris.admin
-import gtk
-import gtk.gdk
-import random
-import pango
-import time
-import os
-import socket
-import fcntl
-import struct
-import re
-import glob
-import string
-
-
-from gcompris import gcompris_gettext as _
-
-from writing_tutor_common import *
-
-_global_rootitem = None # for config dialog
-_global_tablet_indicator= None
-
-
-
-# BEGIN OF class Gcompris_pattern_admin **************************
-class Gcompris_writing_tutor_pattern_admin:
-
- _ap = None
- ap = None
-
- rootitem = None
- board_paused = False
- last_selected_pattern = None
- last_selected_writing_type = None
- pattern = None
- writing_type = "vzorky"
- save_path = None
- sequence = None
- cursor_index = 0
- patterns_count = 0
- area = None
- can_write = False
- tree_already_clicked = False
- drop_button = None
- dat_filename = None
- pixmap = None # drawing area pixmap
- filename = None
- file_handle = None
- writing_status = None
- last_written_point_index = None
- motions_count = None
- points = [None] * 2000
- cas_start = None
-
-
- def __init__(self, gcomprisBoard):
- # this constructor is called for every refresh of gcompris board, eg. help window, config window.. -> global variables may be needed for
- # persistence..
-
- self.gcomprisBoard = gcomprisBoard
-
- gap = 10
- panel_x = 130
- self.select_area = (gap , gap, panel_x + gap , gcompris.BOARD_HEIGHT-gap-100)
- self.panel_area = (panel_x + 3*gap , 0, gcompris.BOARD_WIDTH-gap, gcompris.BOARD_HEIGHT-gap)
-
-
-
- def __del__(self):
- pass
-
-
- def start(self):
- global _global_rootitem
-
- self.window = self.gcomprisBoard.canvas.get_toplevel()
-
- #get default values
- self.config_dict = self.init_config()
-
- #replace configured values (..ak su v db..)
- self.config_dict.update(gcompris.get_board_conf())
-
- self.save_path = self.config_dict['save_path']
- self.sequence = self.config_dict['sequence']
-
- #print "start: save_path=",self.save_path, ", sequence=", self.sequence
-
- self.gcomprisBoard.level=1
- self.gcomprisBoard.maxlevel=1
- self.gcomprisBoard.sublevel=1
- self.gcomprisBoard.number_of_sublevel=1
-
- # 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.
- self.rootitem = self.gcomprisBoard.canvas.root().add(gnomecanvas.CanvasGroup, x=0.0, y=0.0)
- _global_rootitem = self.rootitem
-
-
- gcompris.bar_set( gcompris.BAR_LEVEL|gcompris.BAR_OK|gcompris.BAR_CONFIG )
- #gcompris.bar_hide(1)
-
- gcompris.set_background(self.rootitem, gcompris.skin.image_to_skin("gcompris-bg.jpg"))
-
-
- # graphics controls...
-
- self.left_win = gtk.ScrolledWindow()
- self.left_win.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
- self.left_win.set_shadow_type(gtk.SHADOW_ETCHED_OUT)
-
- self.model = gtk.ListStore(str, str)
- self.treeview = gtk.TreeView(self.model)
- self.treeview.connect('cursor-changed', self.clb_tree_cursor_changed)
- self.treeview.add_events(gtk.gdk.BUTTON_PRESS_MASK)
- self.treeview.connect('button_press_event', self.clb_tree_button_press)
- colnum = 2
- colwidths = [90, 20]
- coltexts = ['Tvar', 'Pocet']
-
- for col in range(colnum):
- renderer = gtk.CellRendererText()
- renderer.set_property('ellipsize', True)
- #renderer.set_property('editable', True)
- renderer.set_property('xpad', 5)
-
- #renderer.connect('edited', on_edit_item, col)
- treecol = self.treeview.insert_column_with_attributes(-1, coltexts[col], renderer, text=col)
- treecol.set_spacing(10)
- treecol.set_resizable(True)
- treecol.set_alignment(0.5)
- treecol.set_data('id', col)
- treecol.set_data('renderer', renderer)
- treecol.set_min_width(colwidths[col])
-
-
- self.update_tree_data()
-
- self.left_win.add(self.treeview)
-
- self.rootitem.add(gnomecanvas.CanvasWidget, widget=self.left_win, x=self.select_area[0], y=self.select_area[1], width=self.select_area[2],
- height=self.select_area[3])
- self.treeview.show()
- self.left_win.show()
-
-
-
- # BEGIN OF radio buttons ************************************
- self.rbgr = gtk.RadioButton(label="vzorky")
- self.rbgr.connect("toggled", self.rb_callback, "vzorky")
- self.rootitem.add(gnomecanvas.CanvasWidget, widget=self.rbgr, x=10, y=430, width=80, height=20 )
- self.rbgr.show()
-
- self.rb1 = gtk.RadioButton(group=self.rbgr, label="predlohy")
- self.rb1.connect("toggled", self.rb_callback, "predlohy")
- self.rootitem.add(gnomecanvas.CanvasWidget, widget=self.rb1, x=80, y=430, width=80, height=20 )
- self.rb1.show()
- # END OF radio buttons ************************************
-
- gcompris.set_background(self.gcomprisBoard.canvas.root(),
- gcompris.skin.image_to_skin("gcompris-bg.jpg"))
- #BC_pixmap = gcompris.utils.load_pixmap("writing_tutor/bg.png")
- #BCself.bg_pixmap = self.rootitem.add(gnomecanvas.CanvasPixbuf, pixbuf = _pixmap, x=0, y=0)
-
-
- # show tablet indicator icon
-
- _t_active = 0
- _devices = gtk.gdk.devices_list()
- for _d in _devices:
- if _d.source == gtk.gdk.SOURCE_PEN:
- _t_active = 1
- if _d.mode == gtk.gdk.MODE_DISABLED: # if tablet is disabled
- _d.set_mode(gtk.gdk.MODE_SCREEN) # enable it (first in sequence)
- break
- else: # already enabled..
- break
-
- if _t_active == 1:
- self.set_tablet_indicator(1)
- else:
- self.set_tablet_indicator(0)
-
- self.treeview.set_cursor(self.cursor_index)
-
- self.start_2()
-
-
-
- def clb_tree_cursor_changed(self, treeview, user_param1=None):
- if self.tree_already_clicked:
- self.tree_already_clicked = False
- else:
- #print "clb_tree_cursor_changed:"
- self.show_pen_animation(0)
- treeselection = treeview.get_selection()
- (model, iter) = treeselection.get_selected()
- self.pattern = model.get(iter, 0)[0]
- pocet = model.get(iter, 1)[0]
-
- self.cursor_index = model.get_path(iter)[0]
- self.show_drop_button(0)
- self.start_2("yes")
- self.can_write = True
-
-
- def clb_tree_button_press(self, widget, event):
-
- #print "clb_tree_button_press: widget=", widget, ", event.button=",event.button, ", event.type=", event.type
- if event.button == 3:
-
- self.show_pen_animation(0)
- self.can_write = False
- treeselection = self.treeview.get_selection()
- (model, iter) = treeselection.get_selected()
- if model == None or iter == None:
- return
- self.pattern = model.get(iter, 0)[0]
- pocet = model.get(iter, 1)[0]
-
- self.cursor_index = model.get_path(iter)[0]
- #print "self.cursor_index=", self.cursor_index
-
- if self.last_selected_pattern != self.pattern or self.last_selected_writing_type != self.writing_type:
- self.pattern_arr_index = 0
- self.last_selected_pattern = self.pattern
- self.last_selected_writing_type = self.writing_type
- self.last_selected_pattern_count = len(self.get_datfiles_list(self.pattern))
- else:
- if self.last_selected_pattern_count > 0:
- self.pattern_arr_index = (self.pattern_arr_index + 1) % self.last_selected_pattern_count
-
- if self.last_selected_pattern_count > 0:
- self.dat_filename = self.get_datfiles_list(self.pattern)[self.pattern_arr_index]
-
- #print "paint:self.patern=", self.pattern, self.dat_filename
- self.configure_event(self.area, None)
- self.paint_pattern(self.dat_filename)
-
- # zobrazi cestu k .dat suboru
- tmp = self.dat_filename.split("/")
- _dat_filename_file = tmp[len(tmp)-1]
- tmp.remove(_dat_filename_file)
- _dat_filename_dir = "/".join(tmp) + "/"
- context = self.area.create_pango_context()
- desc = pango.FontDescription('Sans 9')
- gc = self.pixmap.new_gc()
- self.layout = self.area.create_pango_layout(_dat_filename_dir) # v 1. riadku nazov adresar
- self.layout.set_font_description(desc)
- self.pixmap.draw_layout(gc, x=30, y=15, layout=self.layout)
- self.layout = self.area.create_pango_layout(_dat_filename_file) # v 2. riadku nazov .dat suboru
- self.layout.set_font_description(desc)
- self.pixmap.draw_layout(gc, x=30, y=30, layout=self.layout)
- self.area.queue_draw_area(0, 0, 650, 500)
-
- # zobraz tlacitko na zmazanie
- self.show_drop_button(1)
-
-
-
- self.tree_already_clicked = True
-
-
-
-
- def get_datfiles_list(self, _pattern):
-
- dat_list = glob.glob(self.save_path + "/tutor/" + self.writing_type + "/" + _pattern + "/*.dat")
- empty_dat_list = []
- for _file in dat_list:
- if os.stat(_file).st_size <= 0:
- empty_dat_list.append(_file) # v zozname necha len neprazdne subory
-
- set_dat_list = set(dat_list)
- set_empty_dat_list = set(empty_dat_list)
-
- res = set_dat_list - set_empty_dat_list # rozdiel mnozin
- return list(res)
-
-
- def update_tree_data(self):
- #print "update_tree_data: writing_type=", self.writing_type
-
- # sequence: a|b|c|d|A|B|C|D|ab|@kruh
-
- self.model.clear()
- self.patterns_count = 0
-
- _sequence = re.sub(r'\s', '', self.sequence)
- _sequence = _sequence.replace("$", "|") # v tejto aktivite nie su levely, ale ak nahodou je separator $ tak -> |
- _sequence = _sequence.split("|")
- for s in _sequence:
- if len(s) > 0:
- self.model.append([s, str(len(self.get_datfiles_list(s)))])
- self.patterns_count += 1
-
-
- def tree_select_next_item(self):
- self.cursor_index = (self.cursor_index + 1 ) % self.patterns_count
- self.treeview.set_cursor(self.cursor_index)
- #print "tree_select_next_item: self.cursor_index=", self.cursor_index, ", self.patterns_count=", self.patterns_count
-
-
-
- def show_drop_button(self, show):
- #print "show_drop_button: show=", show
-
- if show == 1:
- if self.drop_button == None:
- _pixmap = gcompris.utils.load_pixmap("writing_tutor/drop.png")
- self.drop_button = self.rootitem.add(gnomecanvas.CanvasPixbuf, pixbuf = _pixmap, x = 90, y = gcompris.BOARD_HEIGHT -60)
- self.drop_button.connect("event", self.drop_button_click_event)
- self.drop_button.show()
-
- else:
- if self.drop_button != None:
- self.drop_button.hide()
-
-
- def drop_button_click_event(self, widget, event):
- #print "drop_button_click_event: event.type=", event.type
- if event.type == gtk.gdk.BUTTON_PRESS: # and je nejaky pattern ...
- # zmaz aktualny datafile + update_tree_data+ zobraz dalsie
- # dorob !!
- if os.path.exists(self.dat_filename):
- os.remove(self.dat_filename)
- #print ".dat file deleted: ", self.dat_filename
-
- gcompris.sound.play_ogg_cb("sounds/crash.ogg", self.clb_dummy)
- self.pattern_arr_index = 0
- self.last_selected_pattern_count = len(self.get_datfiles_list(self.pattern))
- self.update_tree_data()
- self.treeview.set_cursor(self.cursor_index)
-
- return True
-
-
- def recreate_drawing_area(self):
-
- # BEGIN OF drawing_area ************************************
-
- if self.area != None:
- self.area.destroy()
-
- self.area = gtk.DrawingArea()
-
- # Signals used to handle backing pixmap
- self.area.connect("expose_event", self.expose_event)
- self.area.connect("configure_event", self.configure_event)
-
- # Event signals
- self.area.connect("motion_notify_event", self.motion_notify_event)
- #area.connect("button_press_event", self.button_press_event)
-
- self.area.set_events(gtk.gdk.EXPOSURE_MASK | gtk.gdk.LEAVE_NOTIFY_MASK | gtk.gdk.BUTTON_PRESS_MASK
- | gtk.gdk.POINTER_MOTION_MASK | gtk.gdk.PROXIMITY_IN | gtk.gdk.PROXIMITY_OUT_MASK)
-
- # The following call enables tracking and processing of extension
- # events for the drawing area
- #self.area.set_extension_events(gtk.gdk.EXTENSION_EVENTS_CURSOR)
- self.area.set_extension_events(gtk.gdk.EXTENSION_EVENTS_ALL)
-
- #area.size(400, 300)
- #self.area.set_size_request(550, 600)
-
- self.rootitem.add(gnomecanvas.CanvasWidget, widget=self.area, x=self.panel_area[0], y=self.panel_area[1],
- width=self.panel_area[2], height=self.panel_area[3])
-
- self.area.show()
- # END OF drawing_area ************************************
-
- #print "recreate_drawing_area()"
-
-
-
- def paint_pattern(self, pattern_dat_file):
- #print "paint_pattern: ", pattern_dat_file
- if os.path.getsize(pattern_dat_file) > 0:
- _filehandle = open(pattern_dat_file, "r")
- for line in _filehandle:
- l = line.split()
- #print "x=",l[0]," y=",l[1], " pressure=", l[2]
- if len(l) == 6:
- self.draw_brush(self.area, float(l[0]), float(l[1]), float(l[2]))
- #time.sleep(0.010)
- else:
- print "BAD FILE FORMAT: "
- print pattern_dat_file
- break
-
- _filehandle.close()
-
-
- def start_2(self, recreate="yes"):
- #print "start_2"
-
- ip = get_ip_address('eth0')
-
- datum = time.strftime('%d.%m.%Y_%X').replace('/','.')
- filename1 = self.save_path + "/tutor/" + self.writing_type + "/" + self.pattern
- self.filename = filename1 + "/" + ip + "__" + datum + ".dat"
- # musi existovat cesta => adresare!
- if not os.path.exists(filename1):
- os.makedirs(filename1)
-
- self.file_handle = open(self.filename,"w")
- if recreate == "yes":
- self.recreate_drawing_area()
-
- #self.draw_guiding_lines()
- self.show_pen_animation(1)
-
-
-
- # BEGIN OF drawing_area HANDLERS ************************************
- # Create a new backing pixmap of the appropriate size
- def configure_event(self, widget, event):
-
- x, y, width, height = widget.get_allocation()
- self.pixmap = gtk.gdk.Pixmap(widget.window, width, height)
- #pixmap.draw_rectangle(widget.get_style().white_gc, True, 0, 0, width, height)
-
- pixbuf = gcompris.utils.load_pixmap("writing_tutor/pattern_admin_bg.png")
- self.pixmap.draw_pixbuf(widget.get_style().fg_gc[gtk.STATE_NORMAL], pixbuf, 0, 0, 0, 0, width, height)
-
-
- draw_guiding_lines(self.pixmap, self.area, self.pattern, 570)
-
- return True
-
-
- # Redraw the screen from the backing pixmap
- def expose_event(self, widget, event):
- x , y, width, height = event.area
- widget.window.draw_drawable(widget.get_style().fg_gc[gtk.STATE_NORMAL], self.pixmap, x, y, x, y, width, height)
- return False
-
- # Draw a rectangle on the screen
- def draw_brush(self, widget, x, y, pressure):
- rect = (int(x-5*pressure), int(y-5*pressure), int(10*pressure), int(10*pressure))
- self.pixmap.draw_rectangle(widget.get_style().black_gc, True, rect[0], rect[1], rect[2], rect[3])
- widget.queue_draw_area(rect[0], rect[1], rect[2], rect[3])
-
-
-
- def motion_notify_event(self, widget, event):
- if not self.can_write:
- return True
-
- # is_hint => mys
- if event.is_hint:
- x, y, state = event.window.get_pointer()
- pressure = 0.0
- x_tilt = 0.0
- y_tilt = 0.0
- else: # pero tabletu
- state = event.state
- x = event.get_axis(gtk.gdk.AXIS_X)
- y = event.get_axis(gtk.gdk.AXIS_Y)
- pressure = event.get_axis(gtk.gdk.AXIS_PRESSURE)
- x_tilt = event.get_axis(gtk.gdk.AXIS_XTILT) # musi to podporovat tablet,napr "Wacom Intuos"
- if x_tilt == None:
- x_tilt = 0.0
- y_tilt = event.get_axis(gtk.gdk.AXIS_YTILT)
- if y_tilt == None:
- y_tilt = 0.0
-
- #wheel = event.get_axis(gtk.gdk.AXIS_WHEEL) #?
- #print "x=",x," y=",y," pressure=",pressure, " x_tilt=", x_tilt," y_tilt=",y_tilt
-
-
- if (not (x >= 10 and x <= 550 and y >= 10 and y<= 500)): #if not in drawing_area_rect:
- if self.writing_status == 1:
- self.writing_status = None
- return True
-
-
- if state & gtk.gdk.BUTTON1_MASK and self.pixmap != None:
-
- if event.is_hint:
- pressure = 1.0
- if pressure == None:
- pressure = 1.0
-
- if self.writing_status == None and pressure > 0.0:
- self.show_pen_animation(0)
- self.writing_status = 1 # zacal som pisat pismeno/zaznamenavat udaje
- self.motions_count = 1
- self.cas_start = time.time() # pri zaciatku pisania pismena sa poznaci cas
-
-
- if pressure > 0.0:
- self.draw_brush(widget, x, y, pressure)
- self.last_written_point_index = self.motions_count
-
- if self.writing_status == 1:
- #points[motions_count] = str(int(x)) + " " + str(int(y)) + " " + str(int(pressure)) + "\n"
- self.points[self.motions_count] = str(float(x)) + " " + str(float(y)) + " " + str(pressure) + " " + str(x_tilt) + " " + str(y_tilt) + " " + str((time.time()-self.cas_start)*1000.0) + "\n"
- #print "points[",motions_count,"]=", points[motions_count]
- self.motions_count += 1
-
- return True
-
-# END OF drawing_area HANDLERS ************************************
-
-
- def rb_callback(self, widget, data):
- # zavola sa len pri aktivovani rb, nie pri deaktivovani
- if not widget.get_active():
- return
-
- #print "rb_callback"
-
- self.show_drop_button(0)
- self.show_pen_animation(0)
- self.writing_type = data
- self.update_tree_data()
- self.cursor_index = 0
- self.treeview.set_cursor(self.cursor_index)
- self.start_2("no")
-
-
-
-
- def end(self):
- #gcompris.sound.reopen()
-
- if self.rootitem != None:
- self.rootitem.destroy()
- self.rootitem = None
- pass
-
-
- def show_pen_animation(self, show):
- if show == 0:
- if self.ap != None:
- self.ap.gnomecanvas.hide()
- else:
- if self.ap == None:
- self._ap = gcompris.anim.Animation("writing_tutor/anim_pen.txt")
- self.ap = gcompris.anim.CanvasItem(self._ap, self.rootitem)
- self.ap.gnomecanvas.set(x=80, y=gcompris.BOARD_HEIGHT - 70)
- self.ap.setState(0)
- self.ap.gnomecanvas.show()
- else:
- self.ap.gnomecanvas.show()
-
-
-
-
- def ok(self):
- #print "ok"
-
- self.writing_status = None
-
- # od naposledy napisaneho bodu vsetky vymaz (s tlakom=0)
- # zapise do suboru vsetky body od prveho prilozenia pera, az po posledny napisany bod..
- if self.last_written_point_index != None:
- for i in range(self.last_written_point_index):
- #print "i=",i," , last_written_point_index=",last_written_point_index
- self.file_handle.write(self.points[i+1])
- self.file_handle.close()
-
- _empty_dat_list = glob.glob(self.save_path + "/tutor/" + self.writing_type + "/" + self.pattern + "/*.dat")
- for _file in _empty_dat_list:
- if os.stat(_file).st_size <= 0:
- os.remove(_file) # zmaze .dat subory 0-vej dlzky
- #print "empty file deleted: ", _file
- #if os.path.getsize(filename) < 1:
-
- #self.start_2() # !!
- self.update_tree_data()
- self.can_write = False
- self.set_level(1)
-
-
- def set_level(self, level):
- #print "set_level"
-
- self.tree_select_next_item()
- self.show_pen_animation(1)
- self.start_2("yes")
-
-
-
-
- def key_press(self, keyval, commit_str, preedit_str):
- return False
-
- def repeat(self):
- print "repeat"
-
- def pause(self, pause):
- self.board_paused = pause
-
- # There is a problem with GTK widgets, they are not covered by the help, We hide/show them here
- if(pause):
- self.left_win.hide()
- self.area.hide()
- self.rbgr.hide()
- self.rb1.hide()
-
- else:
- self.left_win.show()
- self.area.show()
- self.rbgr.show()
- self.rb1.show()
-
- self.repeat()
- return
-
-
- def config(self):
- print "Config"
- pass
-
- def config_stop(self):
- print "config_stop", self
- pass
-
-
- def config_start(self, profile):
- print "config_start"
- global _global_rootitem
-
- # show only tablet configuration. save_path, sequence only in admin mode
- if _global_rootitem != None: # not in admin mode
- dlg = GtkInputDialog(self)
- return
-
- self.configure_profile = profile
-
- self.config_dict = self.init_config()
- self.config_dict.update(gcompris.get_conf(profile, self.gcomprisBoard))
-
- self.main_vbox = gcompris.configuration_window (\
- _('Hra <b>%s</b> - nastavenie pre profil <b>%s</b>') % ('Tutor', profile.name), self.save_config)
-
- gcompris.separator()
- self.button = gtk.Button("Nastavenie tabletu...")
- self.button.connect("clicked", self.input_dlg_callback)
- self.button.show()
- self.main_vbox.pack_start(self.button, False, False, 0)
- gcompris.separator()
-
- # !! ak je v admin mode, tak nemoze nastavovat tablet...
- if _global_rootitem == None: # in admin mode
- self.button.set_state(gtk.STATE_INSENSITIVE)
-
-
- gcompris.textview(_('Adresar, kde sa budu ukladat vzorky/predlohy: '), 'save_path', 'desc', self.config_dict['save_path'],
- self.validate_callback)
- gcompris.separator()
-
- gcompris.textview(_('Postupnost tvarov pre zbieranie vzoriek: '), 'sequence', 'desc', self.config_dict['sequence'],
- self.validate_callback)
- gcompris.separator()
-
-
- def validate_callback(self, key, value, z):
- #print "validate_callback: key=", key, ", value=", value, ", z=", z
-
- if key == 'save_path':
- if not os.path.exists(value):
- return False
- if key == 'sequence':
- pass
-
- return True
-
-
- def input_dlg_callback(self, table):
- dlg = GtkInputDialog(self)
-
-
- def dummy_enter_callback(self, widget, _entry):
- pass
-
- def clb_dummy(self, x=None):
- pass
-
-
- def save_config(self, table):
- print "save_config: table=", table
- global _global_rootitem
-
- if table == None:
- return
-
-
- for key,value in table.iteritems():
- gcompris.set_board_conf(self.configure_profile, self.gcomprisBoard, key, value) # save config to db
-
- if _global_rootitem != None:
- self.start_2("no")
-
-
- def configuration(self, value, init):
- if self.config_dict.has_key(value):
- return eval(self.config_dict[value])
- else:
- return init
-
-
- def set_tablet_indicator(self, tablet_status):
- """
- Description:
- Set tablet indicator icon
-
- Arguments:
- tablet_status -- 1 or 0 indicating status of tablet device (enabled or disabled)
- """
- global _global_rootitem
- global _global_tablet_indicator
-
- #print "set_tablet_indicator(", tablet_status, ")"
-
- if tablet_status == 1:
- _pixmap = gcompris.utils.load_pixmap("writing_tutor/tablet_active.png")
- else:
- _pixmap = gcompris.utils.load_pixmap("writing_tutor/tablet_inactive.png")
-
- if _global_tablet_indicator != None:
- _global_tablet_indicator.destroy()
-
- _global_tablet_indicator = _global_rootitem.add(gnomecanvas.CanvasPixbuf, pixbuf = _pixmap, x = 10, y = gcompris.BOARD_HEIGHT -50)
- _global_tablet_indicator.show()
-
-
- def init_config(self):
- default_config_dict = { 'save_path' : gcompris.get_properties().user_dir,
- 'sequence' : 'a|b|c|d|e|A|B|C|D|E|_A|_B|1|2|@kruh|@stvorec'
- }
- return default_config_dict
-
- # sequence format:
- #a|b|c|d|A|B|C|D|ab|@kruh
-
-
-
-
-# END OF class Gcompris_pattern_admin ************************************
-
-
diff --git a/src/boards/python/writing_tutor_template_match.py b/src/boards/python/writing_tutor_template_match.py
deleted file mode 100644
index b48dbc8..0000000
--- a/src/boards/python/writing_tutor_template_match.py
+++ /dev/null
@@ -1,734 +0,0 @@
-# gcompris/tutor/template_match.py - Writing Tutor project
-#
-# Author: Jozef Cerven, 5mi, (c) 2006/2007
-# FACULTY OF MATHEMATICS, PHYSICS AND INFORMATICS COMENIUS UNIVERSITY BRATISLAVA, Informatics Teaching and Basic of Informatics department
-# http://www.edi.fmph.uniba.sk
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, see <http://www.gnu.org/licenses/>.
-#
-
-# first level of this activity is "with template", others are "without template"
-
-
-import gnomecanvas
-import gcompris
-import gcompris.utils
-import gcompris.bonus
-import gcompris.skin
-import gcompris.anim
-import gcompris.sound
-import gcompris.admin
-import gcompris.score
-import gtk
-import gtk.gdk
-import random
-import pango
-import time
-import os
-import socket
-import fcntl
-import struct
-import re
-import glob
-import string
-import time
-
-
-#import gobject
-from gcompris import gcompris_gettext as _
-
-from writing_tutor_common import *
-
-import DTW.dtw
-
-
-_global_rootitem = None # for config dialog
-_global_tablet_indicator= None
-
-
-
-
-
-# BEGIN OF class Gcompris_template_match ************************************
-class Gcompris_writing_tutor_template_match:
-
- _ap = None
- ap = None
- _sb = None
- sb = None
-
- rootitem = None
- board_paused = 0
-
- save_path = None
- sequence = None
- pattern = None
- show_template = 100*[None] # if show_template[0]==1: show_template in level 1
-
- area = None
- notepad_area = None
- label = None
- won_level = 0
-
- dat_filename = None
- pixmap = None # drawing area pixmap
- filename = None
- file_handle = None
- writing_status = None
- last_written_point_index = None
- motions_count = None
- points = [None] * 2000
- cas_start = None
- button_pixbuf = None
-
- def __init__(self, gcomprisBoard):
- self.gcomprisBoard = gcomprisBoard
-
- _notepad_width = 485
- _notepad_height = 485
-
- #self.notepad_area = ((gcompris.BOARD_WIDTH/2 - _notepad_width/2), 20, _notepad_width, _notepad_height) # centered
- self.notepad_area = (280, 10, _notepad_width, _notepad_height)
-
-
-
- def start(self):
- global _global_rootitem
-
- self.window = self.gcomprisBoard.canvas.get_toplevel()
-
- self.config_dict = self.init_config()
- self.config_dict.update(gcompris.get_board_conf())
-
- self.save_path = self.config_dict['save_path']
- self.sequence = self.config_dict['template_match_sequence']
-
- self.parse_sequence()
-
- self.gcomprisBoard.level=1
- self.gcomprisBoard.maxlevel=len(self.sequence)
- self.gcomprisBoard.sublevel=1
- self.gcomprisBoard.number_of_sublevel = len(self.sequence[self.gcomprisBoard.level-1])
-
-
- _pixmap = gcompris.utils.load_pixmap(gcompris.skin.image_to_skin("button_reload.png"))
- if(_pixmap):
- gcompris.bar_set_repeat_icon(_pixmap)
- gcompris.bar_set(gcompris.BAR_LEVEL|gcompris.BAR_OK|gcompris.BAR_REPEAT_ICON|gcompris.BAR_CONFIG)
- else:
- gcompris.bar_set(gcompris.BAR_LEVEL|gcompris.BAR_OK|gcompris.BAR_REPEAT|gcompris.BAR_CONFIG)
-
-
- #gcompris.set_background(self.rootitem, gcompris.skin.image_to_skin("gcompris-bg.jpg"))
- gcompris.set_background(self.rootitem, "writing_tutor/wood_oak.png")
-
-
- # 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.
- self.rootitem = self.gcomprisBoard.canvas.root().add(gnomecanvas.CanvasGroup, x=0.0, y=0.0)
- _global_rootitem = self.rootitem
-
-
- # show tablet indicator icon
-
- _t_active = 0
- _devices = gtk.gdk.devices_list()
- for _d in _devices:
- if _d.source == gtk.gdk.SOURCE_PEN:
- _t_active = 1
- if _d.mode == gtk.gdk.MODE_DISABLED: # if tablet is disabled
- _d.set_mode(gtk.gdk.MODE_SCREEN) # enable it (first in sequence)
- break
- else: # already enabled..
- break
-
- if _t_active == 1:
- self.set_tablet_indicator(1)
- else:
- self.set_tablet_indicator(0)
-
-
- self.set_level(1)
-
-
-
-
- def recreate_drawing_area(self):
-
- # BEGIN OF drawing_area ************************************
-
- if self.area != None:
- self.area.destroy()
-
- self.area = gtk.DrawingArea()
-
- # Signals used to handle backing pixmap
- self.area.connect("expose_event", self.expose_event)
- self.area.connect("configure_event", self.configure_event)
-
- # Event signals
- self.area.connect("motion_notify_event", self.motion_notify_event)
- #area.connect("button_press_event", self.button_press_event)
-
- self.area.set_events(gtk.gdk.EXPOSURE_MASK | gtk.gdk.LEAVE_NOTIFY_MASK | gtk.gdk.BUTTON_PRESS_MASK
- | gtk.gdk.POINTER_MOTION_MASK | gtk.gdk.PROXIMITY_IN | gtk.gdk.PROXIMITY_OUT_MASK)
-
- # The following call enables tracking and processing of extension
- # events for the drawing area
- #self.area.set_extension_events(gtk.gdk.EXTENSION_EVENTS_CURSOR)
- self.area.set_extension_events(gtk.gdk.EXTENSION_EVENTS_ALL)
-
- self.rootitem.add(gnomecanvas.CanvasWidget, widget=self.area, x=self.notepad_area[0], y=self.notepad_area[1],
- width=self.notepad_area[2], height=self.notepad_area[3])
-
- self.area.show()
- # END OF drawing_area ************************************
-
- #print "recreate_drawing_area()"
-
-
-
- def start_2(self, recreate="yes"):
-
- self.pattern = self.sequence[self.gcomprisBoard.level-1][self.gcomprisBoard.sublevel-1]
- gcompris.score.set(self.gcomprisBoard.sublevel)
- self.draw_text(140, 150, self.pattern)
- self.won_level = 0
-
- if recreate == "yes":
- self.recreate_drawing_area()
-
-
- if self.show_template[self.gcomprisBoard.level-1] == 1: # level with "show_template"
- predlohy_dir = self.save_path + "/writing_tutor/predlohy/" + self.pattern + "/"
- if not os.path.exists(predlohy_dir):
- print "%s DOES NOT EXISTS!", predlohy_dir
- else:
- arglist = []
- os.path.walk(predlohy_dir,self.walk_callback,arglist)
-
- ip = get_ip_address('eth0') # eth0
- datum = time.strftime('%d.%m.%Y_%X').replace('/','.')
- filename1 = self.save_path + "/writing_tutor/predloha_test/" + self.pattern
- self.filename = filename1 + "/" + ip + "__" + datum + ".dat"
- # musi existovat cesta => adresare!
- if not os.path.exists(filename1):
- os.makedirs(filename1)
-
- self.file_handle = open(self.filename,"w")
-
- self.show_pen_animation(1)
-
-
-
-
- def walk_callback(self, arg, dirname, fnames ):
- global area
-
- # print "dirname: ", dirname
- if len(fnames) < 1:
- print "walk_callback: len(fnames)<1 !! : ", len(fnames)
-
- for _filename in fnames:
- if os.path.getsize(dirname+_filename) > 0:
- # print "df: ", dirname , _filename
- _filehandle = open(dirname + _filename, "r")
- for line in _filehandle:
- l = line.split()
- #print "x=",l[0]," y=",l[1], " pressure=", l[2]
- self.draw_brush(self.area, float(l[0]), float(l[1]), float(l[2]),'predloha')
- time.sleep(0.010)
- _filehandle.close()
- break # berieme len prvu predlohu v adresari
-
-
-
- # BEGIN OF drawing_area HANDLERS ************************************
- # Create a new backing pixmap of the appropriate size
- def configure_event(self, widget, event):
- x, y, width, height = widget.get_allocation()
- self.pixmap = gtk.gdk.Pixmap(widget.window, width, height)
- #self.pixmap.draw_rectangle(widget.get_style().white_gc, True, 0, 0, width, height)
-
- #pixbuf = gcompris.utils.load_pixmap("boardicons/notepad.png")
- tmp = self.gcomprisBoard.filename.split("/")
- _file = tmp[len(tmp)-1]
- tmp.remove(_file)
- _board_dir = "/".join(tmp)
-
- pixbuf = gtk.gdk.pixbuf_new_from_file(_board_dir + "/writing_tutor/wood_oak.png") # transparent png
- self.pixmap.draw_pixbuf(widget.get_style().fg_gc[gtk.STATE_NORMAL], pixbuf, 0, 0, 0, 0, width, height)
- pixbuf = gtk.gdk.pixbuf_new_from_file(_board_dir + "/writing_tutor/notepad.png") # transparent png
- self.pixmap.draw_pixbuf(widget.get_style().fg_gc[gtk.STATE_NORMAL], pixbuf, 0, 0, 0, 0, width, height)
-
- draw_guiding_lines(self.pixmap, self.area, self.pattern, 450)
-
- return True
-
-
- # Redraw the screen from the backing pixmap
- def expose_event(self, widget, event):
- x , y, width, height = event.area
- widget.window.draw_drawable(widget.get_style().fg_gc[gtk.STATE_NORMAL], self.pixmap, x, y, x, y, width, height)
- return False
-
-
- def draw_brush(self, widget, x, y, pressure, _type='vzorka'):
-
- colormap = self.area.get_colormap()
- if _type == 'predloha':
- color = colormap.alloc_color(86*256, 153*256, 215*256) # slabo modra
- rect = (int(x-4*pressure), int(y-4*pressure), int(8*pressure), int(8*pressure))
- else:
- color = colormap.alloc_color(97*256, 105*256, 141*256) # tmavo seda
- rect = (int(x-5*pressure), int(y-5*pressure), int(10*pressure), int(10*pressure))
-
-
- gc = self.area.get_style().fg_gc[gtk.STATE_NORMAL]
- gc.foreground = color
-
- self.pixmap.draw_rectangle(widget.get_style().fg_gc[gtk.STATE_NORMAL], True, rect[0], rect[1], rect[2], rect[3])
- widget.window.draw_drawable(widget.get_style().fg_gc[gtk.STATE_NORMAL], self.pixmap, rect[0], rect[1], rect[0], rect[1], rect[2], rect[3])
-
- while gtk.events_pending(): gtk.main_iteration() # refreshing widget
-
- # nastavim naspat ciernu
- color = colormap.alloc_color(0,0,0) # slabo modra
- gc = self.area.get_style().fg_gc[gtk.STATE_NORMAL]
- gc.foreground = color
-
-
-
- def motion_notify_event(self, widget, event):
- #if not self.can_write: #!!
- # return True
- # is_hint => mys
- if event.is_hint:
- x, y, state = event.window.get_pointer()
- pressure = 0.0
- x_tilt = 0.0
- y_tilt = 0.0
- else: # pero tabletu
- state = event.state
- x = event.get_axis(gtk.gdk.AXIS_X)
- y = event.get_axis(gtk.gdk.AXIS_Y)
- pressure = event.get_axis(gtk.gdk.AXIS_PRESSURE)
- x_tilt = event.get_axis(gtk.gdk.AXIS_XTILT) # musi to podporovat tablet,napr "Wacom Intuos"
- if x_tilt == None:
- x_tilt = 0.0
- y_tilt = event.get_axis(gtk.gdk.AXIS_YTILT)
- if y_tilt == None:
- y_tilt = 0.0
-
- #wheel = event.get_axis(gtk.gdk.AXIS_WHEEL) #?
- #print "x=",x," y=",y," pressure=",pressure, " x_tilt=", x_tilt," y_tilt=",y_tilt
-
-
- if (not (x >= 10 and x <= 485 and y >= 10 and y<= 485)): #if not in drawing_area_rect:
- if self.writing_status == 1:
- self.writing_status = None
- return True
-
-
- if state & gtk.gdk.BUTTON1_MASK and self.pixmap != None:
-
- if event.is_hint:
- pressure = 1.0
- if pressure == None:
- pressure = 1.0
-
- if self.writing_status == None and pressure > 0.0:
- self.show_pen_animation(0)
- self.writing_status = 1 # zacal som pisat pismeno/zaznamenavat udaje
- self.motions_count = 1
- self.cas_start = time.time() # pri zaciatku pisania pismena sa poznaci cas
-
-
-
- if pressure > 0.0:
- self.draw_brush(widget, x, y, pressure)
- self.last_written_point_index = self.motions_count
-
- if self.writing_status == 1:
- #points[motions_count] = str(int(x)) + " " + str(int(y)) + " " + str(int(pressure)) + "\n"
- self.points[self.motions_count] = str(float(x)) + " " + str(float(y)) + " " + str(pressure) + " " + str(x_tilt) + " " + str(y_tilt) + " " + str((time.time()-self.cas_start)*1000.0) + "\n"
- #print "points[",motions_count,"]=", points[motions_count]
- self.motions_count = self.motions_count + 1
-
- return True
-
-
-
- # END OF drawing_area HANDLERS ************************************
-
-
-
- #def onBoard(self, x, y):
- # return x >= 0 and x < self.width and y >= 0 and y < self.height
-
-
- def end(self):
- #gcompris.sound.reopen()
-
- if self.rootitem != None:
- self.rootitem.destroy()
- self.rootitem = None
- gcompris.score.end()
- pass
-
-
- def get_datfiles_list(self, _pattern):
-
- dat_list = glob.glob(self.save_path + "/writing_tutor/predlohy/" + _pattern + "/*.dat")
- res_dat_list = []
- for _file in dat_list:
- if os.stat(_file).st_size > 0:
- res_dat_list.append(_file) # v zozname necha len neprazdne subory
-
- return res_dat_list
-
-
- def _remove_empty_list_item(self, _list):
- if '' in _list:
- _list.remove('')
-
- return _list
-
-
- def parse_sequence(self):
- """ parse sequence string into levels and sublevels """
- # sequence:
- # a|b|@kruh$ - $ :level separator
- # x|@tvar* - * - show template
-
-
- _sequence = re.sub(r'\s', '', self.sequence) # remove white spaces
- _sequence = _sequence.split("$") # divide into levels (this activity has 2 levels)
- _sequence = self._remove_empty_list_item(_sequence) # remove empty level string if extsts
- self.sequence = []
-
-
- _level = 0
- for _s in _sequence: # for each level (should be max 2)
- _s_tmp = _s
- _dat_list = self._remove_empty_list_item(_s_tmp.split("|"))
- _non_empty_dat_list = _dat_list[:]
- for s in _dat_list: # for each pattern in level
- if s != '*' and len(self.get_datfiles_list(s)) < 1: # iba ak existuju .dat subor predlohy
- _non_empty_dat_list.remove(s)
- print "NEEXISTUJE predloha pre ",s
-
- if _non_empty_dat_list.count('*') > 0:
- _non_empty_dat_list.remove('*')
- self.show_template[_level] = 1
- else:
- self.show_template[_level] = 0
-
- _level += 1
-
- if len(_non_empty_dat_list) > 0:
- self.sequence.append(_non_empty_dat_list)
-
-
-
-
-
- # Called by gcompris when the user click on the level icon
- def set_level(self, level):
- #print "set_level: level=",level
-
- if self.gcomprisBoard.sublevel-1 == self.gcomprisBoard.number_of_sublevel and self.gcomprisBoard.level == self.gcomprisBoard.maxlevel:
- gcompris.bonus.board_finished(gcompris.bonus.FINISHED_RANDOM)
- self.won_level = 1
- return
-
- self.gcomprisBoard.level=level
- self.gcomprisBoard.sublevel=1
- self.gcomprisBoard.number_of_sublevel = len(self.sequence[self.gcomprisBoard.level-1])
- gcompris.bar_set_level(self.gcomprisBoard) # nastavi kocku na cislo levelu
-
- gcompris.score.start(gcompris.score.STYLE_NOTE, 10, 50, len(self.sequence[self.gcomprisBoard.level-1]))
-
- self.start_2("yes")
-
-
-
- def increment_level(self):
- self.gcomprisBoard.sublevel += 1
- if self.gcomprisBoard.sublevel > self.gcomprisBoard.number_of_sublevel:
- self.set_level(self.gcomprisBoard.level % self.gcomprisBoard.maxlevel + 1)
- else:
- self.start_2("yes")
-
-
- # stlacenie "ruky"
- def ok(self):
-
- self.writing_status = None
-
- # zapise do suboru vsetky body od prveho prilozenia pera, az po posledny napisany bod..
-
- if self.last_written_point_index != None: # if something was written...
- for i in range(self.last_written_point_index):
- self.file_handle.write(self.points[i+1])
-
- self.file_handle.close()
-
- self.show_sablier_animation(1)
-
- _dtw = DTW.dtw.DTW(self.save_path, self.pattern)
- dtw_res = _dtw.dtw(self.filename, 1)
- print "ok: dtw_res=", str(dtw_res)
-
- self.show_sablier_animation(0)
-
- if dtw_res < 5:
- gcompris.bonus.display(gcompris.bonus.WIN, gcompris.bonus.RANDOM)
- self.won_level = 1
- else:
- gcompris.bonus.display(gcompris.bonus.LOOSE, gcompris.bonus.RANDOM)
- self.won_level = 1
-
- else: # none was written
- gcompris.bonus.display(gcompris.bonus.LOOSE, gcompris.bonus.RANDOM)
- self.won_level = 1
-
-
- self.last_written_point_index = None
-
-
-
-
-
-
- def key_press(self, keyval, commit_str, preedit_str):
- return False
-
- def repeat(self):
- #print "repeat"
- self.start_2("yes")
-
-
-
- def pause(self, pause): # called after config dialog, help, bonus
- #print "pause"
-
- self.board_paused = pause
-
- if(pause):
- self.area.hide()
- self.show_pen_animation(0)
- if self.label != None:
- self.label.hide()
- else:
- self.area.show()
- if self.won_level:
- # if we are paused, then unpaused it means that they beat the sublevel
- self.increment_level()
- else:
- self.set_level(self.gcomprisBoard.level)
-
- ## There is a problem with GTK widgets, they are not covered by the help, We hide/show them here
- #if(pause):
- # self.area.hide()
- #else:
- # self.area.show()
- # self.repeat()
-
-
- return
-
-
-
- def config(self):
- print "Config"
- pass
-
- def config_stop(self):
- print "config_stop", self
- pass
-
-
-
-
- def show_pen_animation(self, show):
- if show == 0:
- if self.ap != None:
- self.ap.gnomecanvas.hide()
- else:
- if self.ap == None:
- self._ap = gcompris.anim.Animation("writing_tutor/anim_pen.txt")
- self.ap = gcompris.anim.CanvasItem(self._ap, self.rootitem)
- self.ap.gnomecanvas.set(x=80, y=gcompris.BOARD_HEIGHT - 70)
- self.ap.setState(0)
- self.ap.gnomecanvas.show()
- else:
- self.ap.gnomecanvas.show()
-
-
- def show_sablier_animation(self, show):
- if show == 0:
- if self.sb != None:
- self.sb.gnomecanvas.hide()
- else:
- if self.sb == None:
- self._sb = gcompris.anim.Animation("connect4/sablier.txt")
- self.sb = gcompris.anim.CanvasItem(self._sb, self.rootitem)
- self.sb.gnomecanvas.set(x=40, y= gcompris.BOARD_HEIGHT - 300)
- self.sb.setState(0)
- self.sb.gnomecanvas.show()
- else:
- self.sb.gnomecanvas.show()
-
-
- def draw_text(self, x, y, text, color='blue'):
- if self.label != None:
- self.label.destroy()
-
- self.label = self.rootitem.add(gnomecanvas.CanvasText, x=x, y=y, text=text, fill_color="dark blue", font='sans bold 45', )
-
- #self.label = self.rootitem.add(gnomecanvas.CanvasText, x= x, y= y, text= text, fill_color="black",
- # font=gcompris.skin.get_font("gcompris/board/huge bold"), )
-
-
- def set_tablet_indicator(self, tablet_status):
- """
- Description:
- Set tablet indicator icon
-
- Arguments:
- tablet_status -- 1 or 0 indicating status of tablet device (enabled or disabled)
- """
- global _global_rootitem
- global _global_tablet_indicator
-
- #print "set_tablet_indicator(", tablet_status, ")"
-
- if tablet_status == 1:
- _pixmap = gcompris.utils.load_pixmap("writing_tutor/tablet_active.png")
- else:
- _pixmap = gcompris.utils.load_pixmap("writing_tutor/tablet_inactive.png")
-
- if _global_tablet_indicator != None:
- _global_tablet_indicator.destroy()
-
- _global_tablet_indicator = _global_rootitem.add(gnomecanvas.CanvasPixbuf, pixbuf = _pixmap, x = 10, y = gcompris.BOARD_HEIGHT -50)
- _global_tablet_indicator.show()
-
-
-
- def config_start(self, profile):
- print "config_start"
- global _global_rootitem
-
-
- # show only tablet configuration. save_path, sequence only in admin mode
- if _global_rootitem != None: # not in admin mode
- dlg = GtkInputDialog(self)
- return
-
- self.configure_profile = profile
-
- self.config_dict = self.init_config()
- self.config_dict.update(gcompris.get_conf(profile, self.gcomprisBoard))
-
- self.main_vbox = gcompris.configuration_window (\
- _('Hra <b>%s</b> - nastavenie pre profil <b>%s</b>') % ('Tutor', profile.name), self.save_config)
-
- gcompris.separator()
- self.button = gtk.Button("Nastavenie tabletu...")
- self.button.connect("clicked", self.input_dlg_callback)
- self.button.show()
- self.main_vbox.pack_start(self.button, False, False, 0)
- gcompris.separator()
-
- # !! ak je v admin mode, tak nemoze nastavovat tablet...
- if _global_rootitem == None: # in admin mode
- self.button.set_state(gtk.STATE_INSENSITIVE)
-
-
- gcompris.textview(_('Adresar, kde sa budu ukladat vzorky/predlohy: '), 'save_path', 'desc', self.config_dict['save_path'],
- self.validate_callback)
- gcompris.separator()
-
- gcompris.textview(_('Postupnosti tvarov pre testovanie: '), 'template_match_sequence', 'desc', self.config_dict['template_match_sequence'], self.validate_callback)
- gcompris.separator()
-
-
- def validate_callback(self, key, value, z):
- #print "validate_callback: key=", key, ", value=", value, ", z=", z
-
- if key == 'save_path':
- if not os.path.exists(value):
- return False
- if key == 'sequence':
- pass
-
- return True
-
-
- def input_dlg_callback(self, table):
- dlg = GtkInputDialog()
-
-
- def dummy_enter_callback(self, widget, _entry):
- pass
-
- def clb_dummy(self, x=None):
- pass
-
- def save_config(self, table):
- print "save_config: table=", table
- global _global_rootitem
-
- if table == None:
- return
-
- for key,value in table.iteritems():
- gcompris.set_board_conf(self.configure_profile, self.gcomprisBoard, key, value) # save config to db
-
- if _global_rootitem != None:
- self.start_2("no")
-
-
- def configuration(self, value, init):
- if self.config_dict.has_key(value):
- return eval(self.config_dict[value])
- else:
- return init
-
-
- def init_config(self):
- default_config_dict = { 'save_path' :gcompris.get_properties().user_dir,
- 'template_match_sequence' : 'a|b|c $ A|B|C $ 1|2 $ @kruh'
- }
- return default_config_dict
-
- # sequence format:
-
- #a|b|c|d|A|B|C|D $ 1. level
- #ab|auto $ 2. level
- #@kruh $ 3. level
-
-
-
-# END OF class Gcompris_template_match ************************************
-
-
-
-
-def stop_board():
- gcompris.bonus.board_finished(gcompris.bonus.FINISHED_RANDOM)
-
-