Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--edit.py86
-rw-r--r--icons/journal-image.svg76
-rw-r--r--icons/load-image-from-journal.svg83
-rw-r--r--icons/load-text-from-journal.svg97
-rw-r--r--infoslicer/processing/Article_Builder.py8
-rw-r--r--infoslicer/processing/HTML_strip.py89
-rw-r--r--infoslicer/widgets/Gallery_View.py20
-rw-r--r--infoslicer/widgets/Journal_Gallery_View.py168
-rw-r--r--infoslicer/widgets/Journal_Image_Pane.py62
-rw-r--r--library.py24
10 files changed, 682 insertions, 31 deletions
diff --git a/edit.py b/edit.py
index e48509e..f3c8fe6 100644
--- a/edit.py
+++ b/edit.py
@@ -13,21 +13,34 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
from gi.repository import Gtk
+from gi.repository import Gdk
from gi.repository import GObject
from gettext import gettext as _
from sugar3.graphics.toolbutton import ToolButton
from sugar3.graphics.toggletoolbutton import ToggleToolButton
+from sugar3 import mime
+from sugar3.graphics.objectchooser import ObjectChooser
+
from infoslicer.widgets.Edit_Pane import Edit_Pane
from infoslicer.widgets.Format_Pane import Format_Pane
from infoslicer.widgets.Image_Pane import Image_Pane
+from infoslicer.widgets.Journal_Image_Pane import Journal_Image_Pane
+from infoslicer.processing.HTML_strip import dehtml
+from infoslicer.processing.Article import Article
+
import book
+import logging
+
+
TABS = (Edit_Pane(),
Image_Pane(),
+ Journal_Image_Pane(),
Format_Pane())
+
class View(Gtk.Notebook):
def __init__(self):
GObject.GObject.__init__(self)
@@ -51,20 +64,38 @@ class View(Gtk.Notebook):
class ToolbarBuilder():
def __init__(self, edit, toolbar):
self.edit = edit
+ logging.debug('init edit toolbar')
+ logging.debug(self.edit)
self.txt_toggle = ToggleToolButton('ascii')
self.img_toggle = ToggleToolButton('image')
+ self.jimg_toggle = ToggleToolButton('journal-image')
+ self.jimg_chooser_toggle = ToolButton('load-image-from-journal')
+ self.jtext_chooser_toggle = ToolButton('load-text-from-journal')
self.txt_toggle.set_tooltip(_('Text'))
self.txt_toggle.connect('toggled', self._toggle_cb,
- [self.txt_toggle, self.img_toggle])
+ [self.txt_toggle, self.img_toggle, self.jimg_toggle])
toolbar.insert(self.txt_toggle, -1)
self.img_toggle.set_tooltip(_('Images'))
self.img_toggle.connect('toggled', self._toggle_cb,
- [self.txt_toggle, self.img_toggle])
+ [self.txt_toggle, self.img_toggle, self.jimg_toggle])
toolbar.insert(self.img_toggle, -1)
+ self.jimg_toggle.set_tooltip(_('Journal Images'))
+ self.jimg_toggle.connect('toggled', self._toggle_cb,
+ [self.txt_toggle, self.img_toggle, self.jimg_toggle])
+ toolbar.insert(self.jimg_toggle, -1)
+
+ self.jimg_chooser_toggle.set_tooltip(_('Choose Journal Images'))
+ self.jimg_chooser_toggle.connect('clicked', self._toggle_image_chooser)
+ toolbar.insert(self.jimg_chooser_toggle, -1)
+
+ self.jtext_chooser_toggle.set_tooltip(_('Choose Journal Text'))
+ self.jtext_chooser_toggle.connect('clicked', self._toggle_text_chooser)
+ toolbar.insert(self.jtext_chooser_toggle, -1)
+
for tab in TABS:
for i in tab.toolitems:
toolbar.insert(i, -1)
@@ -74,10 +105,48 @@ class ToolbarBuilder():
def sensitize_all(self):
self.txt_toggle.set_sensitive(True)
self.img_toggle.set_sensitive(True)
+ self.jimg_toggle.set_sensitive(True)
def unsensitize_all(self):
self.txt_toggle.set_sensitive(False)
self.img_toggle.set_sensitive(False)
+ self.jimg_toggle.set_sensitive(False)
+
+ def _toggle_image_chooser(self, widget):
+ # self._old_cursor = self.edit.get_window().get_cursor()
+ # self.edit.get_window().set_cursor(Gdk.Cursor.new(Gdk.CursorType.WATCH))
+ GObject.idle_add(self.__image_chooser)
+
+ def __image_chooser(self):
+ chooser = ObjectChooser(what_filter=mime.GENERIC_TYPE_IMAGE)
+ result = chooser.run()
+ if result == Gtk.ResponseType.ACCEPT:
+ jobject = chooser.get_selected_object()
+ if jobject and jobject.file_path:
+ title = str(jobject.metadata['title'])
+ path = str(jobject.file_path)
+ TABS[2].gallery.add_image(path, title)
+ # self.edit.get_window().set_cursor(self._old_cursor)
+
+ def _toggle_text_chooser(self, widget):
+ # self._old_cursor = self.edit.get_window().get_cursor()
+ # self.edit.get_window().set_cursor(Gdk.Cursor.new(Gdk.CursorType.WATCH))
+ GObject.idle_add(self.__text_chooser)
+
+ def __text_chooser(self):
+ chooser = ObjectChooser(what_filter=mime.GENERIC_TYPE_TEXT)
+ result = chooser.run()
+ if result == Gtk.ResponseType.ACCEPT:
+ jobject = chooser.get_selected_object()
+ if jobject and jobject.file_path:
+ title = str(jobject.metadata['title'])
+ path = str(jobject.file_path)
+ fp = open(path, 'r')
+ text = fp.read()
+ fp.close()
+ article_data = dehtml(text, title)
+ TABS[0].set_source_article(Article(article_data))
+ # self.edit.get_window().set_cursor(self._old_cursor)
def _toggle_cb(self, widget, toggles):
for tab in TABS:
@@ -85,16 +154,19 @@ class ToolbarBuilder():
i.hide()
if not widget.get_active():
- index = 2
+ index = 3
else:
- another = toggles[0] == widget and 1 or 0
- toggles[another].set_active(False)
- index = int(not another)
+ for t in range(0, len(toggles)):
+ if toggles[t] != widget:
+ toggles[t].set_active(False)
+ else:
+ index = t
for i in TABS[index].toolitems:
i.show()
- if book.wiki.article:
+ # We don't require any article data to display jounal images
+ if book.wiki.article and index != 2:
TABS[index].set_source_article(book.wiki.article)
if book.custom.article:
TABS[index].set_working_article(book.custom.article)
diff --git a/icons/journal-image.svg b/icons/journal-image.svg
new file mode 100644
index 0000000..e0118e9
--- /dev/null
+++ b/icons/journal-image.svg
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ version="1.1"
+ width="55"
+ height="55"
+ viewBox="0 0 55 55"
+ id="svg2"
+ xml:space="preserve"><metadata
+ id="metadata25"><rdf:RDF><cc:Work
+ rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
+ id="defs33" /><g
+ transform="matrix(0.65959435,0,0,0.65959435,2.2217886,-0.13950423)"
+ id="clipping-image"
+ style="display:block"><g
+ id="g5"
+ style="display:inline"><g
+ id="g7"><polygon
+ points="48.788,23.002 36.849,11.058 5.962,11.058 5.962,43.944 48.788,43.944 "
+ id="polygon9"
+ style="fill:#ffffff;stroke:#010101;stroke-width:3.5" /><polyline
+ style="fill:none;stroke:#010101;stroke-width:3.5"
+ points="36.849,11.058 36.849,23.002 48.788,23.002 "
+ id="polyline11" /></g></g><path
+ d="m 27.504,23.342 c -6.258,0 -11.471,6.241 -11.471,6.241 0,0 5.213,6.271 11.471,6.267 6.259,-0.005 11.475,-6.274 11.475,-6.274 0,0 -5.216,-6.238 -11.475,-6.234 z m 0,10.642 c -2.423,0 -4.387,-1.966 -4.387,-4.389 0,-2.419 1.964,-4.388 4.387,-4.388 2.42,0 4.386,1.969 4.386,4.388 0,2.424 -1.966,4.389 -4.386,4.389 z"
+ id="path13"
+ style="fill:#010101;display:inline" /><circle
+ cx="27.504"
+ cy="29.597"
+ r="1.9910001"
+ id="circle15"
+ style="fill:#010101;display:inline" /></g><g
+ transform="matrix(1.079797,0,0,1.079797,-5.2529966,-5.2292405)"
+ id="g3013"
+ style="stroke:#ffffff;stroke-opacity:1"><g
+ transform="matrix(0.55205508,0,0,0.55205508,77.118464,18.235971)"
+ id="g4382"
+ style="stroke:#ffffff;stroke-opacity:1"><g
+ transform="translate(-80.093659,12.220029)"
+ id="g4308"
+ style="fill:none;stroke:#ffffff;stroke-opacity:1"><g
+ id="g4310"
+ style="fill:none;stroke:#ffffff;stroke-opacity:1"><path
+ d="m 6.736,49.002 h 24.52 c 2.225,0 3.439,-1.447 3.439,-3.441 v -27.28 c 0,-1.73 -1.732,-3.441 -3.439,-3.441 h -4.389"
+ id="path4312"
+ style="fill:none;stroke:#ffffff;stroke-width:3.5;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1" /></g></g><g
+ transform="translate(-80.093659,12.220029)"
+ id="g4314"
+ style="fill:none;stroke:#ffffff;stroke-opacity:1"><g
+ id="g4316"
+ style="fill:none;stroke:#ffffff;stroke-opacity:1"><path
+ d="m 26.867,38.592 c 0,1.836 -1.345,3.201 -3.441,4.047 L 6.736,49.002 V 14.84 l 16.69,-8.599 c 2.228,-0.394 3.441,0.84 3.441,2.834 v 29.517 z"
+ id="path4318"
+ style="fill:none;stroke:#ffffff;stroke-width:3.5;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1" /></g></g><path
+ d="m -70.669659,54.827029 c 0,0 -1.351,-0.543 -2.702,-0.543 -1.351,0 -2.703,0.543 -2.703,0.543"
+ id="path4320"
+ style="fill:none;stroke:#ffffff;stroke-width:2.25;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1" /><path
+ d="m -70.669659,44.226029 c 0,0 -1.239,-0.543 -2.815,-0.543 -1.577,0 -2.59,0.543 -2.59,0.543"
+ id="path4322"
+ style="fill:none;stroke:#ffffff;stroke-width:2.25;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1" /><path
+ d="m -70.669659,33.898029 c 0,0 -1.125,-0.544 -2.927,-0.544 -1.802,0 -2.478,0.544 -2.478,0.544"
+ id="path4324"
+ style="fill:none;stroke:#ffffff;stroke-width:2.25;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1" /><line
+ id="line4326"
+ y2="23.725029"
+ y1="58.753029"
+ x2="-66.884659"
+ x1="-66.884659"
+ style="fill:none;stroke:#ffffff;stroke-width:2.25;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1" /></g></g></svg> \ No newline at end of file
diff --git a/icons/load-image-from-journal.svg b/icons/load-image-from-journal.svg
new file mode 100644
index 0000000..b8307c8
--- /dev/null
+++ b/icons/load-image-from-journal.svg
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ version="1.1"
+ width="55"
+ height="55"
+ viewBox="0 0 55 55"
+ id="svg2"
+ xml:space="preserve"><metadata
+ id="metadata25"><rdf:RDF><cc:Work
+ rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
+ id="defs33" /><g
+ transform="matrix(0.55205508,0,0,0.55205508,77.118464,18.235971)"
+ id="g4382"><g
+ transform="translate(-80.093659,12.220029)"
+ id="g4308"
+ style="fill:none;stroke:#ffffff;stroke-opacity:1"><g
+ id="g4310"
+ style="fill:none;stroke:#ffffff;stroke-opacity:1"><path
+ d="m 6.736,49.002 h 24.52 c 2.225,0 3.439,-1.447 3.439,-3.441 v -27.28 c 0,-1.73 -1.732,-3.441 -3.439,-3.441 h -4.389"
+ id="path4312"
+ style="fill:none;stroke:#ffffff;stroke-width:3.5;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1" /></g></g><g
+ transform="translate(-80.093659,12.220029)"
+ id="g4314"
+ style="fill:none;stroke:#ffffff;stroke-opacity:1"><g
+ id="g4316"
+ style="fill:none;stroke:#ffffff;stroke-opacity:1"><path
+ d="m 26.867,38.592 c 0,1.836 -1.345,3.201 -3.441,4.047 L 6.736,49.002 V 14.84 l 16.69,-8.599 c 2.228,-0.394 3.441,0.84 3.441,2.834 v 29.517 z"
+ id="path4318"
+ style="fill:none;stroke:#ffffff;stroke-width:3.5;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1" /></g></g><path
+ d="m -70.669659,54.827029 c 0,0 -1.351,-0.543 -2.702,-0.543 -1.351,0 -2.703,0.543 -2.703,0.543"
+ id="path4320"
+ style="fill:none;stroke:#ffffff;stroke-width:2.25;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1" /><path
+ d="m -70.669659,44.226029 c 0,0 -1.239,-0.543 -2.815,-0.543 -1.577,0 -2.59,0.543 -2.59,0.543"
+ id="path4322"
+ style="fill:none;stroke:#ffffff;stroke-width:2.25;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1" /><path
+ d="m -70.669659,33.898029 c 0,0 -1.125,-0.544 -2.927,-0.544 -1.802,0 -2.478,0.544 -2.478,0.544"
+ id="path4324"
+ style="fill:none;stroke:#ffffff;stroke-width:2.25;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1" /><line
+ style="fill:none;stroke:#ffffff;stroke-width:2.25;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1"
+ x1="-66.884659"
+ x2="-66.884659"
+ y1="58.753029"
+ y2="23.725029"
+ id="line4326" /></g><g
+ transform="matrix(1.1623273,0,0,1.1623273,-14.422024,-12.63995)"
+ id="g3882"
+ style="fill:none;stroke:#ffffff;stroke-width:2.15085721;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;display:inline"><g
+ id="g3884"
+ style="fill:none;stroke:#ffffff;stroke-width:2.15085721;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"><polygon
+ points="35.281,13.812 15.204,13.812 15.204,35.189 43.041,35.189 43.041,21.577 "
+ id="polygon3886"
+ style="fill:none;stroke:#ffffff;stroke-width:2.15085721;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /><polyline
+ id="polyline3888"
+ points="35.281,13.812 35.281,21.577 43.041,21.577 "
+ style="fill:none;stroke:#ffffff;stroke-width:2.15085721;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /></g></g><path
+ d="m 19.426691,12.275117 c -4.727185,0 -8.666312,4.714399 -8.666312,4.714399 0,0 3.939127,4.737646 8.666312,4.735322 4.729509,-0.0046 8.668637,-4.739971 8.668637,-4.739971 0,0 -3.939128,-4.713237 -8.668637,-4.70975 z m 0,8.039818 c -1.830666,0 -3.314958,-1.484292 -3.314958,-3.31612 0,-1.827179 1.484292,-3.314958 3.314958,-3.314958 1.828341,0 3.312632,1.487779 3.312632,3.314958 0,1.831828 -1.484291,3.31612 -3.312632,3.31612 z"
+ id="path3890"
+ style="fill:#ffffff;fill-opacity:1;stroke:none;display:inline" /><circle
+ cx="29.207001"
+ cy="25.863001"
+ r="1.294"
+ transform="matrix(1.1623273,0,0,1.1623273,-14.520241,-13.061294)"
+ id="circle3892"
+ style="fill:#ffffff;fill-opacity:1;stroke:none;display:inline" /><g
+ transform="matrix(-1,0,0,1,90.661358,9.6560695)"
+ id="g4770"><g
+ transform="translate(34.0803,-1006.42)"
+ id="g4772"><polyline
+ transform="matrix(-0.469241,0.469241,-0.469241,-0.469241,66.2906,1019.03)"
+ style="fill:none;stroke:#ffffff;stroke-width:3.5;stroke-linecap:round;stroke-linejoin:round"
+ points="51.562,15.306 41.17,16.188 42.053,5.794"
+ id="polyline4774" /><path
+ d="m 39.363241,1033.1291 -0.05636,9.9115 -8.750608,0.067"
+ id="path4776"
+ style="fill:none;stroke:#ffffff;stroke-width:2.5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /></g></g></svg> \ No newline at end of file
diff --git a/icons/load-text-from-journal.svg b/icons/load-text-from-journal.svg
new file mode 100644
index 0000000..b3db477
--- /dev/null
+++ b/icons/load-text-from-journal.svg
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ version="1.1"
+ width="55"
+ height="55"
+ viewBox="0 0 55 55"
+ id="svg2"
+ xml:space="preserve"><metadata
+ id="metadata25"><rdf:RDF><cc:Work
+ rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
+ id="defs33" /><g
+ transform="matrix(0.55205508,0,0,0.55205508,77.118464,18.235971)"
+ id="g4382"><g
+ transform="translate(-80.093659,12.220029)"
+ id="g4308"
+ style="fill:none;stroke:#ffffff;stroke-opacity:1"><g
+ id="g4310"
+ style="fill:none;stroke:#ffffff;stroke-opacity:1"><path
+ d="m 6.736,49.002 h 24.52 c 2.225,0 3.439,-1.447 3.439,-3.441 v -27.28 c 0,-1.73 -1.732,-3.441 -3.439,-3.441 h -4.389"
+ id="path4312"
+ style="fill:none;stroke:#ffffff;stroke-width:3.5;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1" /></g></g><g
+ transform="translate(-80.093659,12.220029)"
+ id="g4314"
+ style="fill:none;stroke:#ffffff;stroke-opacity:1"><g
+ id="g4316"
+ style="fill:none;stroke:#ffffff;stroke-opacity:1"><path
+ d="m 26.867,38.592 c 0,1.836 -1.345,3.201 -3.441,4.047 L 6.736,49.002 V 14.84 l 16.69,-8.599 c 2.228,-0.394 3.441,0.84 3.441,2.834 v 29.517 z"
+ id="path4318"
+ style="fill:none;stroke:#ffffff;stroke-width:3.5;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1" /></g></g><path
+ d="m -70.669659,54.827029 c 0,0 -1.351,-0.543 -2.702,-0.543 -1.351,0 -2.703,0.543 -2.703,0.543"
+ id="path4320"
+ style="fill:none;stroke:#ffffff;stroke-width:2.25;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1" /><path
+ d="m -70.669659,44.226029 c 0,0 -1.239,-0.543 -2.815,-0.543 -1.577,0 -2.59,0.543 -2.59,0.543"
+ id="path4322"
+ style="fill:none;stroke:#ffffff;stroke-width:2.25;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1" /><path
+ d="m -70.669659,33.898029 c 0,0 -1.125,-0.544 -2.927,-0.544 -1.802,0 -2.478,0.544 -2.478,0.544"
+ id="path4324"
+ style="fill:none;stroke:#ffffff;stroke-width:2.25;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1" /><line
+ style="fill:none;stroke:#ffffff;stroke-width:2.25;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1"
+ x1="-66.884659"
+ x2="-66.884659"
+ y1="58.753029"
+ y2="23.725029"
+ id="line4326" /></g><g
+ transform="matrix(0,-1,1,0,9.8287336,88.386573)"
+ id="g4770"><g
+ transform="translate(34.0803,-1006.42)"
+ id="g4772"><polyline
+ transform="matrix(-0.469241,0.469241,-0.469241,-0.469241,66.2906,1019.03)"
+ style="fill:none;stroke:#ffffff;stroke-width:3.5;stroke-linecap:round;stroke-linejoin:round"
+ points="51.562,15.306 41.17,16.188 42.053,5.794"
+ id="polyline4774" /><path
+ d="m 39.363241,1033.1291 -0.05636,9.9115 -8.750608,0.067"
+ id="path4776"
+ style="fill:none;stroke:#ffffff;stroke-width:2.5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /></g></g><g
+ transform="matrix(0.75578519,0,0,0.75578519,-4.9396196,-1.2911009)"
+ id="clipping-text"
+ style="fill:none;stroke:#ffffff;stroke-opacity:1;display:block"><g
+ id="g3152"
+ style="fill:none;stroke:#ffffff;stroke-opacity:1;display:inline"><g
+ id="g3154"
+ style="fill:none;stroke:#ffffff;stroke-opacity:1"><polygon
+ points="10.932,6.088 31.874,6.088 43.818,18.027 43.818,48.914 10.932,48.914 "
+ id="polygon3156"
+ style="fill:none;stroke:#ffffff;stroke-width:3.5;stroke-opacity:1" /><polyline
+ id="polyline3158"
+ points="43.818,18.027 31.874,18.027 31.874,6.088 "
+ style="fill:none;stroke:#ffffff;stroke-width:3.5;stroke-opacity:1" /></g></g><line
+ id="line3160"
+ y2="26.25"
+ y1="26.25"
+ x2="36.875"
+ x1="17.875"
+ display="inline"
+ style="fill:none;stroke:#ffffff;stroke-width:3.5;stroke-opacity:1;display:inline" /><line
+ id="line3162"
+ y2="33.25"
+ y1="33.25"
+ x2="36.875"
+ x1="17.875"
+ display="inline"
+ style="fill:none;stroke:#ffffff;stroke-width:3.5;stroke-opacity:1;display:inline" /><line
+ id="line3164"
+ y2="40.25"
+ y1="40.25"
+ x2="36.875"
+ x1="17.875"
+ display="inline"
+ style="fill:none;stroke:#ffffff;stroke-width:3.5;stroke-opacity:1;display:inline" /></g></svg> \ No newline at end of file
diff --git a/infoslicer/processing/Article_Builder.py b/infoslicer/processing/Article_Builder.py
index b6bd750..5d2a429 100644
--- a/infoslicer/processing/Article_Builder.py
+++ b/infoslicer/processing/Article_Builder.py
@@ -135,7 +135,7 @@ def get_article_from_dita(image_path, dita):
sentence_data_list.insert(0, picture_data)
article_title = input.find("title").renderContents().replace("\n", "").strip()
-
+
image_list = []
imglist_tag = input.find(True, attrs={"id" : "imagelist"})
if imglist_tag != None:
@@ -149,9 +149,9 @@ def get_article_from_dita(image_path, dita):
logger.info('cannot find image %s' % img['href'])
else:
image_list.append((img['href'], caption, img['orig_href']))
-
- data = Article_Data(article_id, article_id, article_title, "theme", section_data_list, image_list)
-
+
+ data = Article_Data(article_id, article_id, article_title, "theme", section_data_list, image_list)
+
return data
diff --git a/infoslicer/processing/HTML_strip.py b/infoslicer/processing/HTML_strip.py
new file mode 100644
index 0000000..cdd5108
--- /dev/null
+++ b/infoslicer/processing/HTML_strip.py
@@ -0,0 +1,89 @@
+# Copyright (C) 2012 Aneesh Dogra <lionaneesh@gmail.com>
+#
+# 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 HTMLParser import HTMLParser
+from re import sub
+from infoslicer.processing.Article_Data import Sentence_Data, \
+ Paragraph_Data, \
+ Section_Data, \
+ Article_Data
+import string
+
+def filter_non_printable(str):
+ return ''.join([c for c in str if ord(c) > 31 or ord(c) == 9])
+
+class HTML_Strip(HTMLParser):
+ def __init__(self):
+ HTMLParser.__init__(self)
+ self.__text = []
+
+ def handle_data(self, data):
+ text = data.strip()
+ if len(text) > 0:
+ text = sub('[\t\r\n]+', '', text)
+ # replace multiple spaces with one
+ text = sub('[ ]+', ' ', text)
+ text = filter_non_printable(text)
+ self.__text.append(text + '')
+
+ def handle_starttag(self, tag, attrs):
+ if tag == 'p':
+ self.__text.append('<PARAGRAPH>')
+ elif tag == 'br':
+ self.__text.append('<SENTENCE>')
+ if tag == 'div':
+ self.__text.append('<SECTION>')
+
+ def text(self):
+ return ''.join(self.__text).strip()
+
+
+# takes in a HTML document and returns a list of Section objects.
+def dehtml(text, title):
+ try:
+ parser = HTML_Strip()
+ parser.feed(text)
+ parser.close()
+ text_stripped = parser.text()
+ except:
+ text_stripped = text
+
+ # We now need to convert this stripped data to an
+ # Article Data object.
+ sections = text_stripped.split('<SECTION>')
+ section_objs = []
+ for section in sections:
+ s = section.strip()
+ if s:
+ paragraphs = text_stripped.split('<PARAGRAPH>')
+ p_objs = []
+ for para in paragraphs:
+ if para[:len('<SECTION>')] == '<SECTION>':
+ para = para[len('<SECTION>'):]
+ if para.endswith('<SECTION>'):
+ para = para[:-len('<SECTION>')]
+ p = para.strip()
+ if p:
+ sentences = para.split('<SENTENCE>')
+ s_objs = []
+ for sentence in sentences:
+ s = sentence.strip()
+ if s:
+ s_objs += [Sentence_Data(text=s)]
+ s_objs += [Sentence_Data(text='\n')]
+ p_objs += [Paragraph_Data(sentences_data=s_objs)]
+ section_objs += [Section_Data(paragraphs_data=p_objs)]
+ return Article_Data(article_title=title, sections_data=section_objs)
diff --git a/infoslicer/widgets/Gallery_View.py b/infoslicer/widgets/Gallery_View.py
index b46800c..7cd3ce8 100644
--- a/infoslicer/widgets/Gallery_View.py
+++ b/infoslicer/widgets/Gallery_View.py
@@ -24,18 +24,16 @@ class Gallery_View( Gtk.HBox ):
displays the images associated with that article, in a scrollable display.
- Drag-and-drop methods have been added to set up the images as a drag
- source.
- The data returned by drag-data-get will be a list containing
- an Image_Data object and a Sentence_Data object.
- These correspond to the image
- and caption respectively.
+ Drag-and-drop methods have been added to set up the images as a
+ drag source. The data returned by drag-data-get will be a list
+ containing an Image_Data object and a Sentence_Data object. These
+ correspond to the image and caption respectively.
"""
def __init__(self):
self.image_list = []
GObject.GObject.__init__(self)
-
+ self.set_size_request(int(Gdk.Screen.width() / 2), -1)
self.current_index = -1
left_button = Gtk.Button(label="\n\n << \n\n")
@@ -54,17 +52,19 @@ class Gallery_View( Gtk.HBox ):
Gdk.DragAction.COPY)
self.imagebox.drag_source_add_image_targets()
self.imagebox.connect("drag-begin", self.drag_begin_event, None)
- logging.debug('##################### Galler_View.connect')
+ logging.debug('##################### Gallery_View.connect')
self.imagebox.connect("drag-data-get", self.drag_data_get_event, None)
self.caption = Gtk.Label(label="")
+ self.caption.set_size_request(int(Gdk.Screen.width() / 3), -1)
self.caption.set_line_wrap(True)
+ self.caption.set_max_width_chars(40)
self.image_drag_container = Gtk.VBox()
self.image_drag_container.pack_start(self.imagenumberlabel, expand=False,
fill=False, padding=0)
- self.image_drag_container.pack_start(self.imagebox, False, True, 0)
- self.image_drag_container.pack_start(self.caption, False, True, 0)
+ self.image_drag_container.pack_start(self.imagebox, False, False, 0)
+ self.image_drag_container.pack_start(self.caption, False, False, 0)
image_container = Gtk.VBox()
image_container.pack_start(Gtk.Label(" "), True, True, 0)
diff --git a/infoslicer/widgets/Journal_Gallery_View.py b/infoslicer/widgets/Journal_Gallery_View.py
new file mode 100644
index 0000000..5358d05
--- /dev/null
+++ b/infoslicer/widgets/Journal_Gallery_View.py
@@ -0,0 +1,168 @@
+# -*- coding: utf-8 -*-
+# Copyright (C) Aneesh Dogra <lionaneesh@gmail.com>
+#
+# 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 General Public License
+# along with this library; if not, write to the Free Software
+# Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA
+
+from gi.repository import Gtk
+from gi.repository import Gdk
+from gi.repository import GObject
+from gi.repository import GdkPixbuf
+import os
+import cPickle
+import pickle
+import logging
+
+from Editable_Textbox import Editable_Textbox
+from infoslicer.processing.Article_Data import *
+from infoslicer.processing.Article import Article
+import book
+# from infoslicer.processing import Journal_Getter as journal
+
+logger = logging.getLogger('infoslicer')
+
+# For journal images
+IMG_WIDTH = 400
+IMG_HEIGHT = 300
+
+class Journal_Gallery_View( Gtk.HBox ):
+ """
+ Created by Aneesh Dogra
+ Journal Gallery View
+
+ The journal gallery view displays the jounal images.
+
+ Drag-and-drop methods have been added to set up the images as a drag
+ source.
+ The data returned by drag-data-get will be a list containing
+ an Image_Data object and a Sentence_Data object.
+ These correspond to the image
+ and caption respectively.
+ """
+
+ def __init__(self):
+ self.image_list = []
+ GObject.GObject.__init__(self)
+ self.current_index = -1
+ self.source_article_id = -1
+ left_button = Gtk.Button(label="\n\n << \n\n")
+ right_button = Gtk.Button(label="\n\n >> \n\n")
+ self.imagenumberlabel = Gtk.Label()
+ self.image = Gtk.Image()
+ self.imagebox = Gtk.EventBox()
+ self.imagebox.add(self.image)
+ self.imagebox.drag_source_set(Gdk.ModifierType.BUTTON1_MASK,
+ [],
+ Gdk.DragAction.COPY)
+ self.imagebox.drag_source_add_image_targets()
+ self.imagebox.connect("drag-begin", self.drag_begin_event, None)
+ logging.debug('##################### Galler_View.connect')
+ self.imagebox.connect("drag-data-get", self.drag_data_get_event, None)
+
+ self.caption = Gtk.Label(label="")
+ self.caption.set_line_wrap(True)
+
+ self.image_drag_container = Gtk.VBox()
+ self.image_drag_container.pack_start(self.imagenumberlabel, expand=False,
+ fill=False, padding=0)
+ self.image_drag_container.pack_start(self.imagebox, False, True, 0)
+ self.image_drag_container.pack_start(self.caption, False, True, 0)
+
+ image_container = Gtk.VBox()
+ image_container.pack_start(Gtk.Label(" "), True, True, 0)
+ image_container.pack_start(self.image_drag_container, False, True, 0)
+ image_container.pack_start(Gtk.Label(" "), True, True, 0)
+
+ left_button_container = Gtk.VBox()
+ left_button_container.pack_start(Gtk.Label(" "), True, True, 0)
+ left_button_container.pack_start(left_button, False, True, 0)
+ left_button_container.pack_start(Gtk.Label(" "), True, True, 0)
+
+ right_button_container = Gtk.VBox()
+ right_button_container.pack_start(Gtk.Label(" "), True, True, 0)
+ right_button_container.pack_start(right_button, False, True, 0)
+ right_button_container.pack_start(Gtk.Label(" "), True, True, 0)
+
+
+ self.pack_start(left_button_container, False, True, 0)
+ self.pack_start(image_container, True, True, 0)
+ self.pack_start(right_button_container, False, True, 0)
+
+ self.show_all()
+ right_button.connect("clicked", self.get_next_item, None)
+ left_button.connect("clicked", self.get_prev_item, None)
+ self.get_next_item(right_button, None)
+
+ def get_next_item(self, button, param):
+ if self.image_list == []:
+ self.caption.set_text("No images were found in the journal.")
+ self.image.clear()
+ return
+ self.current_index += 1
+ if self.current_index == len(self.image_list):
+ self.current_index = 0
+ self.imagebuf = GdkPixbuf.Pixbuf.new_from_file(self.image_list[self.current_index][0])
+ self.imagebuf = self.imagebuf.scale_simple(IMG_WIDTH, IMG_HEIGHT,
+ GdkPixbuf.InterpType.BILINEAR)
+ self.image.set_from_pixbuf(self.imagebuf)
+ self.caption.set_text("\n" + self.image_list[self.current_index][1])
+ self.imagenumberlabel.set_text("(%d / %d)\n" % (self.current_index+1, len(self.image_list)))
+
+ def get_prev_item(self, button, param):
+ if self.image_list == []:
+ self.caption.set_text("No images were found in the journal.")
+ self.image.clear()
+ return
+ if self.current_index == 0:
+ self.current_index = len(self.image_list)
+ self.current_index -= 1
+ self.imagebuf = GdkPixbuf.Pixbuf.new_from_file(self.image_list[self.current_index][0])
+ self.imagebuf = self.imagebuf.scale_simple(IMG_WIDTH, IMG_HEIGHT,
+ GdkPixbuf.InterpType.BILINEAR)
+ self.image.set_from_pixbuf(self.imagebuf)
+ self.caption.set_text("\n" + self.image_list[self.current_index][1])
+ self.imagenumberlabel.set_text("(%d / %d)\n" % (self.current_index+1, len(self.image_list)))
+
+ def get_first_item(self):
+ if self.image_list == []:
+ self.caption.set_text("No images were found in the journal.")
+ self.image.clear()
+ return
+ self.current_index = 0
+ self.imagebuf = GdkPixbuf.Pixbuf.new_from_file(self.image_list[self.current_index][0])
+ self.imagebuf = self.imagebuf.scale_simple(IMG_WIDTH, IMG_HEIGHT,
+ GdkPixbuf.InterpType.BILINEAR)
+ self.image.set_from_pixbuf(self.imagebuf)
+ self.caption.set_text("\n" + self.image_list[self.current_index][1])
+ logger.debug("setting text to:")
+ logger.debug("(%d / %d)\n" %
+ (self.current_index+1, len(self.image_list)))
+ self.imagenumberlabel.set_text("(%d / %d)\n" % (self.current_index+1, len(self.image_list)))
+
+ def drag_begin_event(self, widget, context, data):
+ logging.debug('########### Journal_Journal_Gallery_View.drag_begin_event called')
+ self.imagebox.drag_source_set_icon_pixbuf(self.imagebuf)
+
+ def drag_data_get_event(self, widget, context, selection_data, info, timestamp, data):
+ logger.debug('############# Journal_Journal_Gallery_View.drag_data_get_event')
+ atom = Gdk.atom_intern("section", only_if_exists=False)
+ imagedata = Picture_Data(self.source_article_id,
+ self.image_list[self.current_index][0])
+ captiondata = Sentence_Data(0, self.source_article_id, 0, 0, 0, self.image_list[self.current_index][1])
+ paragraph1data = Paragraph_Data(0, self.source_article_id, 0, 0, [imagedata])
+ paragraph2data = Paragraph_Data(0, self.source_article_id, 0, 0, [captiondata])
+ sectionsdata = [Section_Data(0, self.source_article_id, 0, [paragraph1data, paragraph2data])]
+ string = cPickle.dumps(sectionsdata)
+ selection_data.set(atom, 8, string)
+
+ def add_image(self, image_path, title):
+ logger.debug('############# Journal_Journal_Gallery_View.add_image')
+ self.image_list.append((image_path, title))
+ logger.debug(self.image_list)
+ self.get_first_item()
diff --git a/infoslicer/widgets/Journal_Image_Pane.py b/infoslicer/widgets/Journal_Image_Pane.py
new file mode 100644
index 0000000..38c1c23
--- /dev/null
+++ b/infoslicer/widgets/Journal_Image_Pane.py
@@ -0,0 +1,62 @@
+# Copyright (C) IBM Corporation 2008
+import gi
+gi.require_version('Gtk', '3.0')
+from gi.repository import Gtk
+from gi.repository import Gdk
+from gi.repository import GObject
+import logging
+
+from gettext import gettext as _
+from Editing_View import Editing_View
+from infoslicer.widgets.Journal_Gallery_View import Journal_Gallery_View
+from infoslicer.processing.Article import Article
+
+logger = logging.getLogger('infoslicer')
+
+class Journal_Image_Pane(Gtk.HBox):
+ """
+ Created by Aneesh Dogra
+
+ See __init__.py for overview of panes.
+
+ The Image Pane gives a side-by-side view of the jounal images and edit article.
+ The left hand side shows the jounal images. These can be dragged into
+ the edit article.
+ """
+
+ def __init__(self):
+ GObject.GObject.__init__(self)
+ self.toolitems = []
+
+ gallery_box = Gtk.VBox()
+ gallery_box.show()
+
+ labeleb = Gtk.EventBox()
+ labeleb.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("#EEEEEE"))
+ gallery_box.pack_start(labeleb, False, False, 0)
+ labeleb.show()
+
+ self.articletitle = Gtk.Label()
+ self.articletitle.set_justify(Gtk.Justification.CENTER)
+ labeleb.add(self.articletitle)
+ self.articletitle.show()
+
+ self.gallery = Journal_Gallery_View()
+ self.gallery.set_size_request(Gdk.Screen.width()/2, -1)
+ gallery_box.pack_start(self.gallery, True, True, 0)
+
+ self.pack_start(gallery_box, False, False, 0)
+
+ self.editarticle = Editing_View()
+ self.pack_start(self.editarticle, True, True, 0)
+ self.editarticle.show_all()
+
+ def set_working_article(self, article):
+ logger.debug("working received, title %s" % article.article_title)
+
+ self.editarticle.articletitle.set_markup(
+ "<span size='medium'><b> %s </b> %s</span>"% \
+ (_("Article:"), article.article_title))
+
+ if self.editarticle.textbox.get_article() != article:
+ self.editarticle.textbox.set_article(article)
diff --git a/library.py b/library.py
index 3087072..920c819 100644
--- a/library.py
+++ b/library.py
@@ -91,7 +91,7 @@ class View(Gtk.EventBox):
search_box.pack_start(self.wikimenu, False, False, 0)
self.searchentry = Gtk.Entry()
- self.searchentry.set_size_request(int(Gdk.Screen.width() / 4), -1)
+ self.searchentry.set_size_request(int(Gdk.Screen.width() / 6), -1)
self.searchentry.set_text(_("Article name"))
self.searchentry.select_region(0, -1)
self.searchentry.connect('activate', self._search_activate_cb)
@@ -119,8 +119,10 @@ class View(Gtk.EventBox):
wiki_box.pack_start(search_box, False, False, 0)
wiki_box.pack_start(wiki, True, True, 0)
wiki_box.pack_start(self.progress, False, False, 0)
- wiki_box.set_size_request(Gdk.Screen.width()/4*3,
- Gdk.Screen.height()/2 - style.GRID_CELL_SIZE / 2)
+ logging.debug(int(Gdk.Screen.width() * 3 / 4.))
+ wiki_box.set_size_request(int(Gdk.Screen.width() * 3 / 4.),
+ int((Gdk.Screen.height() - \
+ style.GRID_CELL_SIZE) / 2))
custom_widget = Reading_View()
custom = Gtk.Notebook()
@@ -130,8 +132,9 @@ class View(Gtk.EventBox):
custom.append_page(custom_widget, None)
# custom.set_size_request(Gdk.Screen.width()/4*3,
# Gdk.Screen.height()/2 - 55)
- custom.set_size_request(Gdk.Screen.width()/4*3,
- Gdk.Screen.height()/2 - style.GRID_CELL_SIZE / 2)
+ custom.set_size_request(int(Gdk.Screen.width() * 3 / 4.),
+ int((Gdk.Screen.height() - \
+ style.GRID_CELL_SIZE) / 2))
# workspace
@@ -236,8 +239,9 @@ class ToolbarBuilder():
def _publish_clicked_cb(self, widget):
xol.publish(self.activity)
-WIKI = { _("English Wikipedia") : "en.wikipedia.org",
- _("Simple English Wikipedia") : "simple.wikipedia.org",
- _("German Wikipedia") : "de.wikipedia.org",
- _("Spanish Wikipedia") : "es.wikipedia.org",
- _("French Wikipedia") : "fr.wikipedia.org" }
+WIKI = { _('English Wikipedia') : 'en.wikipedia.org',
+ _('Simple English Wikipedia') : 'simple.wikipedia.org',
+ _('French Wikipedia') : 'fr.wikipedia.org',
+ _('German Wikipedia') : 'de.wikipedia.org',
+ _('Polish Wikipedia') : 'pl.wikipedia.org',
+ _('Spanish Wikipedia') : 'es.wikipedia.org'}