diff options
-rw-r--r-- | CixosActivity.pyc | bin | 4859 -> 0 bytes | |||
-rw-r--r-- | CixosActivity.py~ | 156 | ||||
-rw-r--r-- | NEWS~ | 11 | ||||
-rw-r--r-- | constants.pyc | bin | 238 -> 0 bytes | |||
-rw-r--r-- | sprite_factory.pyc | bin | 1957 -> 0 bytes | |||
-rw-r--r-- | sprite_factory.py~ | 54 | ||||
-rw-r--r-- | sprites.pyc | bin | 6105 -> 0 bytes | |||
-rw-r--r-- | sprites.py~ | 165 | ||||
-rw-r--r-- | window.pyc | bin | 7081 -> 0 bytes | |||
-rw-r--r-- | window.py~ | 187 |
10 files changed, 0 insertions, 573 deletions
diff --git a/CixosActivity.pyc b/CixosActivity.pyc Binary files differdeleted file mode 100644 index 46ad42b..0000000 --- a/CixosActivity.pyc +++ /dev/null diff --git a/CixosActivity.py~ b/CixosActivity.py~ deleted file mode 100644 index 9f765cd..0000000 --- a/CixosActivity.py~ +++ /dev/null @@ -1,156 +0,0 @@ -# -*- 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 = '<Ctrl>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() @@ -1,11 +0,0 @@ -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/constants.pyc b/constants.pyc Binary files differdeleted file mode 100644 index ac04bb2..0000000 --- a/constants.pyc +++ /dev/null diff --git a/sprite_factory.pyc b/sprite_factory.pyc Binary files differdeleted file mode 100644 index e1cc078..0000000 --- a/sprite_factory.pyc +++ /dev/null diff --git a/sprite_factory.py~ b/sprite_factory.py~ deleted file mode 100644 index 70916ab..0000000 --- a/sprite_factory.py~ +++ /dev/null @@ -1,54 +0,0 @@ -#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.pyc b/sprites.pyc Binary files differdeleted file mode 100644 index 69525b7..0000000 --- a/sprites.pyc +++ /dev/null diff --git a/sprites.py~ b/sprites.py~ deleted file mode 100644 index b702eb4..0000000 --- a/sprites.py~ +++ /dev/null @@ -1,165 +0,0 @@ -# -*- 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 x<spr.x: return False - if x>spr.x+spr.width: return False - if y<spr.y: return False - if y>spr.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.pyc b/window.pyc Binary files differdeleted file mode 100644 index 289c195..0000000 --- a/window.pyc +++ /dev/null diff --git a/window.py~ b/window.py~ deleted file mode 100644 index bad4fef..0000000 --- a/window.py~ +++ /dev/null @@ -1,187 +0,0 @@ -# -*- 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() |