Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorolpc user <olpc@xo-a7-2e-8c.localdomain>2010-05-03 02:52:00 (GMT)
committer olpc user <olpc@xo-a7-2e-8c.localdomain>2010-05-03 02:52:00 (GMT)
commite362b9bbf4a2a518f8e2947067c9ac9cebd6c988 (patch)
tree268ff8acc8c7e2ac9b476d7448f7cd5b290f5242
parent2d560fb0b16d7c03b3a6ac1abe270fdd0bcc43a9 (diff)
Create repository and load
-rw-r--r--dist/Honeypot-1 (Kopie).zipbin0 -> 14575 bytes
-rw-r--r--dist/Honeypot-1.tar.bz2bin0 -> 14 bytes
-rw-r--r--dist/Honeypot-1.xobin0 -> 14599 bytes
-rw-r--r--dist/Honeypot.activity/MANIFEST8
-rw-r--r--dist/Honeypot.activity/activity.py501
-rw-r--r--dist/Honeypot.activity/activity/activity.info8
-rw-r--r--dist/Honeypot.activity/activity/honeypot.svg17
-rw-r--r--dist/Honeypot.activity/gtk_honeypot.glade85
-rwxr-xr-xdist/Honeypot.activity/gtk_honeypot.py280
-rw-r--r--dist/Honeypot.activity/logger.logfile371
-rw-r--r--dist/Honeypot.activity/mathparse_honeypot.py103
-rw-r--r--dist/Honeypot.activity/mathparse_honeypot.pyobin0 -> 2842 bytes
-rw-r--r--dist/Honeypot.activity/my_first_questions.honeypot77
-rw-r--r--dist/Honeypot.activity/xml_honeypot.py111
-rw-r--r--dist/Honeypot.activity/xml_honeypot.pyobin0 -> 4933 bytes
15 files changed, 1561 insertions, 0 deletions
diff --git a/dist/Honeypot-1 (Kopie).zip b/dist/Honeypot-1 (Kopie).zip
new file mode 100644
index 0000000..b911c12
--- /dev/null
+++ b/dist/Honeypot-1 (Kopie).zip
Binary files differ
diff --git a/dist/Honeypot-1.tar.bz2 b/dist/Honeypot-1.tar.bz2
new file mode 100644
index 0000000..b56f3b9
--- /dev/null
+++ b/dist/Honeypot-1.tar.bz2
Binary files differ
diff --git a/dist/Honeypot-1.xo b/dist/Honeypot-1.xo
new file mode 100644
index 0000000..a891eb6
--- /dev/null
+++ b/dist/Honeypot-1.xo
Binary files differ
diff --git a/dist/Honeypot.activity/MANIFEST b/dist/Honeypot.activity/MANIFEST
new file mode 100644
index 0000000..6185978
--- /dev/null
+++ b/dist/Honeypot.activity/MANIFEST
@@ -0,0 +1,8 @@
+activity.py
+gtk_honeypot.glade
+gtk_honeypot.py
+xml_honeypot.py
+mathparse_honeypot.py
+my_first_questions.honeypot
+activity/activity.info
+activity/honeypot.svg
diff --git a/dist/Honeypot.activity/activity.py b/dist/Honeypot.activity/activity.py
new file mode 100644
index 0000000..066041e
--- /dev/null
+++ b/dist/Honeypot.activity/activity.py
@@ -0,0 +1,501 @@
+#!/usr/bin/env python
+#
+# Copyright (C) 2010, Johannes Ponader
+#
+# 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 2 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, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+import logging
+_logger = logging.getLogger('activity')
+_logger.setLevel(logging.DEBUG)
+
+import pygtk
+pygtk.require('2.0')
+import gtk, sys, random, time
+
+# load activity source code from gtk_honeypot.py
+from gtk_honeypot import gtk_honeypot
+
+from sugar.activity import activity
+
+class honeypot(activity.Activity):
+ def __init__(self, handle):
+ activity.Activity.__init__(self, handle)
+ self._name = handle
+
+ self.set_title("Honeypot")
+
+ # Show the toolbox elements
+ toolbox = activity.ActivityToolbox(self)
+ self.set_toolbox(toolbox)
+ toolbox.show()
+
+ # create the main container
+ self._main_view = gtk.VBox()
+
+ # import gtk_honeypot, where the main activity code lies
+ # load class, which creates gtk_honeypot.widget
+ self.gtk_honeypot = gtk_honeypot()
+ # remove the widget's parent
+ if self.gtk_honeypot.widget.parent:
+ _logger.debug('s.gtk-h.widget.parent: ' + str(self.gtk_honeypot.widget.parent))
+ self.gtk_honeypot.widget.parent.remove(self.gtk_honeypot.widget)
+ _logger.debug('s.gtk-h.widget.parent: ' + str(self.gtk_honeypot.widget.parent))
+ # and attach the widget to our window
+ self._main_view.pack_start(self.gtk_honeypot.widget)
+
+ # display everything
+ self.gtk_honeypot.widget.show()
+ self._main_view.show()
+ self.set_canvas(self._main_view)
+ self.show_all()
+
+"""
+ # Register the event callbacks
+ # Exposure needs redraw
+ self.connect("expose_event", self.area_expose_cb)
+ # keyboard
+ self.connect("key_press_event", self.keypress_cb)
+ # mouse
+ self.connect("button_press_event", self.button_press_cb)
+ self.show
+
+
+ # Seed the random number generator
+ random.seed(time.time())
+
+ self.area = self.window
+ self.gc = slf.area.new_gc()
+
+"""
+
+
+"""
+import logging
+_logger = logging.getLogger('implode-activity')
+
+from gettext import gettext as _
+
+from sugar.activity.activity import Activity, get_bundle_path
+from sugar.graphics import style
+from sugar.graphics.icon import Icon
+from sugar.graphics.radiotoolbutton import RadioToolButton
+from sugar.graphics.toolbutton import ToolButton
+
+try:
+ # 0.86+ toolbar widgets
+ from sugar.activity.widgets import ActivityToolbarButton, StopButton
+ from sugar.graphics.toolbarbox import ToolbarBox, ToolbarButton
+ _USE_OLD_TOOLBARS = False
+except ImportError:
+ # Pre-0.86 toolbar widgets
+ from sugar.activity.activity import ActivityToolbox
+ _USE_OLD_TOOLBARS = True
+
+from implodegame import ImplodeGame
+from helpwidget import HelpWidget
+
+import os
+
+try:
+ import json
+ json.dumps
+except (ImportError, AttributeError):
+ import simplejson as json
+from StringIO import StringIO
+import gtk
+import gobject
+
+from keymap import KEY_MAP
+
+class ImplodeActivity(Activity):
+ def __init__(self, handle):
+ super(ImplodeActivity, self).__init__(handle)
+
+ _logger.debug('Starting implode activity...')
+
+ self._game = ImplodeGame()
+
+ game_box = gtk.VBox()
+ game_box.pack_start(self._game)
+ self._stuck_strip = _StuckStrip()
+
+ self._configure_toolbars()
+
+ self.set_canvas(game_box)
+
+ # Show everything except the stuck strip.
+ self.show_all()
+ game_box.pack_end(self._stuck_strip, expand=False)
+
+ self._game.connect('show-stuck', self._show_stuck_cb)
+ self._stuck_strip.connect('undo-clicked', self._stuck_undo_cb)
+ game_box.connect('key-press-event', self._key_press_event_cb)
+
+ self._game.grab_focus()
+
+ last_game_path = self._get_last_game_path()
+ if os.path.exists(last_game_path):
+ self.read_file(last_game_path)
+
+ def _get_last_game_path(self):
+ return os.path.join(self.get_activity_root(), 'data', 'last_game')
+
+ def read_file(self, file_path):
+ # Loads the game state from a file.
+ f = file(file_path, 'rt')
+ content = f.read()
+ io = StringIO(content)
+ file_data = json.load(io)
+ f.close()
+
+ print file_data
+ _logger.debug(file_data)
+ (file_type, version, game_data) = file_data
+ if file_type == 'Implode save game' and version <= [1, 0]:
+ self._game.set_game_state(game_data)
+ # Ensure that the visual display matches the game state. <MS>
+ self._levels_buttons[game_data['difficulty']].props.active = True
+
+ def write_file(self, file_path):
+ # Writes the game state to a file.
+ game_data = self._game.get_game_state()
+ file_data = ['Implode save game', [1, 0], game_data]
+ last_game_path = self._get_last_game_path()
+ for path in (file_path, last_game_path):
+ f = file(path, 'wt')
+ io = StringIO()
+ json.dump(file_data,io)
+ content = io.getvalue()
+ f.write(content)
+ f.close()
+
+ def _show_stuck_cb(self, state, data=None):
+ if data:
+ self._stuck_strip.show_all()
+ else:
+ if self._stuck_strip.focus_child:
+ self._game.grab_focus()
+ self._stuck_strip.hide()
+
+ def _stuck_undo_cb(self, state, data=None):
+ self._game.undo_to_solvable_state()
+
+ def _key_press_event_cb(self, source, event):
+ # Make the game navigable by keypad controls.
+ action = KEY_MAP.get(event.keyval, None)
+ if action is None:
+ return False
+ if not self._stuck_strip.flags() & gtk.VISIBLE:
+ return True
+ if self._game.focus_child:
+ if action == 'down':
+ self._stuck_strip.button.grab_focus()
+ return True
+ elif self._stuck_strip.focus_child:
+ if action == 'up':
+ self._game.grab_focus()
+ elif action == 'select':
+ self._stuck_strip.button.activate()
+ return True
+ return True
+
+ def _configure_toolbars(self):
+ #Create, set, and show a toolbar box with an activity button, game
+ controls, difficulty selector, help button, and stop button. All
+ callbacks are locally defined.
+
+ if _USE_OLD_TOOLBARS:
+ toolbox = ActivityToolbox(self)
+ toolbar = gtk.Toolbar()
+ else:
+ toolbar_box = ToolbarBox()
+ toolbar = toolbar_box.toolbar
+
+ activity_button = ActivityToolbarButton(self)
+ toolbar_box.toolbar.insert(activity_button, 0)
+ activity_button.show()
+
+ self._add_expander(toolbar_box.toolbar)
+
+ toolbar.add(gtk.SeparatorToolItem())
+
+ def add_button(icon_name, tooltip, func):
+ def callback(source):
+ func()
+ button = ToolButton(icon_name)
+ toolbar.add(button)
+ button.connect('clicked', callback)
+ button.set_tooltip(tooltip)
+
+ add_button('new-game' , _("New") , self._game.new_game)
+ add_button('replay-game', _("Replay"), self._game.replay_game)
+ add_button('edit-undo' , _("Undo") , self._game.undo)
+ add_button('edit-redo' , _("Redo") , self._game.redo)
+
+ toolbar.add(gtk.SeparatorToolItem())
+
+ self._levels_buttons = []
+ def add_level_button(icon_name, tooltip, numeric_level):
+ if self._levels_buttons:
+ button = RadioToolButton(named_icon=icon_name,
+ group=self._levels_buttons[0])
+ else:
+ button = RadioToolButton(named_icon=icon_name)
+ self._levels_buttons.append(button)
+ toolbar.add(button)
+
+ def callback(source):
+ if source.get_active():
+ self._game.set_level(numeric_level)
+
+ button.connect('clicked', callback)
+ button.set_tooltip(tooltip)
+
+ add_level_button('easy-level' , _("Easy") , 0)
+ add_level_button('medium-level', _("Medium"), 1)
+ add_level_button('hard-level' , _("Hard") , 2)
+
+ self._add_expander(toolbar)
+
+ def _help_clicked_cb():
+ help_window = _HelpWindow()
+ help_window.set_transient_for(self.get_toplevel())
+ help_window.show_all()
+
+ # NOTE: Naming the icon "help" instead of "help-icon" seems to use a
+ # GTK stock icon instead of our custom help; the stock icon may be more
+ # desireable in the future. It doesn't seem to be themed for Sugar
+ # right now, however.
+ add_button('help-icon', _("Help"), _help_clicked_cb)
+
+ if _USE_OLD_TOOLBARS:
+ toolbox.add_toolbar(_("Game"), toolbar)
+ toolbox.set_current_toolbar(1)
+
+ self.set_toolbox(toolbox)
+ toolbox.show()
+ else:
+ stop_button = StopButton(self)
+ stop_button.props.accelerator = '<Ctrl><Shift>Q'
+ toolbar_box.toolbar.insert(stop_button, -1)
+ stop_button.show()
+
+ self.set_toolbar_box(toolbar_box)
+ toolbar_box.show()
+
+ def _add_expander(self, toolbar):
+ #Insert a toolbar item which will expand to fill the available
+ space.
+ separator = gtk.SeparatorToolItem()
+ separator.props.draw = False
+ separator.set_expand(True)
+ toolbar.insert(separator, -1)
+ separator.show()
+
+
+class _DialogWindow(gtk.Window):
+ # A base class for a modal dialog window.
+ def __init__(self, icon_name, title):
+ super(_DialogWindow, self).__init__()
+
+ self.set_border_width(style.LINE_WIDTH)
+ offset = style.GRID_CELL_SIZE
+ width = gtk.gdk.screen_width() / 2
+ height = gtk.gdk.screen_height() / 2
+ self.set_size_request(width, height)
+ self.set_position(gtk.WIN_POS_CENTER_ALWAYS)
+ self.set_decorated(False)
+ self.set_resizable(False)
+ self.set_modal(True)
+
+ vbox = gtk.VBox()
+ self.add(vbox)
+
+ toolbar = _DialogToolbar(icon_name, title)
+ toolbar.connect('stop-clicked', self._stop_clicked_cb)
+ vbox.pack_start(toolbar, False)
+
+ self.content_vbox = gtk.VBox()
+ self.content_vbox.set_border_width(style.DEFAULT_SPACING)
+ vbox.add(self.content_vbox)
+
+ self.connect('realize', self._realize_cb)
+
+ def _stop_clicked_cb(self, source):
+ self.destroy()
+
+ def _realize_cb(self, source):
+ self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
+ self.window.set_accept_focus(True)
+
+
+class _HelpWindow(_DialogWindow):
+ # A dialog window to display the game instructions.
+ def __init__(self):
+ super(_HelpWindow, self).__init__('help-icon', _("Help"))
+
+ offset = style.GRID_CELL_SIZE
+ width = gtk.gdk.screen_width() - offset * 2
+ height = gtk.gdk.screen_height() - offset * 2
+ self.set_size_request(width, height)
+
+ self._help_widget = HelpWidget(self._icon_file)
+ self.content_vbox.pack_start(self._help_widget)
+
+ self._help_nav_bar = _HelpNavBar()
+ self.content_vbox.pack_end(self._help_nav_bar,
+ expand=False,
+ padding=style.DEFAULT_SPACING)
+
+ for (signal_name, callback) in [
+ ('forward-clicked', self._forward_clicked_cb),
+ ('reload-clicked', self._reload_clicked_cb),
+ ('back-clicked', self._back_clicked_cb)]:
+ self._help_nav_bar.connect(signal_name, callback)
+
+ self._update_prev_next()
+
+ def _forward_clicked_cb(self, source):
+ self._help_widget.next_stage()
+ self._update_prev_next()
+
+ def _back_clicked_cb(self, source):
+ self._help_widget.prev_stage()
+ self._update_prev_next()
+
+ def _reload_clicked_cb(self, source):
+ self._help_widget.replay_stage()
+
+ def _icon_file(self, icon_name):
+ activity_path = get_bundle_path()
+ file_path = os.path.join(activity_path, 'icons', icon_name + '.svg')
+ return file_path
+
+ def _update_prev_next(self):
+ hw = self._help_widget
+ self._help_nav_bar.set_can_prev_stage(hw.can_prev_stage())
+ self._help_nav_bar.set_can_next_stage(hw.can_next_stage())
+
+
+class _DialogToolbar(gtk.Toolbar):
+ # Displays a dialog window's toolbar, with title, icon, and close box.
+ __gsignals__ = {
+ 'stop-clicked' : (gobject.SIGNAL_RUN_LAST, None, ()),
+ }
+ def __init__(self, icon_name, title):
+ super(_DialogToolbar, self).__init__()
+
+ icon = Icon()
+ icon.set_from_icon_name(icon_name, gtk.ICON_SIZE_LARGE_TOOLBAR)
+ self._add_widget(icon)
+
+ self._add_separator()
+
+ label = gtk.Label(title)
+ self._add_widget(label)
+
+ self._add_separator(expand=True)
+
+ stop = ToolButton(icon_name='dialog-cancel')
+ stop.set_tooltip(_('Done'))
+ stop.connect('clicked', self._stop_clicked_cb)
+ self.add(stop)
+
+ def _add_separator(self, expand=False):
+ separator = gtk.SeparatorToolItem()
+ separator.set_expand(expand)
+ separator.set_draw(False)
+ self.add(separator)
+
+ def _add_widget(self, widget):
+ tool_item = gtk.ToolItem()
+ tool_item.add(widget)
+ self.add(tool_item)
+
+ def _stop_clicked_cb(self, button):
+ self.emit('stop-clicked')
+
+
+class _HelpNavBar(gtk.HButtonBox):
+ # A widget to display the navigation controls at the bottom of the help
+ # dialog.
+ __gsignals__ = {
+ 'forward-clicked' : (gobject.SIGNAL_RUN_LAST, None, ()),
+ 'back-clicked' : (gobject.SIGNAL_RUN_LAST, None, ()),
+ 'reload-clicked' : (gobject.SIGNAL_RUN_LAST, None, ()),
+ }
+
+ def __init__(self):
+ super(_HelpNavBar, self).__init__()
+
+ self.set_layout(gtk.BUTTONBOX_SPREAD)
+
+ def add_button(icon_name, tooltip, signal_name):
+ icon = Icon()
+ icon.set_from_icon_name(icon_name, gtk.ICON_SIZE_LARGE_TOOLBAR)
+ button = gtk.Button()
+ button.set_image(icon)
+ button.set_tooltip_text(tooltip)
+ self.add(button)
+
+ def callback(source):
+ self.emit(signal_name)
+ button.connect('clicked', callback)
+
+ return button
+
+ self._back_button = add_button('back', _("Previous"), 'back-clicked')
+ add_button('reload', _("Again"), 'reload-clicked')
+ self._forward_button = add_button('forward', _("Next"), 'forward-clicked')
+
+ def set_can_prev_stage(self, can_prev_stage):
+ self._back_button.set_sensitive(can_prev_stage)
+
+ def set_can_next_stage(self, can_next_stage):
+ self._forward_button.set_sensitive(can_next_stage)
+
+
+class _StuckStrip(gtk.HBox):
+ __gsignals__ = {
+ 'undo-clicked' : (gobject.SIGNAL_RUN_LAST, None, ()),
+ }
+ def __init__(self, *args, **kwargs):
+ super(_StuckStrip, self).__init__(*args, **kwargs)
+
+ spacer1 = gtk.Label('')
+ self.pack_start(spacer1, expand=True)
+
+ spacer2 = gtk.Label('')
+ self.pack_end(spacer2, expand=True)
+
+ self.set_spacing(10)
+
+ self.set_border_width(10)
+
+ label = gtk.Label(_("Stuck? You can still solve the puzzle."))
+ self.pack_start(label, expand=False)
+
+ icon = Icon()
+ icon.set_from_icon_name('edit-undo-many', gtk.ICON_SIZE_LARGE_TOOLBAR)
+ self.button = gtk.Button(stock=gtk.STOCK_UNDO)
+ self.button.set_image(icon)
+ self.button.set_label(_("Undo some moves"))
+ self.pack_end(self.button, expand=False)
+
+ def callback(source):
+ self.emit('undo-clicked')
+ self.button.connect('clicked', callback)
+
+"""
diff --git a/dist/Honeypot.activity/activity/activity.info b/dist/Honeypot.activity/activity/activity.info
new file mode 100644
index 0000000..116dc5e
--- /dev/null
+++ b/dist/Honeypot.activity/activity/activity.info
@@ -0,0 +1,8 @@
+[Activity]
+name = Honeypot
+activity_version = 1
+service_name = org.laptop.honeypot
+icon = honeypot
+class = activity.honeypot
+license = GPLv2+
+show_launcher = yes
diff --git a/dist/Honeypot.activity/activity/honeypot.svg b/dist/Honeypot.activity/activity/honeypot.svg
new file mode 100644
index 0000000..fa46eaf
--- /dev/null
+++ b/dist/Honeypot.activity/activity/honeypot.svg
@@ -0,0 +1,17 @@
+<?xml version="1.0" ?><!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd' [
+ <!ENTITY stroke_color "#010101">
+ <!ENTITY fill_color "#FFFFFF">
+]>
+<svg enable-background="new 0 0 55 55" height="55px" version="1.1" viewBox="0 0 55 55" width="55px" x="0px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" y="0px">
+<g display="block" id="activity-honeypot">
+ <g display="inline">
+ <path d="m 43.300034,10.144966 c 7.698563,19.128987 6.051971,18.097876 2.447034,32.796153 -2.099519,8.560292 -5.107162,8.837818 -16.154662,8.837818 -11.0475,0 -13.685846,-0.143017 -16.15366,-8.022141 C 8.8579002,29.131279 5.9262653,34.011339 14.370949,10.261492" fill="&fill_color;" stroke="&stroke_color;" stroke-linecap="square" stroke-width="3.5"/>
+ <g>
+
+ <g><path d="m 9.4704596,26.844669 c 16.1051494,5.482769 26.2761954,4.924095 39.1330814,-0.767241 0.21448,2.770582 0.05739,6.67036 -1.566795,11.7395 -10.981496,3.666733 -20.198862,4.048603 -35.665231,0.0376 C 9.5083015,33.564619 8.399748,31.287385 9.4704596,26.844669 z"
+ fill="&fill_color;" stroke="&stroke_color;" stroke-linecap="square" stroke-width="3.5"/></g>
+ </g>
+ </g>
+ </g><path d="m 14.311685,7.1996824 c 9.760031,-0.081564 19.572293,-0.1280551 29.644495,0 3.59362,0.1283784 4.13841,2.1059895 -0.141457,2.1352335 0.49248,1.0468131 -28.772732,0.9183681 -28.870714,0 C 12.086051,9.5052829 9.3615349,7.475641 14.311685,7.1996824 z"
+ fill="&fill_color;" stroke="&stroke_color;" stroke-linecap="square" stroke-width="3.5"/><path d="m 30.960157,6.9850899 c 0.113166,4.9718801 0.209894,5.6214611 -2.107547,10.0689251 -1.40723,2.700653 -3.795595,7.600714 2.185001,9.462568 7.055728,1.723529 10.817114,-5.752931 7.219554,-11.801529 -1.938213,-2.452905 -1.327292,-7.5195423 -1.327292,-7.5195423" fill="&fill_color;" stroke="&stroke_color;" stroke-linecap="square" stroke-width="3.5"/>
+ </svg>
diff --git a/dist/Honeypot.activity/gtk_honeypot.glade b/dist/Honeypot.activity/gtk_honeypot.glade
new file mode 100644
index 0000000..c6d8d6b
--- /dev/null
+++ b/dist/Honeypot.activity/gtk_honeypot.glade
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<glade-interface>
+ <!-- interface-requires gtk+ 2.16 -->
+ <!-- interface-naming-policy project-wide -->
+ <widget class="GtkWindow" id="window1">
+ <child>
+ <widget class="GtkVBox" id="vbox1">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <property name="homogeneous">True</property>
+ <child>
+ <widget class="GtkButton" id="label_question">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Click here for a new question.</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ </widget>
+ <packing>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkVBox" id="vbox2">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <widget class="GtkEntry" id="textfield_answer">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="invisible_char">&#x25CF;</property>
+ </widget>
+ <packing>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkHBox" id="hbox2">
+ <property name="visible">True</property>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <widget class="GtkVBox" id="vbox3">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <widget class="GtkButton" id="button_guess">
+ <property name="label" translatable="yes">This button has no special function so far...</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ </widget>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ </widget>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </widget>
+ </child>
+ </widget>
+</glade-interface>
diff --git a/dist/Honeypot.activity/gtk_honeypot.py b/dist/Honeypot.activity/gtk_honeypot.py
new file mode 100755
index 0000000..645f5c2
--- /dev/null
+++ b/dist/Honeypot.activity/gtk_honeypot.py
@@ -0,0 +1,280 @@
+#!/usr/bin/env python
+#
+# Copyright (C) 2010, Johannes Ponader
+#
+# 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 2 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, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+from mathparse_honeypot import mathparse_honeypot
+from xml_honeypot import xml_honeypot
+
+import gtk
+import gtk.glade
+import sys
+import random
+import time
+import logging
+import pango
+import pygtk
+
+'''
+try:
+ # should we use the treadsafe database module TS_Base?.
+ # although it is very unlikelike that a user runs two instances on his account,
+ # what would be the effect?
+ from buzhug import Base
+
+# as long as buzhug is a subdirectory of Honeypot.activity, import should be trivial
+# do we want to install it anyway? would that be better for performance?
+except ImportError:
+
+ from distutils.core import setup
+
+ # this command, esp. sys_args = 'install', is not tested yet
+ # perhaps run_setup('buzhug_setup', 'install') would be more clearly
+
+ # btw, if we don't have the permission to install it into the standard location
+ # ('/usr/', i guess), we have to sudo the install or have to use the home dir instead?
+ # see http://docs.python.org/install/
+ # what about win users using the script as standalone?
+
+ setup(name='buzhug',
+ version='1.6',
+ description='Buzhug, a pure-Python database',
+ author='Pierre Quentel',
+ author_email='pierre.quentel@gmail.com',
+ url='http://buzhug.sourceforge.net/',
+ packages = ['buzhug'],
+ script_args = 'install')
+
+ from buzhug import Base
+
+# if we don't have the permission to install it into the standard location
+# ('/usr/', i guess), we have to sudo the install or have to use the home dir instead?
+# see http://docs.python.org/install/
+# what about win users using the script as standalone?
+'''
+
+
+_logger = logging.getLogger('gtk_honeypot')
+
+# for logging outside sugar
+if __name__ == '__main__':
+ LOG_FILENAME = 'logger.logfile'
+ logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG)
+
+_logger.setLevel(logging.DEBUG)
+
+# Pango is a library for rendering internationalized texts
+
+pygtk.require('2.0')
+
+# load xml parser from xml_honeypot.py
+
+
+# load mathparse parser from mathparse_honeypot.py
+
+# class guessfield(gtk_textfield):
+
+class gtk_honeypot:
+
+ def __init__(self, runaslib=True):
+
+ # Create DB, certainly, this goes into Journal afterwards, if it's not standalone
+ # not yet implemented
+ # path = '/home/olpc/Development/buzhug/'
+ # db = Base(path)
+
+
+ # Load glade xml
+ self.xml = gtk.glade.XML("gtk_honeypot.glade")
+
+ # get window
+ self.window = self.xml.get_widget('window1')
+ self.window.connect("delete_event", gtk.main_quit)
+
+ # get window child
+ self.window_child = self.window.get_child()
+ _logger.debug("self.window_child: " + str(self.window_child))
+
+ # get the label_button
+ self.label_question = self.xml.get_widget('label_question')
+ self.label_question.connect('clicked', self.on_label_question)
+
+ # with self.textfield_answer as tf:
+ # funktioniert das? oder hat das seltame Nebeneffekte?
+ # am ende von with wid das objekt schliesslich aufgeraeumt...
+
+ # get the textfield
+ self.textfield_answer = self.xml.get_widget('textfield_answer')
+ # self.textfield_answer.connect('clicked', self.on_guessed)
+ self.textfield_answer.connect('activate', self.on_textfield_answer_activate)
+ # self.textfield_answer.connect('move-cursor', self.on_textfield_answer_move_cursor)
+
+ self.textfield_answer.handler_id = []
+ # self.textfield.handler_id.append(self.textfield_answer.connect('insert-at-cursor', self.on_textfield_answer_insert_at_cursor))
+ self.textfield_answer.handler_id.append(self.textfield_answer.connect('move-cursor', self.kill_event, 'move-cursor'))
+ self.textfield_answer.handler_id.append(self.textfield_answer.connect('delete-text', self.kill_event, 'delete-text'))
+ self.textfield_answer.handler_id.append(self.textfield_answer.connect('insert-text', self.on_textfield_answer_insert_text))
+ # we need a get-focus or so event-handler, which sets the cursor right again in state STATE_WRONG
+
+ self.textfield_answer.move_cursor_id = self.textfield_answer.handler_id[0]
+ # block these handlers for now
+ for i in range(0, len(self.textfield_answer.handler_id)):
+ self.textfield_answer.handler_block(self.textfield_answer.handler_id[i])
+
+
+
+ # self.textfield_answer.connect('event', self.on_textfield_answer_event)
+ # backspace, copy-clipboard, cut-clipboard, deleste-from-cursor, insert-at-cursor, move-cursor, paste-clipboard,
+ # changed, delete-text, insert-text
+ # gobject.stop_emission()
+ # key-press-event
+ # selection-clear-event, (selection-get-event),
+ # drag-.
+
+
+ # this is a dirty way to define the color, i suppose
+ # we should use the current stylemap
+ self.cursor_color_train = gtk.Entry().get_colormap().alloc_color("red")
+ self.cursor_color_answer = gtk.Entry().get_colormap().alloc_color("black")
+
+ self.textfield_answer.modify_cursor(self.cursor_color_answer, self.cursor_color_answer)
+
+ # get the button
+ self.button_guess = self.xml.get_widget('button_guess')
+ self.button_guess.connect('clicked', self.on_button_guess)
+ # self.button_guess.connect('activate', self.on_button_guess)
+
+ # self.widget will be attached to the Activity
+ # this can be any gtk widget except a window
+ self.widget = self.window_child
+
+ # Seed the random number generator
+ random.seed(time.time())
+
+ # load one or more collections of questions and answers
+ self.honeypot = xml_honeypot()
+ self.honeypot.load_drops()
+
+ # load the mathpars parser
+ # note: there must be a parser regitration lateron, so that the script
+ # can determine which parsers are successfully loaded
+ self.mathparse = mathparse_honeypot()
+
+ # we define four states:
+ # 'fresh', 'open', 'wrong', 'right'
+ self.STATE_FRESH = 0
+ self.STATE_OPEN = 1
+ self.STATE_WRONG = 2
+
+ # and safe the actual state in self.state
+ self.state = self.STATE_FRESH
+
+ if not runaslib:
+ self.window.show_all()
+ gtk.main()
+
+
+ def on_textfield_answer_activate(self, *args):
+
+ if self.state == self.STATE_FRESH:
+ self.open_new_question()
+
+ elif self.state == self.STATE_OPEN:
+ self.check_answer()
+
+ # we need no else, because we want to ignore RETURN in the state 'wrong'
+
+
+
+ def on_textfield_answer_insert_text(self, *args):
+
+ # insert-text(editable, new_text, text_length, position, data)
+
+ if args[1] == self.drop[1][self.rewrite_position]:
+ self.rewrite_position += 1
+ self.textfield_answer.handler_block(self.textfield_answer.move_cursor_id)
+ self.textfield_answer.set_position(self.rewrite_position)
+ self.textfield_answer.handler_unblock(self.textfield_answer.move_cursor_id)
+
+ # we check if the user typed in the whole answer
+ # kann ich die endposition eleganter auslesen?
+ if self.textfield_answer.get_position() == len(self.drop[1]):
+ self.label_question.set_label(self.drop[0] + "\nThat's it.\nClick here or hit RETURN for another question.")
+
+ for i in range(0, len(self.textfield_answer.handler_id)):
+ self.textfield_answer.handler_block(self.textfield_answer.handler_id[i])
+
+ self.state = self.STATE_FRESH
+
+ self.textfield_answer.stop_emission('insert-text')
+
+
+ def kill_event(self, *args):
+ self.textfield_answer.stop_emission(args[len(args)-1])
+
+ def on_textfield_answer_event(self, *args):
+ if args[1].type not in (3, 10, 11, 2):
+ # GDK_MOTION_NOTIFY, GDK_ENTER_NOTIFY, GDK_LEAVE_NOTIFY, GDK_EXPOSE):
+ print(args[1].type)
+
+ def on_button_guess(self, *args):
+ # self.textfield_answer.add_events()
+ # self.textfield_answer.set_editable(False)
+
+ # self.textfield_answer.select_region(0,1)
+ pass
+
+
+ def on_label_question(self, *args):
+ self.open_new_question()
+
+ def open_new_question(self):
+ self.drop = random.choice(self.honeypot.content_handler.drops)
+ _logger.debug('random choice: ' + str(self.drop))
+ # we now take always the mathparse parser -
+ # choose the parser dynamically from xml-atribute lateron
+ # self.label_question.set_label("I'll ask some other question, dude: " + self.drop[0])
+ self.drop = self.mathparse.parse(self.drop)
+ self.label_question.set_label("Question:\n" + self.drop[0])
+
+ self.textfield_answer.grab_focus()
+ self.textfield_answer.set_text('')
+ self.state = self.STATE_OPEN
+
+ def check_answer(self):
+ if self.textfield_answer.get_text() == self.drop[1]:
+ # correct answer
+ self.label_question.set_label("Correct!\nClick here or hit RETURN for another question.")
+ self.state = self.STATE_FRESH
+ else:
+ # wrong answer
+ self.label_question.set_label(self.drop[0] + "\nYour answer:\n" + self.textfield_answer.get_text() +
+ "\nThis answer is wrong :-(\nRetype the correct answer\nand hit RETURN for the next question.")
+
+ # write correct answer
+ self.textfield_answer.set_text(self.drop[1])
+ self.rewrite_position = 0
+
+ # activate special handlers
+ for i in range(0, len(self.textfield_answer.handler_id)):
+ self.textfield_answer.handler_unblock(self.textfield_answer.handler_id[i])
+ # self.textfield_answer.handler_unblock_by_func(self.on_textfield_answer_insert_text)
+ self.textfield_answer.modify_cursor(self.cursor_color_train, self.cursor_color_train)
+ self.state = self.STATE_WRONG
+
+
+if __name__ == '__main__':
+ gtk_honeypot(False)
diff --git a/dist/Honeypot.activity/logger.logfile b/dist/Honeypot.activity/logger.logfile
new file mode 100644
index 0000000..ce675a9
--- /dev/null
+++ b/dist/Honeypot.activity/logger.logfile
@@ -0,0 +1,371 @@
+DEBUG:gtk_honeypot:self.window_child: <gtk.VBox object at 0x8e3198c (GtkVBox at 0x8edd400)>
+DEBUG:xml_honeypot:content_handler init
+DEBUG:xml_honeypot:DTD_handler init
+DEBUG:xml_honeypot:error_handler init
+DEBUG:xml_honeypot:element: honeypot, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4410c>
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: collection, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4428c>
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: drop, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4428c>
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: question, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4428c>
+DEBUG:xml_honeypot:content: 1 × 1
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: answer, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4422c>
+DEBUG:xml_honeypot:q/a: 1 × 1/1
+DEBUG:xml_honeypot:content: 1
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: drop, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4428c>
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: question, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4428c>
+DEBUG:xml_honeypot:content: [1-10] × [1-10]
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: answer, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4410c>
+DEBUG:xml_honeypot:q/a: [1-10] × [1-10]/{\1 * \2}
+DEBUG:xml_honeypot:content: {\1 * \2}
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: collection, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e442ac>
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: drop, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4426c>
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: question, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4426c>
+DEBUG:xml_honeypot:content: [1-10] + [1-10] * [1-20]
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: step, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e442cc>
+DEBUG:xml_honeypot:content: \1 + {\2 * \3}
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: answer, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e442cc>
+DEBUG:xml_honeypot:q/a: [1-10] + [1-10] * [1-20]/{\1 + \2 * \3}
+DEBUG:xml_honeypot:content: {\1 + \2 * \3}
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: drop, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e442ac>
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: question, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4422c>
+DEBUG:xml_honeypot:content: ([1-10] + [1-10]) * ({\4 + [1-10]} - [1-10])
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: way, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e442ac>
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: step, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4422c>
+DEBUG:xml_honeypot:content: {\1 + \2} * ({\4 + \3} - \4)
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: way, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e442ac>
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: step, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4422c>
+DEBUG:xml_honeypot:content: (\1 + \2) * \3
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: answer, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e442ac>
+DEBUG:xml_honeypot:q/a: ([1-10] + [1-10]) * ({\4 + [1-10]} - [1-10])/{(\1 + \2) * \3}
+DEBUG:xml_honeypot:content: {(\1 + \2) * \3}
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: collection, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4430c>
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: drop, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4420c>
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: question, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4420c>
+DEBUG:xml_honeypot:content: [1-20] + x = {\1 + [1-20]}
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: answer, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4426c>
+DEBUG:xml_honeypot:q/a: [1-20] + x = {\1 + [1-20]}/\2
+DEBUG:xml_honeypot:content: \2
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: drop, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4422c>
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: question, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4422c>
+DEBUG:xml_honeypot:content: x + [1-20] = {[1-40] + \1}
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: answer, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4410c>
+DEBUG:xml_honeypot:q/a: x + [1-20] = {[1-40] + \1}/\2
+DEBUG:xml_honeypot:content: \2
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: drop, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4420c>
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: question, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4420c>
+DEBUG:xml_honeypot:content: x - [1-20] = [1-20]
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: answer, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4432c>
+DEBUG:xml_honeypot:q/a: x - [1-20] = [1-20]/{\1 + \2}
+DEBUG:xml_honeypot:content: {\1 + \2}
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: drop, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4422c>
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: question, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4422c>
+DEBUG:xml_honeypot:content: [1-10] * x = {\1 * [1-10]}
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: answer, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4434c>
+DEBUG:xml_honeypot:q/a: [1-10] * x = {\1 * [1-10]}/\2
+DEBUG:xml_honeypot:content: \2
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: drop, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4420c>
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: question, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4420c>
+DEBUG:xml_honeypot:content: x * [1-10] = {\1 * [1-10]}
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: answer, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e442cc>
+DEBUG:xml_honeypot:q/a: x * [1-10] = {\1 * [1-10]}/\2
+DEBUG:xml_honeypot:content: \2
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: drop, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4422c>
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: question, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4422c>
+DEBUG:xml_honeypot:content: x : [1-10] = [1-10]
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: answer, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4438c>
+DEBUG:xml_honeypot:q/a: x : [1-10] = [1-10]/{\1 * \2}
+DEBUG:xml_honeypot:content: {\1 * \2}
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: drop, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4420c>
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: question, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4420c>
+DEBUG:xml_honeypot:content: ([11-20] * x) - [1-10] = {\1 * [1-20] - \2}
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: step, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4428c>
+DEBUG:xml_honeypot:content: ([11-20] * x) = {\1 * [1-20]}
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: step, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4428c>
+DEBUG:xml_honeypot:content: [11-20] * x = {\1 * [1-20]}
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: answer, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e443ac>
+DEBUG:xml_honeypot:q/a: ([11-20] * x) - [1-10] = {\1 * [1-20] - \2}/\3
+DEBUG:xml_honeypot:content: \3
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: collection, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e443cc>
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: drop, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4422c>
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: question, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4422c>
+DEBUG:xml_honeypot:content: an apple
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: answer, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e442ec>
+DEBUG:xml_honeypot:q/a: an apple/ein Apfel
+DEBUG:xml_honeypot:content: ein Apfel
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: drop, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4436c>
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: question, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4436c>
+DEBUG:xml_honeypot:content: a pea
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: answer, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4428c>
+DEBUG:xml_honeypot:q/a: a pea/eine Birne
+DEBUG:xml_honeypot:content: eine Birne
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: drop, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4422c>
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: question, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e4422c>
+DEBUG:xml_honeypot:content: a pineapple
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:element: answer, attributes: <xml.sax.xmlreader.AttributesImpl instance at 0x8e443ec>
+DEBUG:xml_honeypot:q/a: a pineapple/eine Ananas
+DEBUG:xml_honeypot:content: eine Ananas
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:content:
+DEBUG:xml_honeypot:content:
+
+DEBUG:xml_honeypot:end of xml document
+DEBUG:gtk_honeypot:random choice: [u'x - [1-20] = [1-20]', u'{\\1 + \\2}']
+DEBUG:mathparse:begin parse: x - [1-20] = [1-20]
+DEBUG:mathparse:split q1: [u'x - ', u'1', u'20', u' = ', u'1', u'20', u'']
+DEBUG:mathparse:7
+DEBUG:mathparse:q1[1]: [u'x - ', '17', '', u' = ', u'1', u'20', u'']
+DEBUG:mathparse:7
+DEBUG:mathparse:q1[4]: [u'x - ', '17', '', u' = ', '7', '', u'']
+DEBUG:mathparse:join q1: x - 17 = 7
+DEBUG:mathparse:split q2: [u'x - 17 = 7']
+DEBUG:mathparse:join q2: x - 17 = 7
+DEBUG:mathparse:split q3: [u'x - 17 = 7']
+DEBUG:mathparse:join q3: x - 17 = 7
+DEBUG:mathparse:split a1: x - 17 = 7
+DEBUG:mathparse:a1[1]: x - 17 = 7
+DEBUG:mathparse:a1[3]: x - 17 = 7
+DEBUG:mathparse:join a1: x - 17 = 7
+DEBUG:mathparse:split a2: x - 17 = 7
+DEBUG:mathparse:a2[1]: x - 17 = 7
+DEBUG:mathparse:join a2: x - 17 = 7
+DEBUG:gtk_honeypot:random choice: [u'([11-20] * x) - [1-10] = {\\1 * [1-20] - \\2}', u'\\3']
+DEBUG:mathparse:begin parse: ([11-20] * x) - [1-10] = {\1 * [1-20] - \2}
+DEBUG:mathparse:split q1: [u'(', u'11', u'20', u' * x) - ', u'1', u'10', u' = {\\1 * ', u'1', u'20', u' - \\2}']
+DEBUG:mathparse:10
+DEBUG:mathparse:q1[1]: [u'(', '18', '', u' * x) - ', u'1', u'10', u' = {\\1 * ', u'1', u'20', u' - \\2}']
+DEBUG:mathparse:10
+DEBUG:mathparse:q1[4]: [u'(', '18', '', u' * x) - ', '11', '', u' = {\\1 * ', u'1', u'20', u' - \\2}']
+DEBUG:mathparse:10
+DEBUG:mathparse:q1[7]: [u'(', '18', '', u' * x) - ', '11', '', u' = {\\1 * ', '14', '', u' - \\2}']
+DEBUG:mathparse:join q1: (18 * x) - 11 = {\1 * 14 - \2}
+DEBUG:mathparse:split q2: [u'(18 * x) - 11 = {', u'1', u' * 14 - ', u'2', u'}']
+DEBUG:mathparse:q2[1]: [u'(18 * x) - 11 = {', '18', u' * 14 - ', u'2', u'}']
+DEBUG:mathparse:q2[3]: [u'(18 * x) - 11 = {', '18', u' * 14 - ', '11', u'}']
+DEBUG:mathparse:join q2: (18 * x) - 11 = {18 * 14 - 11}
+DEBUG:mathparse:split q3: [u'(18 * x) - 11 = ', u'18 * 14 - 11', u'']
+DEBUG:mathparse:q3[1]: [u'(18 * x) - 11 = ', '241', u'']
+DEBUG:mathparse:join q3: (18 * x) - 11 = 241
+DEBUG:mathparse:split a1: (18 * x) - 11 = 241
+DEBUG:mathparse:a1[1]: (18 * x) - 11 = 241
+DEBUG:mathparse:join a1: (18 * x) - 11 = 241
+DEBUG:mathparse:split a2: (18 * x) - 11 = 241
+DEBUG:mathparse:join a2: (18 * x) - 11 = 241
diff --git a/dist/Honeypot.activity/mathparse_honeypot.py b/dist/Honeypot.activity/mathparse_honeypot.py
new file mode 100644
index 0000000..f8d5f2c
--- /dev/null
+++ b/dist/Honeypot.activity/mathparse_honeypot.py
@@ -0,0 +1,103 @@
+#!/usr/bin/env python
+#
+# Copyright (C) 2010, Johannes Ponader
+#
+# 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 2 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, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+import logging
+_logger = logging.getLogger('mathparse')
+_logger.setLevel(logging.DEBUG)
+
+import sys, random, time, re, ast, parser
+
+
+class mathparse_honeypot:
+
+ def __init__(self, runaslib=True):
+
+ # Seed the random number generator
+ random.seed(time.time())
+
+ def parse(self, drop):
+ question = drop[0]
+ answer = drop[1]
+
+ # look for "[1-10]" etc.
+ regexp = r"\[(\d+)-(\d+)]"
+ _logger.debug('begin parse: ' + str(question))
+ question = re.split(regexp, question)
+ _logger.debug('split q1: ' + str(question))
+ # "\1" stands for random_value[0]
+ random_values = []
+ for i in range(1, len(question), 3):
+ _logger.debug(len(question))
+ rand_val = str(random.randint(int(question[i]), int(question[i+1])+1))
+ random_values.append(rand_val)
+ question[i] = rand_val
+ question[i+1] = ""
+ _logger.debug('q1[' + str(i) + ']: ' + str(question))
+ # make it one string again
+ question = u"".join(question)
+ _logger.debug('join q1: ' + str(question))
+
+ # look for markers like "\1"
+ regexp = r"\\(\d+)"
+ question = re.split(regexp, question)
+ _logger.debug('split q2: ' + str(question))
+ for i in range(1, len(question), 2):
+ #no error/range checking so far
+ question[i] = random_values[int(question[i])-1]
+ _logger.debug('q2[' + str(i) + ']: ' + str(question))
+ question = u"".join(question)
+ _logger.debug('join q2: ' + str(question))
+
+ # look for expressions to evaluate: "{...}"
+ regexp = r"\{(.*)}"
+ question = re.split(regexp, question)
+ _logger.debug('split q3: ' + str(question))
+ for i in range(1, len(question), 2):
+ # Sicherheitsluecke!
+ # vgl. http://effbot.org/zone/librarybook-core-eval.htm
+ question[i] = str(eval(question[i]))
+ _logger.debug('q3[' + str(i) + ']: ' + str(question))
+ question = u"".join(question)
+ _logger.debug('join q3: ' + str(question))
+
+ regexp = r"\\(\d+)"
+ answer = re.split(regexp, answer)
+ _logger.debug('split a1: ' + str(question))
+ for i in range(1, len(answer), 2):
+ answer[i] = random_values[int(answer[i])-1]
+ _logger.debug('a1[' + str(i) + ']: ' + str(question))
+ answer = u"".join(answer)
+ _logger.debug('join a1: ' + str(question))
+
+ regexp = r"\{(.*)}"
+ answer = re.split(regexp, answer)
+ _logger.debug('split a2: ' + str(question))
+ for i in range(1, len(answer), 2):
+ answer[i] = str(eval(answer[i]))
+ # answer[i] = str(ast.literal_eval(ast.parse(answer[i])))
+ _logger.debug('a2[' + str(i) + ']: ' + str(question))
+ answer = u"".join(answer)
+ _logger.debug('join a2: ' + str(question))
+
+ return [question,answer]
+
+
+if __name__ == '__main__':
+ mathparse_honeypot(False)
+
+ \ No newline at end of file
diff --git a/dist/Honeypot.activity/mathparse_honeypot.pyo b/dist/Honeypot.activity/mathparse_honeypot.pyo
new file mode 100644
index 0000000..41a7236
--- /dev/null
+++ b/dist/Honeypot.activity/mathparse_honeypot.pyo
Binary files differ
diff --git a/dist/Honeypot.activity/my_first_questions.honeypot b/dist/Honeypot.activity/my_first_questions.honeypot
new file mode 100644
index 0000000..729e919
--- /dev/null
+++ b/dist/Honeypot.activity/my_first_questions.honeypot
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<honeypot>
+ <collection name="1x1" id="collection1" author_name="Johannes Ponader" language="de" subject_name="Mathematik" subject_id="000" topic_name="kleines Einmaleins" topic_id="101" author_id="001">
+ <drop id="000">
+ <question>1 × 1</question>
+ <answer>1</answer>
+ </drop>
+ <drop id="001" type="mathparse" version="1" differ="\1,\2">
+ <question>[1-10] × [1-10]</question>
+ <answer>{\1 * \2}</answer>
+ </drop>
+ </collection>
+ <collection name="Terme vereinfachen" id="collection2" author_name="Johannes Ponader" language="de" subject_name="Mathematik" subject_id="000" topic_name="Terme vereinfachen" topic_id="102" author_id="001">
+ <drop id="100" type="mathparse" version="1">
+ <question>[1-10] + [1-10] * [1-20]</question>
+ <step skip="forbidden">\1 + {\2 * \3}</step>
+ <answer>{\1 + \2 * \3}</answer>
+ </drop>
+ <drop id="101" type="mathparse" version="1">
+ <question>([1-10] + [1-10]) * ({\4 + [1-10]} - [1-10])</question>
+ <way>
+ <step>{\1 + \2} * ({\4 + \3} - \4)</step>
+ </way>
+ <way>
+ <step>(\1 + \2) * \3</step>
+ </way>
+ <answer>{(\1 + \2) * \3}</answer>
+ </drop>
+ </collection>
+ <collection name="Gleichungen aufloesen" id="collection3" author_name="Johannes Ponader" language="de" subject_name="Mathematik" subject_id="000" topic_name="Gleichungen Aufloesen" topic_id="103" author_id="001">
+ <!-- honeypot-id: author.index -->
+ <drop id="200" type="mathparse" version="1">
+ <question>[1-20] + x = {\1 + [1-20]}</question>
+ <answer>\2</answer>
+ </drop>
+ <drop id="201" type="mathparse" version="1">
+ <question>x + [1-20] = {[1-40] + \1}</question>
+ <answer>\2</answer>
+ </drop>
+ <drop id="202" type="mathparse" version="1">
+ <question>x - [1-20] = [1-20]</question>
+ <answer>{\1 + \2}</answer>
+ </drop>
+ <drop id="210" type="mathparse" version="1">
+ <question>[1-10] * x = {\1 * [1-10]}</question>
+ <answer>\2</answer>
+ </drop>
+ <drop id="211" type="mathparse" version="1">
+ <question>x * [1-10] = {\1 * [1-10]}</question>
+ <answer>\2</answer>
+ </drop>
+ <drop id="212" type="mathparse" version="1">
+ <question>x : [1-10] = [1-10]</question>
+ <answer>{\1 * \2}</answer>
+ </drop>
+ <drop id="220" type="mathparse" version="1">
+ <question>([11-20] * x) - [1-10] = {\1 * [1-20] - \2}</question>
+ <step skip="allowed">([11-20] * x) = {\1 * [1-20]}</step>
+ <step skip="allowed">[11-20] * x = {\1 * [1-20]}</step>
+ <answer>\3</answer>
+ </drop>
+ </collection>
+ <collection name="Learning English - Unit 1: Fruits" id="collection4" author_name="Johannes Ponader" language="en" subject_name="English" subject_id="001" topic_name="Learning English - Unit 1" topic_id="201" author_id="001">
+ <drop id="001" type="bidirectional" case="sensitive" blanks="loose">
+ <question>an apple</question>
+ <answer>ein Apfel</answer>
+ </drop>
+ <drop id="002" type="bidirectional" case="sensitive" blanks="loose">
+ <question>a pea</question>
+ <answer>eine Birne</answer>
+ </drop>
+ <drop id="003" type="bidirectional" case="sensitive" blanks="loose">
+ <question>a pineapple</question>
+ <answer>eine Ananas</answer>
+ </drop>
+ </collection>
+</honeypot>
diff --git a/dist/Honeypot.activity/xml_honeypot.py b/dist/Honeypot.activity/xml_honeypot.py
new file mode 100644
index 0000000..4c2647a
--- /dev/null
+++ b/dist/Honeypot.activity/xml_honeypot.py
@@ -0,0 +1,111 @@
+#!/usr/bin/env python
+#
+# Copyright (C) 2010, Johannes Ponader
+#
+# 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 2 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, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+import logging
+_logger = logging.getLogger('xml_honeypot')
+_logger.setLevel(logging.DEBUG)
+
+# we need to parse some xml files
+from xml.sax import saxutils, handler
+from xml.sax import make_parser
+from xml.sax.handler import feature_namespaces
+
+class content_handler(handler.ContentHandler):
+ def __init__(self):
+ _logger.debug("content_handler init")
+
+ def startDocument(self):
+ self.drops = []
+
+ def endDocument(self):
+ _logger.debug('end of xml document')
+
+ def startElement(self, name, attrs):
+ # we don't check for errors at the moment, and ignore many features
+ if name == 'question' or name == 'answer':
+ self.wait_for_characters = name
+ else:
+ self.wait_for_characters = False
+ _logger.debug("element: " + name + ", attributes: " + str(attrs))
+
+ def characters(self, content):
+ # it's a hack for now, i just take the first chunk of content, this might produce errors
+ if self.wait_for_characters == 'question':
+ self.question = content
+ self.wait_for_characters = ''
+ if self.wait_for_characters == 'answer':
+ self.answer = content
+ self.wait_for_characters = ''
+ self.drops.append([self.question, self.answer])
+ _logger.debug('q/a: ' + self.question + '/' + self.answer)
+
+ _logger.debug('content: ' + content)
+
+
+
+class DTD_handler(handler.DTDHandler):
+ def __init__(self):
+ _logger.debug("DTD_handler init")
+
+class error_handler(handler.ErrorHandler):
+ def __init__(self):
+ _logger.debug("error_handler init")
+
+ def warning(self, exception):
+ _logger.debug(exception)
+
+ def error(self, exception):
+ _logger.debug(exception)
+
+ def fatalError(self, exception):
+ _logger.debug(exception)
+
+
+
+class xml_honeypot:
+
+ def __init__(self, runaslib=True):
+
+ # see http://pyxml.sourceforge.net/topics/howto/node12.html
+
+ # Create a parser
+ self.parser = make_parser()
+
+ # Tell the parser we are not interested in XML namespaces
+ self.parser.setFeature(feature_namespaces, 0)
+
+ # Create the handler
+ self.content_handler = content_handler()
+ self.DTD_handler = DTD_handler()
+ self.error_handler = error_handler()
+
+ # Tell the parser to use our handler
+ self.parser.setContentHandler(self.content_handler)
+ self.parser.setDTDHandler(self.DTD_handler)
+ self.parser.setErrorHandler(self.error_handler)
+
+ def load_drops(self):
+
+ # Parse the input
+ self.xml_filename = 'my_first_questions.honeypot'
+ # xml_file = open(self.xml_filename, 'r')
+ self.parser.parse(self.xml_filename)
+
+if __name__ == '__main__':
+ xml_honeypot(False)
+
diff --git a/dist/Honeypot.activity/xml_honeypot.pyo b/dist/Honeypot.activity/xml_honeypot.pyo
new file mode 100644
index 0000000..ae8413f
--- /dev/null
+++ b/dist/Honeypot.activity/xml_honeypot.pyo
Binary files differ