Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/bookview.py
diff options
context:
space:
mode:
Diffstat (limited to 'bookview.py')
-rw-r--r--bookview.py139
1 files changed, 57 insertions, 82 deletions
diff --git a/bookview.py b/bookview.py
index 197b2a3..8b049d6 100644
--- a/bookview.py
+++ b/bookview.py
@@ -13,74 +13,65 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import os
-from gi.repository import Gtk
+import gtk
import logging
-from gi.repository import GObject
+import gobject
from gettext import gettext as _
-from sugar3.graphics.toolbutton import ToolButton
-from sugar3.activity.activity import get_bundle_path, get_activity_root
-from sugar3.graphics.style import *
+from sugar.graphics.toolbutton import ToolButton
+from sugar.activity.activity import get_bundle_path, get_activity_root
+from sugar.graphics.style import *
+from port.widgets import ToolWidget, ToolButton
logger = logging.getLogger('infoslicer')
PUBLISH = 0
TITLE = 1
-class BookView(Gtk.VBox):
+class BookView(gtk.VBox):
def sync(self):
if not self._changing:
return
- GObject.source_remove(self._changing)
+ gobject.source_remove(self._changing)
index, column = self.tree.get_cursor()
self._cursor_changed(index)
def __init__(self, book, name, tooltip, custom):
- GObject.GObject.__init__(self)
+ gtk.VBox.__init__(self)
self.book = book
self._changing = None
self._check = None
- title = Gtk.Toolbar()
+ title = gtk.Toolbar()
# title checkbox
if custom:
- self._check = Gtk.CheckButton()
+ self._check = gtk.CheckButton()
self._check.props.can_focus = False
self._check.props.tooltip_text = \
_('Articles are ready to be published')
self._check.connect('toggled', self._check_toggled_cb)
- check_box = Gtk.HBox()
+ check_box = gtk.HBox()
check_box.set_size_request(50, -1)
- check_box.pack_start(self._check, True, False, 0)
- tool_item = Gtk.ToolItem()
- tool_item.add(check_box)
- tool_item.show()
- title.insert(tool_item, -1)
+ check_box.pack_start(self._check, True, False)
+ title.insert(ToolWidget(check_box), -1)
else:
- tool_item = Gtk.ToolItem()
- tool_item.add(Gtk.Label(label=' '))
- tool_item.show()
- title.insert(tool_item, -1)
+ title.insert(ToolWidget(gtk.Label(' ')), -1)
# title caption
- caption_label = Gtk.Label(label=name)
+ caption_label = gtk.Label(name)
caption_label.props.tooltip_text = tooltip
- caption_label.modify_fg(Gtk.StateType.NORMAL, COLOR_WHITE.get_gdk_color())
- caption_box = Gtk.HBox()
- caption_box.pack_start(caption_label, False, False, 0)
- caption = Gtk.EventBox()
+ caption_label.modify_fg(gtk.STATE_NORMAL, COLOR_WHITE.get_gdk_color())
+ caption_box = gtk.HBox()
+ caption_box.pack_start(caption_label, False)
+ caption = gtk.EventBox()
caption.add(caption_box)
- caption.modify_bg(Gtk.StateType.NORMAL, COLOR_TOOLBAR_GREY.get_gdk_color())
+ caption.modify_bg(gtk.STATE_NORMAL, COLOR_TOOLBAR_GREY.get_gdk_color())
+ title.insert(ToolWidget(caption), -1)
- tool_item = Gtk.ToolItem()
- tool_item.add(caption)
- tool_item.show()
- title.insert(tool_item, -1)
-
- separator = Gtk.SeparatorToolItem()
+ separator = gtk.SeparatorToolItem()
separator.props.draw = False
separator.set_expand(True)
title.insert(separator, -1)
@@ -88,8 +79,9 @@ class BookView(Gtk.VBox):
# create article button
if custom:
- create = ToolButton('add')
- create.set_tooltip(_('Create new article'))
+ create = ToolButton('add',
+ padding=0,
+ tooltip=_('Create new article'))
create.connect('clicked', self._create_cb)
title.insert(create, -1)
else:
@@ -98,71 +90,57 @@ class BookView(Gtk.VBox):
# delete article button
- delete = ToolButton('edit-delete')
- delete.set_tooltip(_('Delete current article'))
+ delete = ToolButton('edit-delete',
+ padding=0,
+ tooltip=_('Delete current article'))
delete.connect('clicked', self._delete_cb)
title.insert(delete, -1)
# move buttons
- downward = ToolButton('down')
- downward.set_tooltip(_('Move article downward'))
+ downward = ToolButton('down',
+ padding=0,
+ tooltip=_('Move article downward'))
downward.connect('clicked', self._swap_cb, +1)
title.insert(downward, -1)
-
- upward = ToolButton('up')
- upward.set_tooltip(_('Move article upward'))
+ upward = ToolButton('up',
+ padding=0,
+ tooltip=_('Move article upward'))
upward.connect('clicked', self._swap_cb, -1)
title.insert(upward, -1)
# tree
- self.store = Gtk.ListStore(bool, str)
- self.tree = Gtk.TreeView(self.store)
+ self.store = gtk.ListStore(bool, str)
+ self.tree = gtk.TreeView(self.store)
self.tree.props.headers_visible = False
self.tree.connect('cursor-changed', self._cursor_changed_cb)
- cell = Gtk.CellRendererToggle()
+ cell = gtk.CellRendererToggle()
cell.connect('toggled', self._cell_toggled_cb)
cell.props.activatable = True
- # FIXME: insert_column_with_attributes does not exist on pygobject
- # column = self.tree.insert_column_with_attributes(0, '', cell, active=0)
-
- logging.debug('TODO: this is a workaround due '
- 'https://bugzilla.gnome.org/show_bug.cgi?id=679415')
-
- column = Gtk.TreeViewColumn('Wiki', cell)
- column.props.sizing = Gtk.TreeViewColumnSizing.FIXED
+ column = self.tree.insert_column_with_attributes(0, '', cell, active=0)
+ column.props.sizing = gtk.TREE_VIEW_COLUMN_FIXED
column.props.fixed_width = 50
column.props.visible = custom
- self.tree.insert_column(column, 0)
-
- cell = Gtk.CellRendererText()
+ cell = gtk.CellRendererText()
cell.connect('edited', self._cell_edited_cb)
cell.props.editable = True
-
- # FIXME: insert_column_with_attributes does not exist on pygobject
- # self.tree.insert_column_with_attributes(1, '', cell, text=1)
-
- logging.debug('TODO: this is a workaround due '
- 'https://bugzilla.gnome.org/show_bug.cgi?id=679415')
-
- column = Gtk.TreeViewColumn('Custom', cell, text=1)
- self.tree.insert_column(column, 1)
+ self.tree.insert_column_with_attributes(1, '', cell, text=1)
for i in self.book.index:
self.store.append((i['ready'], i['title']))
# scrolled tree
- tree_scroll = Gtk.ScrolledWindow()
- tree_scroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
+ tree_scroll = gtk.ScrolledWindow()
+ tree_scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
tree_scroll.add(self.tree)
- self.pack_start(title, False, False, 0)
- self.pack_start(tree_scroll, True, True, 0)
+ self.pack_start(title, False)
+ self.pack_start(tree_scroll)
if len(self.store):
self.tree.set_cursor(0, self.tree.get_column(1), False)
@@ -185,7 +163,7 @@ class BookView(Gtk.VBox):
return find_name(list, prefix, uniq+1)
if self._changing:
- GObject.source_remove(self._changing)
+ gobject.source_remove(self._changing)
self._changing = None
name = find_name(self.store, _('New article'), 0)
@@ -195,17 +173,15 @@ class BookView(Gtk.VBox):
self._update_check(self.store[-1][PUBLISH])
def _delete_cb(self, widget):
- path, focus_column = self.tree.get_cursor()
-
- if not path:
+ index, column = self.tree.get_cursor()
+ if not index:
return
+ index = index[0]
if self._changing:
- GObject.source_remove(self._changing)
+ gobject.source_remove(self._changing)
self._changing = None
- index = path.get_indices()[0]
-
self.book.remove(self.store[index][TITLE])
self.store.remove(self.tree.props.model.get_iter(index))
@@ -216,16 +192,15 @@ class BookView(Gtk.VBox):
self._update_check(self.store[index][PUBLISH])
def _swap_cb(self, widget, delta):
- path, focus_column = self.tree.get_cursor()
-
- if not path:
+ old_index, column = self.tree.get_cursor()
+ if not old_index:
return
- old_index = path.get_indices()[0]
+ old_index = old_index[0]
new_index = old_index + delta
if new_index < 0:
- new_index = len(self.store) - 1
+ new_index = len(self.store)-1
elif new_index >= len(self.store):
new_index = 0
@@ -259,12 +234,12 @@ class BookView(Gtk.VBox):
def _cursor_changed_cb(self, widget):
if self._changing:
- GObject.source_remove(self._changing)
+ gobject.source_remove(self._changing)
index, column = self.tree.get_cursor()
if index != None:
- self._changing = GObject.timeout_add(500, self._cursor_changed,
+ self._changing = gobject.timeout_add(500, self._cursor_changed,
index)
def _cursor_changed(self, index):