From b844ff54e2908405e91636ccf72d2c1279216cf9 Mon Sep 17 00:00:00 2001 From: cixosfia Date: Sat, 24 Oct 2009 17:20:41 +0000 Subject: New project --- diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..a817f22 --- /dev/null +++ b/COPYING @@ -0,0 +1,20 @@ +Copyright (c) 2007-9, Playful Invention Company, Sugar Labs + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + diff --git a/CixosActivity.py b/CixosActivity.py new file mode 100644 index 0000000..f586eeb --- /dev/null +++ b/CixosActivity.py @@ -0,0 +1,171 @@ +# -*- coding: utf-8 -*- +#Copyright (c) 2009, Walter Bender +#Copyright (c) 2009, Cixos-Fia + +#Permission is hereby granted, free of charge, to any person obtaining a copy +#of this software and associated documentation files (the "Software"), to deal +#in the Software without restriction, including without limitation the rights +#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +#copies of the Software, and to permit persons to whom the Software is +#furnished to do so, subject to the following conditions: + +#The above copyright notice and this permission notice shall be included in +#all copies or substantial portions of the Software. + +#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +#THE SOFTWARE. + +import pygtk +pygtk.require('2.0') +import gtk +import gobject + +import sugar +from sugar.activity import activity +try: # 0.86+ toolbar widgets + from sugar.bundle.activitybundle import ActivityBundle + from sugar.activity.widgets import ActivityToolbarButton + from sugar.activity.widgets import StopButton + from sugar.graphics.toolbarbox import ToolbarBox + from sugar.graphics.toolbarbox import ToolbarButton +except ImportError: + pass +from sugar.graphics.toolbutton import ToolButton +from sugar.graphics.menuitem import MenuItem +from sugar.graphics.icon import Icon +from sugar.datastore import datastore + +from gettext import gettext as _ +import locale +import os.path + +import logging +_logger = logging.getLogger("cixos-activity") + +from sprites import * +import window + +# +# Sugar activity +# +class CixosActivity(activity.Activity): + + def __init__(self, handle): + super(CixosActivity,self).__init__(handle) + + try: + # Use 0.86 toolbar design + toolbar_box = ToolbarBox() + + # Buttons added to the Activity toolbar + activity_button = ActivityToolbarButton(self) + toolbar_box.toolbar.insert(activity_button, 0) + activity_button.show() + + # Label for showing status + self.results_label = gtk.Label("anything you want as a label") + self.results_label.show() + results_toolitem = gtk.ToolItem() + results_toolitem.add(self.results_label) + toolbar_box.toolbar.insert(results_toolitem,-1) + + separator = gtk.SeparatorToolItem() + separator.props.draw = False + separator.set_expand(True) + separator.show() + toolbar_box.toolbar.insert(separator, -1) + + # The ever-present Stop Button + stop_button = StopButton(self) + stop_button.props.accelerator = 'Q' + toolbar_box.toolbar.insert(stop_button, -1) + stop_button.show() + + self.set_toolbar_box(toolbar_box) + toolbar_box.show() + + except NameError: + # Use pre-0.86 toolbar design + self.toolbox = activity.ActivityToolbox(self) + self.set_toolbox(self.toolbox) + + self.projectToolbar = ProjectToolbar(self) + self.toolbox.add_toolbar( _('Project'), self.projectToolbar ) + + self.toolbox.show() + + # Create a canvas + canvas = gtk.DrawingArea() + canvas.set_size_request(gtk.gdk.screen_width(), \ + gtk.gdk.screen_height()) + self.set_canvas(canvas) + canvas.show() + self.show_all() + + # Initialize the canvas + self.tw = window.new_window(canvas, \ + os.path.join(activity.get_bundle_path(), \ + 'images/'), \ + self) + # Read the dpi from the Journal + try: + cardx = self.metadata['card-x-offsets'].replace("[","").replace("]","").split(", ") + cardl = self.metadata['card-layers'].replace("[","").replace("]","").split(", ") + numberx = self.metadata['number-x-offsets'].replace("[","").replace("]","").split(", ") + numberl = self.metadata['number-layers'].replace("[","").replace("]","").split(", ") + j = 0 + for i in self.tw.cards: + move(i.spr,(int(cardx[j]),i.spr.y)) + setlayer(i.spr,int(cardl[j])) + draw(i.spr) + j += 1 + j = 0 + for i in self.tw.numbers: + move(i.spr,(int(numberx[j]),i.spr.y)) + setlayer(i.spr,int(numberl[j])) + draw(i.spr) + j += 1 + except: + pass + + """ + Write the slider positions to the Journal + """ + + def write_file(self, file_path): + cardx = [] + cardl = [] + numberx = [] + numberl = [] + for i in self.tw.cards: + cardx.append(i.spr.x) + cardl.append(i.spr.layer) + for i in self.tw.numbers: + numberx.append(i.spr.x) + numberl.append(i.spr.layer) + self.metadata['card-x-offsets'] = str(cardx) + self.metadata['card-layers'] = str(cardl) + self.metadata['number-x-offsets'] = str(numberx) + self.metadata['number-layers'] = str(numberl) + +# +# Project toolbar for pre-0.86 toolbars +# +class ProjectToolbar(gtk.Toolbar): + + def __init__(self, pc): + gtk.Toolbar.__init__(self) + self.activity = pc + + # Label for showing status + self.activity.results_label = gtk.Label( _("some label text here")) + self.activity.results_label.show() + self.activity.results_toolitem = gtk.ToolItem() + self.activity.results_toolitem.add(self.activity.results_label) + self.insert(self.activity.results_toolitem, -1) + self.activity.results_toolitem.show() diff --git a/CixosActivity.pyc b/CixosActivity.pyc new file mode 100644 index 0000000..46ad42b --- /dev/null +++ b/CixosActivity.pyc Binary files differ diff --git a/CixosActivity.py~ b/CixosActivity.py~ new file mode 100644 index 0000000..9f765cd --- /dev/null +++ b/CixosActivity.py~ @@ -0,0 +1,156 @@ +# -*- coding: utf-8 -*- +#Copyright (c) 2009, Walter Bender + +#Permission is hereby granted, free of charge, to any person obtaining a copy +#of this software and associated documentation files (the "Software"), to deal +#in the Software without restriction, including without limitation the rights +#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +#copies of the Software, and to permit persons to whom the Software is +#furnished to do so, subject to the following conditions: + +#The above copyright notice and this permission notice shall be included in +#all copies or substantial portions of the Software. + +#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +#THE SOFTWARE. + +import pygtk +pygtk.require('2.0') +import gtk +import gobject + +import sugar +from sugar.activity import activity +try: # 0.86+ toolbar widgets + from sugar.bundle.activitybundle import ActivityBundle + from sugar.activity.widgets import ActivityToolbarButton + from sugar.activity.widgets import StopButton + from sugar.graphics.toolbarbox import ToolbarBox + from sugar.graphics.toolbarbox import ToolbarButton +except ImportError: + pass +from sugar.graphics.toolbutton import ToolButton +from sugar.graphics.menuitem import MenuItem +from sugar.graphics.icon import Icon +from sugar.datastore import datastore + +from gettext import gettext as _ +import locale +import os.path + +import logging +_logger = logging.getLogger("cixos-activity") + +from sprites import * +import window + +# +# Sugar activity +# +class CixosActivity(activity.Activity): + + def __init__(self, handle): + super(CixosActivity,self).__init__(handle) + + try: + # Use 0.86 toolbar design + toolbar_box = ToolbarBox() + + # Buttons added to the Activity toolbar + activity_button = ActivityToolbarButton(self) + toolbar_box.toolbar.insert(activity_button, 0) + activity_button.show() + + # Label for showing status + self.results_label = gtk.Label("anything you want as a label") + self.results_label.show() + results_toolitem = gtk.ToolItem() + results_toolitem.add(self.results_label) + toolbar_box.toolbar.insert(results_toolitem,-1) + + separator = gtk.SeparatorToolItem() + separator.props.draw = False + separator.set_expand(True) + separator.show() + toolbar_box.toolbar.insert(separator, -1) + + # The ever-present Stop Button + stop_button = StopButton(self) + stop_button.props.accelerator = 'Q' + toolbar_box.toolbar.insert(stop_button, -1) + stop_button.show() + + self.set_toolbar_box(toolbar_box) + toolbar_box.show() + + except NameError: + # Use pre-0.86 toolbar design + self.toolbox = activity.ActivityToolbox(self) + self.set_toolbox(self.toolbox) + + self.projectToolbar = ProjectToolbar(self) + self.toolbox.add_toolbar( _('Project'), self.projectToolbar ) + + self.toolbox.show() + + # Create a canvas + canvas = gtk.DrawingArea() + canvas.set_size_request(gtk.gdk.screen_width(), \ + gtk.gdk.screen_height()) + self.set_canvas(canvas) + canvas.show() + self.show_all() + + # Initialize the canvas + self.tw = window.new_window(canvas, \ + os.path.join(activity.get_bundle_path(), \ + 'images/'), \ + self) + """ + # Read the dpi from the Journal + try: + self.tw.C.spr.x = int(self.metadata['C']) + self.tw.C_tab.spr.x = int(self.metadata['C']) + self.tw.D.spr.x = int(self.metadata['D']) + self.tw.R.spr.x = int(self.metadata['R']) + self.tw.R_tab_top.spr.x = int(self.metadata['R']) + self.tw.R_tab_bot.spr.x = int(self.metadata['R']) + window.update_label(self.tw) + except: + pass + """ + + """ + Write the slider positions to the Journal + """ + """ + def write_file(self, file_path): + _logger.debug("Write C offset: " + str(self.tw.C.spr.x)) + self.metadata['C'] = str(self.tw.C.spr.x) + _logger.debug("Write D offset: " + str(self.tw.D.spr.x)) + self.metadata['D'] = str(self.tw.D.spr.x) + _logger.debug("Write r offset: " + str(self.tw.R.spr.x)) + self.metadata['R'] = str(self.tw.R.spr.x) + """ + +# +# Project toolbar for pre-0.86 toolbars +# +class ProjectToolbar(gtk.Toolbar): + + def __init__(self, pc): + gtk.Toolbar.__init__(self) + self.activity = pc + + # Label for showing status + self.activity.results_label = gtk.Label( _("some label text here")) + self.activity.results_label.show() + self.activity.results_toolitem = gtk.ToolItem() + self.activity.results_toolitem.add(self.activity.results_label) + self.insert(self.activity.results_toolitem, -1) + self.activity.results_toolitem.show() diff --git a/NEWS b/NEWS new file mode 100644 index 0000000..6b2d1a8 --- /dev/null +++ b/NEWS @@ -0,0 +1,5 @@ +1 + +* Cixos FIA Card game version 1 + + diff --git a/NEWS~ b/NEWS~ new file mode 100644 index 0000000..2f52ccc --- /dev/null +++ b/NEWS~ @@ -0,0 +1,11 @@ +2 + +* Save position in Journal +* Restore position from Journal +* Larger handles on reticule + +1 + +* Sliderule activity +* C and D ln scales for multiplication and division + diff --git a/activity/activity-cixos.svg b/activity/activity-cixos.svg new file mode 100644 index 0000000..7fa38e5 --- /dev/null +++ b/activity/activity-cixos.svg @@ -0,0 +1,70 @@ + + + +]> + + + + + + + + + + + diff --git a/activity/activity.info b/activity/activity.info new file mode 100644 index 0000000..2dab26d --- /dev/null +++ b/activity/activity.info @@ -0,0 +1,8 @@ +[Activity] +name = Cixos +activity_version = 1 +license = GPLv3 +bundle_id = org.cixos.CixosActivity +exec = sugar-activity CixosActivity.CixosActivity +icon = activity-cixos +show_launcher = yes diff --git a/activity/activity.info~ b/activity/activity.info~ new file mode 100644 index 0000000..b98ad96 --- /dev/null +++ b/activity/activity.info~ @@ -0,0 +1,8 @@ +[Activity] +name = Cixos +activity_version = 2 +license = GPLv3 +bundle_id = org.cixos.CixosActivity +exec = sugar-activity CixosActivity.CixosActivity +icon = activity-cixos +show_launcher = yes diff --git a/constants.py b/constants.py new file mode 100644 index 0000000..5e7b825 --- /dev/null +++ b/constants.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +#Copyright (c) 2009, Walter Bender + +#Permission is hereby granted, free of charge, to any person obtaining a copy +#of this software and associated documentation files (the "Software"), to deal +#in the Software without restriction, including without limitation the rights +#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +#copies of the Software, and to permit persons to whom the Software is +#furnished to do so, subject to the following conditions: + +#The above copyright notice and this permission notice shall be included in +#all copies or substantial portions of the Software. + +#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +#THE SOFTWARE. + +OFFSET = 50 +SCALE = 1000. +SWIDTH = 2400 +SHEIGHT = 60 diff --git a/constants.pyc b/constants.pyc new file mode 100644 index 0000000..ac04bb2 --- /dev/null +++ b/constants.pyc Binary files differ diff --git a/icons/blank-in.svg b/icons/blank-in.svg new file mode 100644 index 0000000..9310287 --- /dev/null +++ b/icons/blank-in.svg @@ -0,0 +1,83 @@ + + + + + + + + + + + + + + + + diff --git a/icons/blank-out.svg b/icons/blank-out.svg new file mode 100644 index 0000000..2db258b --- /dev/null +++ b/icons/blank-out.svg @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + diff --git a/icons/buxton.svg b/icons/buxton.svg new file mode 100644 index 0000000..b54b1d1 --- /dev/null +++ b/icons/buxton.svg @@ -0,0 +1,148 @@ + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + Complexity + Time + God's Law + Buxton's Law + + diff --git a/images/C.svg b/images/C.svg new file mode 100644 index 0000000..e1d9c63 --- /dev/null +++ b/images/C.svg @@ -0,0 +1,1167 @@ + + + + + + + C + + 1.0 + + + + + + + + + + + + 1.1 + + + + + + + + + + + + 1.2 + + + + + + + + + + + + 1.3 + + + + + + + + + + + + 1.4 + + + + + + + + + + + + 1.5 + + + + + + + + + + + + 1.6 + + + + + + + + + + + + 1.7 + + + + + + + + + + + + 1.8 + + + + + + + + + + + + 1.9 + + + + + + + + + + + + 2.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 3.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 4.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5.0 + + + + + + + + + + + + + + + + + + + + + + 6.0 + + + + + + + + + + + + + + + + + + + + + + 7.0 + + + + + + + + + + + + + + + + + + + + + + 8.0 + + + + + + + + + + + + + + + + + + + + + + 9.0 + + + + + + + + + + + + + + + + + + + + + + 10.0 + + + diff --git a/images/Carta1.JPG b/images/Carta1.JPG new file mode 100755 index 0000000..de918dd --- /dev/null +++ b/images/Carta1.JPG Binary files differ diff --git a/images/Carta2.JPG b/images/Carta2.JPG new file mode 100755 index 0000000..7c9f40e --- /dev/null +++ b/images/Carta2.JPG Binary files differ diff --git a/images/Carta3.JPG b/images/Carta3.JPG new file mode 100755 index 0000000..05bdf0d --- /dev/null +++ b/images/Carta3.JPG Binary files differ diff --git a/images/CartaChichen.JPG b/images/CartaChichen.JPG new file mode 100755 index 0000000..83d2cf3 --- /dev/null +++ b/images/CartaChichen.JPG Binary files differ diff --git a/images/CartaColiseo.JPG b/images/CartaColiseo.JPG new file mode 100755 index 0000000..4e89624 --- /dev/null +++ b/images/CartaColiseo.JPG Binary files differ diff --git a/images/CartaCristo.JPG b/images/CartaCristo.JPG new file mode 100755 index 0000000..8ba8655 --- /dev/null +++ b/images/CartaCristo.JPG Binary files differ diff --git a/images/CartaGranMuralla.JPG b/images/CartaGranMuralla.JPG new file mode 100755 index 0000000..2ab325c --- /dev/null +++ b/images/CartaGranMuralla.JPG Binary files differ diff --git a/images/CartaMacchu.JPG b/images/CartaMacchu.JPG new file mode 100755 index 0000000..574eec9 --- /dev/null +++ b/images/CartaMacchu.JPG Binary files differ diff --git a/images/CartaPetra.JPG b/images/CartaPetra.JPG new file mode 100755 index 0000000..c3bf0ac --- /dev/null +++ b/images/CartaPetra.JPG Binary files differ diff --git a/images/CartaTaj.JPG b/images/CartaTaj.JPG new file mode 100755 index 0000000..6fb6f44 --- /dev/null +++ b/images/CartaTaj.JPG Binary files differ diff --git a/images/Cartavacia.JPG b/images/Cartavacia.JPG new file mode 100755 index 0000000..67112d4 --- /dev/null +++ b/images/Cartavacia.JPG Binary files differ diff --git a/images/Correcto.JPG b/images/Correcto.JPG new file mode 100755 index 0000000..8acf1bf --- /dev/null +++ b/images/Correcto.JPG Binary files differ diff --git a/images/Cursor.JPG b/images/Cursor.JPG new file mode 100755 index 0000000..8b77334 --- /dev/null +++ b/images/Cursor.JPG Binary files differ diff --git a/images/D.svg b/images/D.svg new file mode 100644 index 0000000..8614a9f --- /dev/null +++ b/images/D.svg @@ -0,0 +1,1167 @@ + + + + + + + D + + 1.0 + + + + + + + + + + + + 1.1 + + + + + + + + + + + + 1.2 + + + + + + + + + + + + 1.3 + + + + + + + + + + + + 1.4 + + + + + + + + + + + + 1.5 + + + + + + + + + + + + 1.6 + + + + + + + + + + + + 1.7 + + + + + + + + + + + + 1.8 + + + + + + + + + + + + 1.9 + + + + + + + + + + + + 2.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 3.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 4.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5.0 + + + + + + + + + + + + + + + + + + + + + + 6.0 + + + + + + + + + + + + + + + + + + + + + + 7.0 + + + + + + + + + + + + + + + + + + + + + + 8.0 + + + + + + + + + + + + + + + + + + + + + + 9.0 + + + + + + + + + + + + + + + + + + + + + + 10.0 + + + diff --git a/images/Elige.JPG b/images/Elige.JPG new file mode 100755 index 0000000..e3de268 --- /dev/null +++ b/images/Elige.JPG Binary files differ diff --git a/images/Estrella.JPG b/images/Estrella.JPG new file mode 100755 index 0000000..17a993c --- /dev/null +++ b/images/Estrella.JPG Binary files differ diff --git a/images/Ganaste2.JPG b/images/Ganaste2.JPG new file mode 100755 index 0000000..3109592 --- /dev/null +++ b/images/Ganaste2.JPG Binary files differ diff --git a/images/Ganaste4.JPG b/images/Ganaste4.JPG new file mode 100755 index 0000000..6421219 --- /dev/null +++ b/images/Ganaste4.JPG Binary files differ diff --git a/images/Intenta.JPG b/images/Intenta.JPG new file mode 100755 index 0000000..7bdc1ff --- /dev/null +++ b/images/Intenta.JPG Binary files differ diff --git a/images/Jugando.JPG b/images/Jugando.JPG new file mode 100755 index 0000000..b17fb12 --- /dev/null +++ b/images/Jugando.JPG Binary files differ diff --git a/images/Niño pekeño.JPG b/images/Niño pekeño.JPG new file mode 100755 index 0000000..ba2fcae --- /dev/null +++ b/images/Niño pekeño.JPG Binary files differ diff --git a/images/Niño.JPG b/images/Niño.JPG new file mode 100755 index 0000000..2e32aed --- /dev/null +++ b/images/Niño.JPG Binary files differ diff --git a/images/Perdiste.JPG b/images/Perdiste.JPG new file mode 100755 index 0000000..e35cd60 --- /dev/null +++ b/images/Perdiste.JPG Binary files differ diff --git a/images/Thumbs.db b/images/Thumbs.db new file mode 100755 index 0000000..8077544 --- /dev/null +++ b/images/Thumbs.db Binary files differ diff --git a/images/Vidamas.JPG b/images/Vidamas.JPG new file mode 100755 index 0000000..06751a2 --- /dev/null +++ b/images/Vidamas.JPG Binary files differ diff --git a/images/Vidamax.JPG b/images/Vidamax.JPG new file mode 100755 index 0000000..3de152d --- /dev/null +++ b/images/Vidamax.JPG Binary files differ diff --git a/images/azul.png b/images/azul.png new file mode 100755 index 0000000..b1308d2 --- /dev/null +++ b/images/azul.png Binary files differ diff --git a/images/check.JPG b/images/check.JPG new file mode 100755 index 0000000..5998e2f --- /dev/null +++ b/images/check.JPG Binary files differ diff --git a/images/diceVoid.png b/images/diceVoid.png new file mode 100755 index 0000000..74a4777 --- /dev/null +++ b/images/diceVoid.png Binary files differ diff --git a/images/fondo.jpg b/images/fondo.jpg new file mode 100755 index 0000000..4d1e249 --- /dev/null +++ b/images/fondo.jpg Binary files differ diff --git a/images/reticule.svg b/images/reticule.svg new file mode 100644 index 0000000..0efd98d --- /dev/null +++ b/images/reticule.svg @@ -0,0 +1,15 @@ + + + + + + diff --git a/images/tab.svg b/images/tab.svg new file mode 100644 index 0000000..9d183cf --- /dev/null +++ b/images/tab.svg @@ -0,0 +1,18 @@ + + + + + + diff --git a/images/tux.png b/images/tux.png new file mode 100755 index 0000000..f9f633f --- /dev/null +++ b/images/tux.png Binary files differ diff --git a/images/x1.JPG b/images/x1.JPG new file mode 100755 index 0000000..7e316f8 --- /dev/null +++ b/images/x1.JPG Binary files differ diff --git a/images/x2.JPG b/images/x2.JPG new file mode 100755 index 0000000..f951b5e --- /dev/null +++ b/images/x2.JPG Binary files differ diff --git a/po/Sliderule.pot b/po/Sliderule.pot new file mode 100644 index 0000000..ab9072f --- /dev/null +++ b/po/Sliderule.pot @@ -0,0 +1,55 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2009-10-21 08:52+0000\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#: activity/activity.info:2 +msgid "Sliderule" +msgstr "" + +#: /home/walter/Desktop/sliderule/SlideruleActivity.py:94 +msgid "Project" +msgstr "" + +#: /home/walter/Desktop/sliderule/SlideruleActivity.py:124 +msgid "D = 1 C = 1 DxC = 1 " +msgstr "" + +#: /home/walter/Desktop/sliderule/sliderule.py:43 +#: /home/walter/Desktop/sliderule/sliderule.py:156 +msgid "CardSort" +msgstr "" + +#: /home/walter/Desktop/sliderule/sliderule.py:44 +msgid "click to rotate; drag to swap" +msgstr "" + +#: /home/walter/Desktop/sliderule/sliderule.py:48 +msgid "Toggle blank card" +msgstr "" + +#: /home/walter/Desktop/sliderule/sliderule.py:51 +msgid "Apply rotation sets" +msgstr "" + +#: /home/walter/Desktop/sliderule/sliderule.py:54 +msgid "Solve it" +msgstr "" + +#: /home/walter/Desktop/sliderule/sliderule.py:153 +#: /home/walter/Desktop/sliderule/sliderule.py:157 +msgid "You solved the puzzle." +msgstr "" diff --git a/setup.py b/setup.py new file mode 100755 index 0000000..bd1e319 --- /dev/null +++ b/setup.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python +from sugar.activity import bundlebuilder +if __name__ == "__main__": + bundlebuilder.start() + diff --git a/sprite_factory.py b/sprite_factory.py new file mode 100644 index 0000000..758ac05 --- /dev/null +++ b/sprite_factory.py @@ -0,0 +1,65 @@ +#Copyright (c) 2009, Walter Bender + +#Permission is hereby granted, free of charge, to any person obtaining a copy +#of this software and associated documentation files (the "Software"), to deal +#in the Software without restriction, including without limitation the rights +#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +#copies of the Software, and to permit persons to whom the Software is +#furnished to do so, subject to the following conditions: + +#The above copyright notice and this permission notice shall be included in +#all copies or substantial portions of the Software. + +#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +#THE SOFTWARE. + +import pygtk +pygtk.require('2.0') +import gtk +import gobject +import os.path + +from sprites import * + +# +# class for defining individual cards +# +class Sprite: + def __init__(self, tw, name, x, y, w, h, name_label=True): + # create sprite from svg file + self.spr = sprNew(tw, x, y, + self.load_image(tw.path,name,w,h)) + if name_label is True: + self.spr.label = name + else: + self.spr.label = "" + + def draw_slider_bottom(self): + setlayer(self.spr,1000) + draw(self.spr) + + def draw_slider_middle(self): + setlayer(self.spr,1500) + draw(self.spr) + + def draw_slider_top(self): + setlayer(self.spr,2000) + draw(self.spr) + + def load_image(self, file, name, w, h): + try: + return gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(file + + name + + '.JPG'), + w, h) + except: + return gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(file + + name + + '.svg'), + w, h) + diff --git a/sprite_factory.pyc b/sprite_factory.pyc new file mode 100644 index 0000000..e1cc078 --- /dev/null +++ b/sprite_factory.pyc Binary files differ diff --git a/sprite_factory.py~ b/sprite_factory.py~ new file mode 100644 index 0000000..70916ab --- /dev/null +++ b/sprite_factory.py~ @@ -0,0 +1,54 @@ +#Copyright (c) 2009, Walter Bender + +#Permission is hereby granted, free of charge, to any person obtaining a copy +#of this software and associated documentation files (the "Software"), to deal +#in the Software without restriction, including without limitation the rights +#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +#copies of the Software, and to permit persons to whom the Software is +#furnished to do so, subject to the following conditions: + +#The above copyright notice and this permission notice shall be included in +#all copies or substantial portions of the Software. + +#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +#THE SOFTWARE. + +import pygtk +pygtk.require('2.0') +import gtk +import gobject +import os.path + +from sprites import * + +# +# class for defining individual cards +# +class Sprite: + def __init__(self, tw, name, x, y, w, h, name_label=True): + # create sprite from svg file + self.spr = sprNew(tw, x, y, + self.load_image(tw.path,name,w,h)) + if name_label is True: + self.spr.label = name + else: + self.spr.label = "" + + def draw_slider_bottom(self): + setlayer(self.spr,1000) + draw(self.spr) + def draw_slider_top(self): + setlayer(self.spr,2000) + draw(self.spr) + + def load_image(self, file, name, w, h): + return gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(file + + name + + '.JPG'), + w, h) + diff --git a/sprites.py b/sprites.py new file mode 100644 index 0000000..909ad3e --- /dev/null +++ b/sprites.py @@ -0,0 +1,152 @@ +# -*- coding: utf-8 -*- + +#Copyright (c) 2007-8, Playful Invention Company. +#Copyright (c) 2008-9, Walter Bender + +#Permission is hereby granted, free of charge, to any person obtaining a copy +#of this software and associated documentation files (the "Software"), to deal +#in the Software without restriction, including without limitation the rights +#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +#copies of the Software, and to permit persons to whom the Software is +#furnished to do so, subject to the following conditions: + +#The above copyright notice and this permission notice shall be included in +#all copies or substantial portions of the Software. + +#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +#THE SOFTWARE. + +import pygtk +pygtk.require('2.0') +import gtk +import gobject +import pango +class taSprite: pass + +def findsprite(tw,pos): + list = tw.sprites[:] + list.reverse() + for s in list: + if hit(s,pos): return s + return None + +def redrawsprites(tw): + for s in tw.sprites: draw(s) + +def sprNew(tw,x,y,image,altlabel=False): + spr = taSprite() + spr.tw, spr.x, spr.y = tw,x,y + setimage(spr,image) + spr.label = None + spr.ds_id = None + if altlabel: + spr.draw_label = draw_label2 + else: spr.draw_label = draw_label1 + return spr + +def setimage(spr,image): + spr.image = image + if isinstance(image,gtk.gdk.Pixbuf): + spr.width = image.get_width() + spr.height = image.get_height() + else: spr.width,spr.height=image.get_size() + +def move(spr,pos): + inval(spr) + spr.x,spr.y = pos + inval(spr) + +def setshape(spr,image): + inval(spr) + setimage(spr,image) + inval(spr) + +def setshapex(spr): + inval(spr) + +def setlayer(spr, layer): + sprites = spr.tw.sprites + if spr in sprites: sprites.remove(spr) + spr.layer = layer + for i in range(len(sprites)): + if layer < sprites[i].layer: + sprites.insert(i, spr) + inval(spr) + return + sprites.append(spr) + inval(spr) + +def hide(spr): + if spr not in spr.tw.sprites: return + inval(spr) + spr.tw.sprites.remove(spr) + +def setlabel(spr,label): + spr.label = label + inval(spr) + +def inval(spr): + spr.tw.area.invalidate_rect(gtk.gdk.Rectangle(spr.x,spr.y,spr.width, \ + spr.height), False) + +def draw(spr): + if isinstance(spr.image,gtk.gdk.Pixbuf): + spr.tw.area.draw_pixbuf(spr.tw.gc, spr.image, 0, 0, spr.x, spr.y) + else: + spr.tw.area.draw_drawable(spr.tw.gc,spr.image,0,0,spr.x,spr.y,-1,-1) + if spr.label!=None: + if hasattr(spr, 'proto') and hasattr(spr.proto, 'name'): + name = spr.proto.name + else: + name = "" + spr.draw_label(spr,str(spr.label)) + +def hit(spr,pos): + x,y = pos + if xspr.x+spr.width-1: return False + if yspr.y+spr.height-1: return False + return True + +def draw_label(spr, label, myscale, center_flag="False", vert_pos="middle"): + fd = pango.FontDescription('Sans') + fd.set_size(int(myscale*spr.tw.scale*pango.SCALE)) + if type(label) == str or type(label) == unicode: + mylabel = label.replace("\0"," ") + l = len(mylabel) + pl = spr.tw.canvas.create_pango_layout(mylabel) + pl.set_font_description(fd) + if center_flag: + swidth = pl.get_size()[0]/pango.SCALE + centerx = spr.x+spr.width/2 + x = int(centerx-swidth/2) + else: + x = spr.x+4 # small offset from left edge + sheight = pl.get_size()[1]/pango.SCALE + centery = spr.y+spr.height/2 + if vert_pos == "middle": + y = int(centery-sheight/2) + elif vert_pos == "top": + y = int(sheight/2) + elif vert_pos == "bottom": + y = int(spr.height-sheight) + spr.tw.gc.set_foreground(spr.tw.msgcolor) + spr.tw.area.draw_layout(spr.tw.gc, x, y, pl) + else: + print type(label) + +# used for sliders +def draw_label1(spr, label): + draw_label(spr, label, 12, True, "middle") + +def draw_label2(spr, label): + draw_label(spr, str(label), 14, True, "top") + +def draw_label3(spr, label): + draw_label(spr, str(label), 14, True, "bottom") diff --git a/sprites.pyc b/sprites.pyc new file mode 100644 index 0000000..69525b7 --- /dev/null +++ b/sprites.pyc Binary files differ diff --git a/sprites.py~ b/sprites.py~ new file mode 100644 index 0000000..b702eb4 --- /dev/null +++ b/sprites.py~ @@ -0,0 +1,165 @@ +# -*- coding: utf-8 -*- + +#Copyright (c) 2007-8, Playful Invention Company. +#Copyright (c) 2008-9, Walter Bender + +#Permission is hereby granted, free of charge, to any person obtaining a copy +#of this software and associated documentation files (the "Software"), to deal +#in the Software without restriction, including without limitation the rights +#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +#copies of the Software, and to permit persons to whom the Software is +#furnished to do so, subject to the following conditions: + +#The above copyright notice and this permission notice shall be included in +#all copies or substantial portions of the Software. + +#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +#THE SOFTWARE. + +import pygtk +pygtk.require('2.0') +import gtk +import gobject +import pango +class taSprite: pass + +def findsprite(tw,pos): + list = tw.sprites[:] + list.reverse() + for s in list: + if hit(s,pos): return s + return None + +def redrawsprites(tw): + for s in tw.sprites: draw(s) + +def sprNew(tw,x,y,image,altlabel=False): + spr = taSprite() + spr.tw, spr.x, spr.y = tw,x,y + setimage(spr,image) + spr.label = None + spr.ds_id = None + if altlabel: + spr.draw_label = draw_label2 + else: spr.draw_label = draw_label1 + return spr + +def setimage(spr,image): + spr.image = image + if isinstance(image,gtk.gdk.Pixbuf): + spr.width = image.get_width() + spr.height = image.get_height() + else: spr.width,spr.height=image.get_size() + +def move(spr,pos): + inval(spr) + spr.x,spr.y = pos + inval(spr) + +def setshape(spr,image): + inval(spr) + setimage(spr,image) + inval(spr) + +def setshapex(spr): + inval(spr) + +def setlayer(spr, layer): + sprites = spr.tw.sprites + if spr in sprites: sprites.remove(spr) + spr.layer = layer + for i in range(len(sprites)): + if layer < sprites[i].layer: + sprites.insert(i, spr) + inval(spr) + return + sprites.append(spr) + inval(spr) + +def hide(spr): + if spr not in spr.tw.sprites: return + inval(spr) + spr.tw.sprites.remove(spr) + +def setlabel(spr,label): + spr.label = label + inval(spr) + +def inval(spr): + spr.tw.area.invalidate_rect(gtk.gdk.Rectangle(spr.x,spr.y,spr.width, \ + spr.height), False) + +def draw(spr): + if isinstance(spr.image,gtk.gdk.Pixbuf): + spr.tw.area.draw_pixbuf(spr.tw.gc, spr.image, 0, 0, spr.x, spr.y) + else: + spr.tw.area.draw_drawable(spr.tw.gc,spr.image,0,0,spr.x,spr.y,-1,-1) + if spr.label!=None: + if hasattr(spr, 'proto') and hasattr(spr.proto, 'name'): + name = spr.proto.name + else: + name = "" + spr.draw_label(spr,str(spr.label)) + +def hit(spr,pos): + x,y = pos + if xspr.x+spr.width: return False + if yspr.y+spr.height-1: return False + if isinstance(spr.image,gtk.gdk.Pixmap): return True + if hasattr(spr, 'proto') and hasattr(spr.proto, 'name') and \ + spr.proto.name == 'journal': + return True + dx,dy = x-spr.x, y-spr.y + try: + return ord(spr.image.get_pixels()[(dy*spr.width+dx)*4+3]) == 255 + except IndexError: + if hasattr(spr, 'proto') and hasattr(spr.proto, 'name'): + print spr.proto.name + print "IndexError: string index out of range " + str(dx) + " " \ + + str(dy) + " " + str(spr.width) + " " + str(spr.height) + return True + +def draw_label(spr, label, myscale, center_flag="False", vert_pos="middle"): + fd = pango.FontDescription('Sans') + fd.set_size(int(myscale*spr.tw.scale*pango.SCALE)) + if type(label) == str or type(label) == unicode: + mylabel = label.replace("\0"," ") + l = len(mylabel) + pl = spr.tw.canvas.create_pango_layout(mylabel) + pl.set_font_description(fd) + if center_flag: + swidth = pl.get_size()[0]/pango.SCALE + centerx = spr.x+spr.width/2 + x = int(centerx-swidth/2) + else: + x = spr.x+4 # small offset from left edge + sheight = pl.get_size()[1]/pango.SCALE + centery = spr.y+spr.height/2 + if vert_pos == "middle": + y = int(centery-sheight/2) + elif vert_pos == "top": + y = int(sheight/2) + elif vert_pos == "bottom": + y = int(spr.height-sheight) + spr.tw.gc.set_foreground(spr.tw.msgcolor) + spr.tw.area.draw_layout(spr.tw.gc, x, y, pl) + else: + print type(label) + +# used for sliders +def draw_label1(spr, label): + draw_label(spr, label, 12, True, "middle") + +def draw_label2(spr, label): + draw_label(spr, str(label), 14, True, "top") + +def draw_label3(spr, label): + draw_label(spr, str(label), 14, True, "bottom") + diff --git a/window.py b/window.py new file mode 100644 index 0000000..68754d3 --- /dev/null +++ b/window.py @@ -0,0 +1,237 @@ +# -*- coding: utf-8 -*- +#Copyright (c) 2009, Walter Bender + +#Permission is hereby granted, free of charge, to any person obtaining a copy +#of this software and associated documentation files (the "Software"), to deal +#in the Software without restriction, including without limitation the rights +#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +#copies of the Software, and to permit persons to whom the Software is +#furnished to do so, subject to the following conditions: + +#The above copyright notice and this permission notice shall be included in +#all copies or substantial portions of the Software. + +#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +#THE SOFTWARE. + +from constants import * +import pygtk +pygtk.require('2.0') +import gtk +from gettext import gettext as _ +import math + +try: + from sugar.graphics import style + GRID_CELL_SIZE = style.GRID_CELL_SIZE +except: + GRID_CELL_SIZE = 0 + +from sprite_factory import * + +class Window: pass + +# +# handle launch from both within and without of Sugar environment +# +def new_window(canvas, path, parent=None): + + + + # store class variables here + tw = Window() + tw.path = path + tw.activity = parent + + # starting from command line + # we have to do all the work that was done in CardSortActivity.py + if parent is None: + tw.sugar = False + tw.canvas = canvas + + # starting from Sugar + else: + tw.sugar = True + tw.canvas = canvas + parent.show_all() + + tw.canvas.set_flags(gtk.CAN_FOCUS) + tw.canvas.add_events(gtk.gdk.BUTTON_PRESS_MASK) + tw.canvas.add_events(gtk.gdk.BUTTON_RELEASE_MASK) + tw.canvas.add_events(gtk.gdk.POINTER_MOTION_MASK) + tw.canvas.connect("expose-event", _expose_cb, tw) + tw.canvas.connect("button-press-event", _button_press_cb, tw) + tw.canvas.connect("button-release-event", _button_release_cb, tw) + tw.canvas.connect("motion-notify-event", _mouse_move_cb, tw) + tw.width = gtk.gdk.screen_width() + tw.height = gtk.gdk.screen_height()-GRID_CELL_SIZE + tw.area = tw.canvas.window + tw.gc = tw.area.new_gc() + tw.cm = tw.gc.get_colormap() + tw.msgcolor = tw.cm.alloc_color('black') + tw.sprites = [] + tw.scale = 1 + tw.answers_on_top = False + + # Open the sliders + y = 50 + tw.deck = [Sprite(tw,"CartaCristo",100,100,100,198,False),\ + Sprite(tw,"CartaGranMuralla",250,100,100,198,False),\ + Sprite(tw,"CartaMacchu",400,100,100,198,False)] + tw.cards = [tw.deck[0],tw.deck[1],tw.deck[2]] + tw.numbers = [Sprite(tw,"Carta1",100,100,100,198,False),\ + Sprite(tw,"Carta2",250,100,100,198,False),\ + Sprite(tw,"Carta3",400,100,100,198,False)] + + tw.questions = [Sprite(tw,"tab",100,320,100,50,True),\ + Sprite(tw,"tab",250,320,100,50,True),\ + Sprite(tw,"tab",400,320,100,50,True)] + + tw.qa_block = Sprite(tw,"tab",0,0,tw.width,tw.height,False) + tw.answers = [Sprite(tw,"tab",100,420,100,50,True),\ + Sprite(tw,"tab",100,520,100,50,True),\ + Sprite(tw,"tab",100,620,100,50,True),\ + Sprite(tw,"tab",250,420,100,50,True),\ + Sprite(tw,"tab",250,520,100,50,True),\ + Sprite(tw,"tab",250,620,100,50,True),\ + Sprite(tw,"tab",400,420,100,50,True),\ + Sprite(tw,"tab",400,520,100,50,True),\ + Sprite(tw,"tab",400,620,100,50,True)] + + for i in tw.cards: + i.draw_slider_bottom() + + for i in tw.numbers: + i.draw_slider_top() + + setlabel(tw.questions[0].spr,_("How are you?")) + setlabel(tw.answers[0].spr,_("muy bien")) + setlabel(tw.answers[1].spr,_("mas o menos")) + setlabel(tw.answers[2].spr,_("muy mal")) + + setlabel(tw.questions[1].spr,"Where are you?") + setlabel(tw.answers[3].spr,_("Lima")) + setlabel(tw.answers[4].spr,_("Andes")) + setlabel(tw.answers[5].spr,_("Cambridge")) + + setlabel(tw.questions[2].spr,"Who are you?") + setlabel(tw.answers[6].spr,_("Sebastian")) + setlabel(tw.answers[7].spr,_("Kiko")) + setlabel(tw.answers[8].spr,_("Hernán")) + + for i in tw.questions: + i.draw_slider_top() + + for i in tw.answers: + i.draw_slider_bottom() + + tw.qa_block.draw_slider_middle() + + # Start calculating + tw.press = None + tw.dragpos = 0,0 + + return tw + +# +# Button press +# +def _button_press_cb(win, event, tw): + win.grab_focus() + x, y = map(int, event.get_coords()) + tw.dragpos = x,y + spr = findsprite(tw,(x,y)) + tw.press = spr + return True + +# +# Mouse move +# +def _mouse_move_cb(win, event, tw): + if tw.press is None: + tw.dragpos = 0,0 + return True + + win.grab_focus() + x, y = map(int, event.get_coords()) + dx = x-tw.dragpos[0] + if tw.press == tw.cards[2].spr or tw.press == tw.numbers[2].spr: + # everything moves + move(tw.cards[0].spr,(tw.cards[0].spr.x+dx,tw.cards[0].spr.y)) + move(tw.cards[1].spr,(tw.cards[1].spr.x+dx,tw.cards[1].spr.y)) + move(tw.cards[2].spr,(tw.cards[2].spr.x+dx,tw.cards[2].spr.y)) + move(tw.numbers[0].spr,(tw.numbers[0].spr.x+dx,tw.numbers[0].spr.y)) + move(tw.numbers[1].spr,(tw.numbers[1].spr.x+dx,tw.numbers[1].spr.y)) + move(tw.numbers[2].spr,(tw.numbers[2].spr.x+dx,tw.numbers[2].spr.y)) + # reset drag position + tw.dragpos = x,y + +# +# Button release +# +def _button_release_cb(win, event, tw): + if tw.press == None: + tw.dragpos = 0,0 + return True + + if tw.press == tw.cards[1].spr: + x = tw.cards[2].spr.x + move(tw.cards[2].spr,(tw.cards[1].spr.x,tw.cards[2].spr.y)) + move(tw.cards[1].spr,(x,tw.cards[1].spr.y)) + elif tw.press == tw.cards[0].spr: + tw.cards[0].draw_slider_bottom() + tw.cards[1].draw_slider_bottom() + tw.cards[2].draw_slider_bottom() + tw.numbers[0].draw_slider_top() + tw.numbers[1].draw_slider_top() + tw.numbers[2].draw_slider_top() + elif tw.press == tw.numbers[1].spr: + x = tw.numbers[2].spr.x + move(tw.numbers[2].spr,(tw.numbers[1].spr.x,tw.numbers[2].spr.y)) + move(tw.numbers[1].spr,(x,tw.numbers[1].spr.y)) + elif tw.press == tw.numbers[0].spr: + tw.cards[0].draw_slider_top() + tw.cards[1].draw_slider_top() + tw.cards[2].draw_slider_top() + tw.numbers[0].draw_slider_bottom() + tw.numbers[1].draw_slider_bottom() + tw.numbers[2].draw_slider_bottom() + elif tw.press == tw.questions[0].spr: + if tw.answers_on_top is True: + for i in tw.answers: + i.draw_slider_bottom() + tw.answers_on_top = False + else: + tw.answers[0].draw_slider_top() + tw.answers[1].draw_slider_top() + tw.answers[2].draw_slider_top() + tw.answers_on_top = True + + + tw.press = None + update_label(tw) + +def update_label(tw): + # calculate the values for D, C, and D*C (under the redicule) + tw.activity.results_label.set_text( "my label changed " + str(tw.dragpos)) + tw.activity.results_label.show() + return True + +def _calc_C(tw): + return "foo" +def _calc_D(tw): + return "bar" +def _calc_DC(tw): + return "usmp" + +def _expose_cb(win, event, tw): + redrawsprites(tw) + return True + +def _destroy_cb(win, event, tw): + gtk.main_quit() diff --git a/window.pyc b/window.pyc new file mode 100644 index 0000000..289c195 --- /dev/null +++ b/window.pyc Binary files differ diff --git a/window.py~ b/window.py~ new file mode 100644 index 0000000..bad4fef --- /dev/null +++ b/window.py~ @@ -0,0 +1,187 @@ +# -*- coding: utf-8 -*- +#Copyright (c) 2009, Walter Bender + +#Permission is hereby granted, free of charge, to any person obtaining a copy +#of this software and associated documentation files (the "Software"), to deal +#in the Software without restriction, including without limitation the rights +#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +#copies of the Software, and to permit persons to whom the Software is +#furnished to do so, subject to the following conditions: + +#The above copyright notice and this permission notice shall be included in +#all copies or substantial portions of the Software. + +#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +#THE SOFTWARE. + +from constants import * +import pygtk +pygtk.require('2.0') +import gtk +from gettext import gettext as _ +import math + +try: + from sugar.graphics import style + GRID_CELL_SIZE = style.GRID_CELL_SIZE +except: + GRID_CELL_SIZE = 0 + +from sprite_factory import * + +class srWindow: pass + +# +# handle launch from both within and without of Sugar environment +# +def new_window(canvas, path, parent=None): + + + + # store class variables here + tw = srWindow() + tw.path = path + tw.activity = parent + + # starting from command line + # we have to do all the work that was done in CardSortActivity.py + if parent is None: + tw.sugar = False + tw.canvas = canvas + + # starting from Sugar + else: + tw.sugar = True + tw.canvas = canvas + parent.show_all() + + tw.canvas.set_flags(gtk.CAN_FOCUS) + tw.canvas.add_events(gtk.gdk.BUTTON_PRESS_MASK) + tw.canvas.add_events(gtk.gdk.BUTTON_RELEASE_MASK) + tw.canvas.add_events(gtk.gdk.POINTER_MOTION_MASK) + tw.canvas.connect("expose-event", _expose_cb, tw) + tw.canvas.connect("button-press-event", _button_press_cb, tw) + tw.canvas.connect("button-release-event", _button_release_cb, tw) + tw.canvas.connect("motion-notify-event", _mouse_move_cb, tw) + tw.width = gtk.gdk.screen_width() + tw.height = gtk.gdk.screen_height()-GRID_CELL_SIZE + tw.area = tw.canvas.window + tw.gc = tw.area.new_gc() + tw.cm = tw.gc.get_colormap() + tw.msgcolor = tw.cm.alloc_color('black') + tw.sprites = [] + tw.scale = 1 + + # Open the sliders + y = 50 + tw.cards = [Sprite(tw,"CartaCristo",100,100,100,198,False),\ + Sprite(tw,"CartaGranMuralla",250,100,100,198,False),\ + Sprite(tw,"CartaMacchu",400,100,100,198,False)] + tw.numbers = [Sprite(tw,"Carta1",100,100,100,198,False),\ + Sprite(tw,"Carta2",250,100,100,198,False),\ + Sprite(tw,"Carta3",400,100,100,198,False)] + + + tw.cards[0].draw_slider_bottom() + tw.cards[1].draw_slider_bottom() + tw.cards[2].draw_slider_bottom() + tw.numbers[0].draw_slider_top() + tw.numbers[1].draw_slider_top() + tw.numbers[2].draw_slider_top() + + + # Start calculating + tw.press = None + tw.dragpos = 0,0 + + return tw + +# +# Button press +# +def _button_press_cb(win, event, tw): + win.grab_focus() + x, y = map(int, event.get_coords()) + tw.dragpos = x,y + spr = findsprite(tw,(x,y)) + tw.press = spr + return True + +# +# Mouse move +# +def _mouse_move_cb(win, event, tw): + if tw.press is None: + tw.dragpos = 0,0 + return True + + win.grab_focus() + x, y = map(int, event.get_coords()) + dx = x-tw.dragpos[0] + if tw.press == tw.cards[2].spr or tw.press == tw.numbers[2].spr: + # everything moves + move(tw.cards[0].spr,(tw.cards[0].spr.x+dx,tw.cards[0].spr.y)) + move(tw.cards[1].spr,(tw.cards[1].spr.x+dx,tw.cards[1].spr.y)) + move(tw.cards[2].spr,(tw.cards[2].spr.x+dx,tw.cards[2].spr.y)) + move(tw.numbers[0].spr,(tw.numbers[0].spr.x+dx,tw.numbers[0].spr.y)) + move(tw.numbers[1].spr,(tw.numbers[1].spr.x+dx,tw.numbers[1].spr.y)) + move(tw.numbers[2].spr,(tw.numbers[2].spr.x+dx,tw.numbers[2].spr.y)) + # reset drag position + tw.dragpos = x,y + +# +# Button release +# +def _button_release_cb(win, event, tw): + print tw.press + if tw.press == None: + return True + if tw.press == tw.cards[1].spr: + x = tw.cards[2].spr.x + move(tw.cards[2].spr,(tw.cards[1].spr.x,tw.cards[2].spr.y)) + move(tw.cards[1].spr,(x,tw.cards[1].spr.y)) + elif tw.press == tw.cards[0].spr: + tw.cards[0].draw_slider_bottom() + tw.cards[1].draw_slider_bottom() + tw.cards[2].draw_slider_bottom() + tw.numbers[0].draw_slider_top() + tw.numbers[1].draw_slider_top() + tw.numbers[2].draw_slider_top() + elif tw.press == tw.numbers[1].spr: + x = tw.numbers[2].spr.x + move(tw.numbers[2].spr,(tw.numbers[1].spr.x,tw.numbers[2].spr.y)) + move(tw.numbers[1].spr,(x,tw.numbers[1].spr.y)) + elif tw.press == tw.numbers[0].spr: + tw.cards[0].draw_slider_top() + tw.cards[1].draw_slider_top() + tw.cards[2].draw_slider_top() + tw.numbers[0].draw_slider_bottom() + tw.numbers[1].draw_slider_bottom() + tw.numbers[2].draw_slider_bottom() + tw.press = None + update_label(tw) + +def update_label(tw): + # calculate the values for D, C, and D*C (under the redicule) + tw.activity.results_label.set_text( "my label changed " + str(tw.dragpos)) + tw.activity.results_label.show() + return True + +def _calc_C(tw): + return "foo" +def _calc_D(tw): + return "bar" +def _calc_DC(tw): + return "usmp" + +def _expose_cb(win, event, tw): + redrawsprites(tw) + return True + +def _destroy_cb(win, event, tw): + gtk.main_quit() -- cgit v0.9.1