Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/browseeditpanel.py
diff options
context:
space:
mode:
Diffstat (limited to 'browseeditpanel.py')
-rw-r--r--browseeditpanel.py235
1 files changed, 235 insertions, 0 deletions
diff --git a/browseeditpanel.py b/browseeditpanel.py
new file mode 100644
index 0000000..71e9871
--- /dev/null
+++ b/browseeditpanel.py
@@ -0,0 +1,235 @@
+# -*- coding: utf-8 -*-
+#Copyright (c) 2010, Kirk Winans
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+import gtk
+from os import environ
+from os.path import join, basename
+import hippo
+
+import shutil
+import tempfile
+from gettext import gettext as _
+import logging
+from gobject import SIGNAL_RUN_FIRST, TYPE_PYOBJECT
+from sugar.graphics import style
+from sugar.graphics.toolbutton import ToolButton
+from sugar.graphics.icon import Icon
+from sugar.graphics.palette import Palette
+from port.widgets import ToggleToolButton
+from port.widgets import CanvasRoundBox, ToolComboBox
+#from port import chooser
+
+from sugar.datastore import datastore
+import xml.etree.ElementTree
+from datetime import date
+import time
+
+import FlashcardActivity
+
+#
+# Browse/Edit panel for Flashcard Activity
+#
+class BrowseEditPanel(gtk.VBox):
+
+ def __init__(self, activity_root):
+ gtk.VBox.__init__(self)
+
+ self.activity_root = activity_root
+
+ # Loading in tree of cards
+ self.testfile = "testfile.xml"
+ self.tree = xml.etree.ElementTree.parse(self.testfile)
+
+ self.deck_element = self.tree.getroot()
+ self.deck = self.deck_element.findall("card")
+ self.current_card_index = 0
+
+ next_card_tuple = self.next_card()
+
+ self.viewcard_box = gtk.VBox()
+
+ # Boxes to view the different parts of the cards
+ self.viewfront_box = gtk.HBox()
+ self.viewback_box = gtk.HBox()
+ self.viewcatagory_box = gtk.HBox()
+ self.viewstage_box = gtk.HBox()
+ self.viewdate_box = gtk.HBox()
+
+ self.front_label = gtk.Label(_('Front:'))
+
+ self.viewfront = gtk.TextView()
+ self.frontbuffer = self.viewfront.get_buffer()
+ self.viewfront.set_editable(False)
+ self.viewfront.set_wrap_mode(gtk.WRAP_WORD)
+ self.viewfront.set_justification(gtk.JUSTIFY_CENTER)
+ self.viewfront.set_pixels_below_lines(0)
+ self.viewfront.set_pixels_above_lines(40)
+
+ self.back_label = gtk.Label(_('Back:'))
+
+ self.viewback = gtk.TextView()
+ self.backbuffer = self.viewback.get_buffer()
+ self.viewback.set_editable(False)
+ self.viewback.set_wrap_mode(gtk.WRAP_WORD)
+ self.viewback.set_justification(gtk.JUSTIFY_CENTER)
+ self.viewback.set_pixels_below_lines(0)
+ self.viewback.set_pixels_above_lines(40)
+
+ self.catagory_label = gtk.Label(_('Category:'))
+
+ self.viewcatagory = gtk.TextView()
+ self.catagorybuffer = self.viewcatagory.get_buffer()
+ self.viewcatagory.set_editable(False)
+ self.viewcatagory.set_wrap_mode(gtk.WRAP_WORD)
+ self.viewcatagory.set_justification(gtk.JUSTIFY_CENTER)
+ self.viewcatagory.set_pixels_below_lines(0)
+ self.viewcatagory.set_pixels_above_lines(40)
+
+ self.stage_label = gtk.Label(_('Stage:'))
+
+ self.viewstage = gtk.TextView()
+ self.stagebuffer = self.viewstage.get_buffer()
+ self.viewstage.set_editable(False)
+ self.viewstage.set_wrap_mode(gtk.WRAP_WORD)
+ self.viewstage.set_justification(gtk.JUSTIFY_CENTER)
+ self.viewstage.set_pixels_below_lines(0)
+ self.viewstage.set_pixels_above_lines(40)
+
+ self.date_label = gtk.Label(_('Last Reviewed:'))
+
+ self.viewdate = gtk.TextView()
+ self.datebuffer = self.viewdate.get_buffer()
+ self.viewdate.set_editable(False)
+ self.viewdate.set_wrap_mode(gtk.WRAP_WORD)
+ self.viewdate.set_justification(gtk.JUSTIFY_CENTER)
+ self.viewdate.set_pixels_below_lines(0)
+ self.viewdate.set_pixels_above_lines(40)
+
+ self.nextbutton_bar = gtk.HButtonBox()
+
+
+ # Next Card Button
+ self._nextbutton = ToolButton(tooltip=_('Next Card'))
+ self._nextbutton.connect('clicked', self._next_card_cb)
+ self._nextbutton.set_icon_widget(
+ self.make_label('go-next', ' ' + _('Next Card')))
+
+ self.viewfront_box.pack_start(self.front_label)
+ self.viewfront_box.pack_start(self.viewfront)
+
+ self.viewback_box.pack_start(self.back_label)
+ self.viewback_box.pack_start(self.viewback)
+
+ self.viewcatagory_box.pack_start(self.catagory_label)
+ self.viewcatagory_box.pack_start(self.viewcatagory)
+
+ self.viewstage_box.pack_start(self.stage_label)
+ self.viewstage_box.pack_start(self.viewstage)
+
+ self.viewdate_box.pack_start(self.date_label)
+ self.viewdate_box.pack_start(self.viewdate)
+
+
+ self.viewcard_box.pack_start(self.viewfront_box)
+ self.viewcard_box.pack_start(self.viewback_box)
+ self.viewcard_box.pack_start(self.viewcatagory_box)
+ self.viewcard_box.pack_start(self.viewstage_box)
+ self.viewcard_box.pack_start(self.viewdate_box)
+
+ self.nextbutton_bar.pack_start(self._nextbutton)
+
+ self.add(self.viewcard_box)
+ self.add(self.nextbutton_bar)
+
+ self.frontbuffer.set_text(next_card_tuple[0])
+ self.backbuffer.set_text(next_card_tuple[1])
+ self.catagorybuffer.set_text(next_card_tuple[2])
+ self.stagebuffer.set_text(next_card_tuple[3])
+ self.datebuffer.set_text(next_card_tuple[4])
+
+ self.front_label.show()
+ self.back_label.show()
+ self.catagory_label.show()
+ self.stage_label.show()
+ self.date_label.show()
+
+ self.viewfront.show()
+ self.viewback.show()
+ self.viewcatagory.show()
+ self.viewstage.show()
+ self.viewdate.show()
+
+ self.viewfront_box.show()
+ self.viewback_box.show()
+ self.viewcatagory_box.show()
+ self.viewstage_box.show()
+ self.viewdate_box.show()
+
+ self.viewcard_box.show()
+ self._nextbutton.show()
+ self.nextbutton_bar.show()
+
+ # Returns the info from the next card
+ def next_card(self):
+ card = self.deck[self.current_card_index]
+ self.front = card.find("front").text
+ self.back = card.find("back").text
+ last = self.convert_date(card.find("last_reviewed").text)
+ stage = card.find("stage").text
+ self.catagory = card.find("catagory").text
+
+ if (self.current_card_index+1) < len(self.deck):
+ self.current_card_index += 1
+ else:
+ self.current_card_index = 0
+
+ return (self.front, self.back, self.catagory, stage, last)
+
+ # Converts the date from timestamp format to dd/mm/yyyy
+ def convert_date(self, timestamp_string):
+ timestamp = float(timestamp_string)
+ time_structure = time.gmtime(timestamp)
+ return (str(time_structure.tm_mday) + "/" + str(time_structure.tm_mon)
+ + "/" + str(time_structure.tm_year))
+
+ # Next Card button callback, gets next card and sets the text buffers
+ def _next_card_cb(self, button):
+ next_card_tuple = self.next_card()
+ self.frontbuffer.set_text(next_card_tuple[0])
+ self.backbuffer.set_text(next_card_tuple[1])
+ self.catagorybuffer.set_text(next_card_tuple[2])
+ self.stagebuffer.set_text(next_card_tuple[3])
+ self.datebuffer.set_text(next_card_tuple[4])
+
+ # Returns card text
+ def get_card_text(self):
+ return [self.front, self.back, self.catagory]
+
+ # Makes the icons for button and makes the label
+ # Written by Simon Schampijer
+ def make_label(self, icon_name, label):
+ label_box = gtk.HBox()
+ icon = Icon(
+ icon_name=icon_name,
+ icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR)
+ label_box.pack_start(icon, False)
+ label = gtk.Label(label)
+ label.modify_fg(gtk.STATE_NORMAL,
+ style.COLOR_TOOLBAR_GREY.get_gdk_color())
+ label_box.pack_start(label)
+ label_box.show_all()
+ return label_box
+
+
+
+
+