From 03ac155514625f2380c13712c80eb03d538bcd28 Mon Sep 17 00:00:00 2001 From: flavio Date: Wed, 24 Oct 2012 21:48:07 +0000 Subject: Port Gtk 3 --- diff --git a/.gitignore b/.gitignore index 68d0d43..8da010e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,6 @@ .ropeproject/ *.e4p *.pyc +*.bak dist/ diff --git a/activity/activity.info b/activity/activity.info index f7f075b..de54096 100644 --- a/activity/activity.info +++ b/activity/activity.info @@ -1,8 +1,8 @@ [Activity] name = Sugar Commander -service_name = org.laptop.sugar.SugarCommander +bundle_id = org.laptop.sugar.SugarCommander icon = scommander exec = sugar-activity sugarcommander.SugarCommander show_launcher = yes -activity_version = 8 +activity_version = 9 license = GPLv2+ diff --git a/iconview.py b/iconview.py index a8c273a..77043ce 100755 --- a/iconview.py +++ b/iconview.py @@ -1,12 +1,12 @@ #! /usr/bin/env python -import pygtk -pygtk.require('2.0') +import gi +from gi.repository import Gtk +from gi.repository import Gdk +from gi.repository import GdkPixbuf import getopt import sys -import gtk -import gtk.gdk def extract_filename(filename): partition_tuple = filename.rpartition('/') @@ -14,13 +14,13 @@ def extract_filename(filename): def make_iconview(args): # First create an iconview - view = gtk.IconView() + view = Gtk.IconView() # Create a store for our iconview and fill it with stock icons - store = gtk.ListStore(str, gtk.gdk.Pixbuf) + store = Gtk.ListStore(str, GdkPixbuf.Pixbuf) i = 0 while i < len(args): - scaled_pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(args[i], 160, 120) + scaled_pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(args[i], 160, 120) filename = extract_filename(args[i]) store.append(['%s' % filename, scaled_pixbuf]) i = i + 1 @@ -32,16 +32,16 @@ def make_iconview(args): view.set_pixbuf_column(1) # Pack our iconview into a scrolled window - swin = gtk.ScrolledWindow() - swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) + swin = Gtk.ScrolledWindow() + swin.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) swin.add_with_viewport(view) swin.show_all() # pack the scrolled window into a simple dialog and run it - dialog = gtk.Dialog('IconView Demo') - close = dialog.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_NONE) + dialog = Gtk.Dialog('IconView Demo') + close = dialog.add_button(Gtk.STOCK_CLOSE, Gtk.RESPONSE_NONE) dialog.set_default_size(1024,800) - dialog.vbox.pack_start(swin) + dialog.vbox.pack_start(swin, False, False, 0) dialog.run() if __name__ == "__main__": diff --git a/resizepics.py b/resizepics.py index 23cee7e..6672c7f 100755 --- a/resizepics.py +++ b/resizepics.py @@ -19,7 +19,9 @@ import getopt import sys import os -import gtk +import gi +from gi.repository import Gtk +from gi.repository import GdkPixbuf import pygame SCREEN_WIDTH = 1200 @@ -36,7 +38,7 @@ def resize_image(filename): if image_width <= SCREEN_WIDTH: resize_to_width = image_width try: - scaled_pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(filename, resize_to_width, ARBITRARY_LARGE_HEIGHT) + scaled_pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(filename, resize_to_width, ARBITRARY_LARGE_HEIGHT) scaled_pixbuf.save(filename, "jpeg", {"quality":"%d" % JPEG_QUALITY}) except: print 'File could not be converted' diff --git a/setup.py b/setup.py index d3ab3a3..2f2c143 100755 --- a/setup.py +++ b/setup.py @@ -16,6 +16,6 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -from sugar.activity import bundlebuilder +from sugar3.activity import bundlebuilder bundlebuilder.start() diff --git a/sugarcommander.py b/sugarcommander.py index daf46f3..58b2b52 100755 --- a/sugarcommander.py +++ b/sugarcommander.py @@ -18,19 +18,37 @@ import logging import os import time -import gtk -import pango +import gi +from gi.repository import Gtk +from gi.repository import Pango +from gi.repository import GObject +from gi.repository import Gio +from gi.repository import GdkPixbuf import pygame import zipfile -from sugar import mime -from sugar.activity import activity -from sugar.datastore import datastore -from sugar.graphics.alert import NotifyAlert -from sugar.graphics import style +from sugar3 import mime +from sugar3.activity import activity +from sugar3.graphics.toolbarbox import ToolbarBox +from sugar3.activity.widgets import StopButton +from sugar3.datastore import datastore +from sugar3.graphics.alert import NotifyAlert +from sugar3.graphics import style from gettext import gettext as _ -import gobject import dbus +def get_mounts(): + + volume_monitor = Gio.VolumeMonitor.get() + + mounts = [] + for mount in volume_monitor.get_mounts(): + description = {} + description['mount_path'] = mount.get_default_location().get_path() + description['label'] = mount.get_name() + mounts.append(description) + + return mounts + COLUMN_TITLE = 0 COLUMN_SIZE = 1 COLUMN_MIME = 2 @@ -46,7 +64,7 @@ DS_DBUS_PATH = '/org/laptop/sugar/DataStore' _logger = logging.getLogger('sugar-commander') class SugarCommander(activity.Activity): - def __init__(self, handle, create_jobject=True): + def __init__(self, handle): "The entry point to the Activity" activity.Activity.__init__(self, handle) self.selected_journal_entry = None @@ -54,204 +72,237 @@ class SugarCommander(activity.Activity): self.update_log_entries = '' self.close_requested = False - canvas = gtk.Notebook() + canvas = Gtk.Notebook() canvas.props.show_border = True canvas.props.show_tabs = True canvas.show() - self.ls_journal = gtk.ListStore(gobject.TYPE_STRING, - gobject.TYPE_UINT64, - gobject.TYPE_STRING, - gobject.TYPE_PYOBJECT) - self.tv_journal = gtk.TreeView(self.ls_journal) + self.ls_journal = Gtk.ListStore(GObject.TYPE_STRING, + GObject.TYPE_UINT64, + GObject.TYPE_STRING, + GObject.TYPE_PYOBJECT) + self.tv_journal = Gtk.TreeView(self.ls_journal) self.tv_journal.set_rules_hint(True) self.tv_journal.set_search_column(COLUMN_TITLE) self.selection_journal = self.tv_journal.get_selection() - self.selection_journal.set_mode(gtk.SELECTION_SINGLE) + self.selection_journal.set_mode(Gtk.SelectionMode.SINGLE) self.selection_journal.connect("changed", self.selection_journal_cb) - renderer = gtk.CellRendererText() - renderer.set_property('wrap-mode', gtk.WRAP_WORD) + renderer = Gtk.CellRendererText() + renderer.set_property('wrap-mode', Gtk.WrapMode.WORD) renderer.set_property('wrap-width', 500) renderer.set_property('width', 500) - self.col_journal = gtk.TreeViewColumn(_('Title'), renderer, + self.col_journal = Gtk.TreeViewColumn(_('Title'), renderer, text=COLUMN_TITLE) self.col_journal.set_sort_column_id(COLUMN_TITLE) self.tv_journal.append_column(self.col_journal) - size_renderer = gtk.CellRendererText() + size_renderer = Gtk.CellRendererText() size_renderer.set_property('width', 100) - size_renderer.set_property('alignment', pango.ALIGN_RIGHT) + size_renderer.set_property('alignment', Pango.Alignment.RIGHT) size_renderer.set_property('xalign', 0.8) - self.col_size = gtk.TreeViewColumn(_('Size (KB)'), size_renderer, + self.col_size = Gtk.TreeViewColumn(_('Size (KB)'), size_renderer, text=COLUMN_SIZE) self.col_size.set_sort_column_id(COLUMN_SIZE) self.tv_journal.append_column(self.col_size) - mime_renderer = gtk.CellRendererText() + mime_renderer = Gtk.CellRendererText() mime_renderer.set_property('width', 200) - self.col_mime = gtk.TreeViewColumn(_('MIME Type'), mime_renderer, + self.col_mime = Gtk.TreeViewColumn(_('MIME Type'), mime_renderer, text=COLUMN_MIME) self.col_mime.set_sort_column_id(COLUMN_MIME) self.tv_journal.append_column(self.col_mime) - self.list_scroller_journal = gtk.ScrolledWindow( + self.list_scroller_journal = Gtk.ScrolledWindow( hadjustment=None, vadjustment=None) self.list_scroller_journal.set_policy( - gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) + Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) self.list_scroller_journal.add(self.tv_journal) - label_attributes = pango.AttrList() - label_attributes.insert(pango.AttrSize(14000, 0, -1)) - label_attributes.insert(pango.AttrForeground(65535, 65535, 65535, 0, -1)) + label_attributes = Pango.AttrList() + # FIXME: Reescribir + #label_attributes.insert(Pango.AttrSize(14000, 0, -1)) + #label_attributes.insert(Pango.AttrForeground(65535, 65535, 65535, 0, -1)) - tab1_label = gtk.Label(_("Journal")) + tab1_label = Gtk.Label(_("Journal")) tab1_label.set_attributes(label_attributes) tab1_label.show() self.tv_journal.show() self.list_scroller_journal.show() - column_table = gtk.Table(rows=1, columns=2, homogeneous = False) + column_table = Gtk.Table(rows=1, columns=2, homogeneous = False) - image_table = gtk.Table(rows=2, columns=2, homogeneous=False) - self.image = gtk.Image() - image_table.attach(self.image, 0, 2, 0, 1, xoptions=gtk.FILL|gtk.SHRINK, - yoptions=gtk.FILL|gtk.SHRINK, xpadding=10, ypadding=10) - - self.dimension_label = gtk.Label("") - image_table.attach(self.dimension_label, 0, 2, 1, 2, xoptions=gtk.SHRINK, - yoptions=gtk.SHRINK, xpadding=10, ypadding=10) - - self.btn_resize = gtk.Button(_("Resize To Width")) - self.btn_resize.connect('button_press_event', + image_table = Gtk.Table(rows=2, columns=2, homogeneous=False) + self.image = Gtk.Image() + image_table.attach(self.image, 0, 2, 0, 1, + xoptions=Gtk.AttachOptions.FILL | + Gtk.AttachOptions.SHRINK, + yoptions=Gtk.AttachOptions.FILL | + Gtk.AttachOptions.SHRINK, + xpadding=10, ypadding=10) + + self.dimension_label = Gtk.Label("") + image_table.attach(self.dimension_label, 0, 2, 1, 2, + xoptions=Gtk.AttachOptions.SHRINK, + yoptions=Gtk.AttachOptions.SHRINK, + xpadding=10, ypadding=10) + + self.btn_resize = Gtk.Button(_("Resize To Width")) + self.btn_resize.connect('button_press_event', self.resize_button_press_event_cb) - image_table.attach(self.btn_resize, 0, 1, 2, 3, xoptions=gtk.SHRINK, - yoptions=gtk.SHRINK, xpadding=10, ypadding=10) - - self.resize_width_entry = gtk.Entry(max=4) - image_table.attach(self.resize_width_entry, 1, 2, 2, 3, - xoptions=gtk.SHRINK, - yoptions=gtk.SHRINK, xpadding=10, ypadding=10) + image_table.attach(self.btn_resize, 0, 1, 2, 3, + xoptions=Gtk.AttachOptions.SHRINK, + yoptions=Gtk.AttachOptions.SHRINK, + xpadding=10, ypadding=10) + + self.resize_width_entry = Gtk.Entry() + self.resize_width_entry.set_max_length(4) + image_table.attach(self.resize_width_entry, 1, 2, 2, 3, + xoptions=Gtk.AttachOptions.SHRINK, + yoptions=Gtk.AttachOptions.SHRINK, + xpadding=10, ypadding=10) self.resize_width_entry.set_text('600') - self.resize_width_entry.connect('key_press_event', + self.resize_width_entry.connect('key_press_event', self.resize_key_press_event_cb) - self.btn_save = gtk.Button(_("Save")) - self.btn_save.connect('button_press_event', + self.btn_save = Gtk.Button(_("Save")) + self.btn_save.connect('button_press_event', self.save_button_press_event_cb) - image_table.attach(self.btn_save, 0, 1, 3, 4, xoptions=gtk.SHRINK, - yoptions=gtk.SHRINK, xpadding=10, ypadding=10) + image_table.attach(self.btn_save, 0, 1, 3, 4, + xoptions=Gtk.AttachOptions.SHRINK, + yoptions=Gtk.AttachOptions.SHRINK, + xpadding=10, ypadding=10) self.btn_save.props.sensitive = False self.btn_save.show() - self.btn_delete = gtk.Button(_("Delete")) - self.btn_delete.connect('button_press_event', + self.btn_delete = Gtk.Button(_("Delete")) + self.btn_delete.connect('button_press_event', self.delete_button_press_event_cb) - image_table.attach(self.btn_delete, 1, 2, 3, 4, xoptions=gtk.SHRINK, - yoptions=gtk.SHRINK, xpadding=10, ypadding=10) + image_table.attach(self.btn_delete, 1, 2, 3, 4, + xoptions=Gtk.AttachOptions.SHRINK, + yoptions=Gtk.AttachOptions.SHRINK, + xpadding=10, ypadding=10) self.btn_delete.props.sensitive = False self.btn_delete.show() - entry_table = gtk.Table(rows=3, columns=2, + entry_table = Gtk.Table(rows=3, columns=2, homogeneous=False) - title_label = gtk.Label(_("Title")) - entry_table.attach(title_label, 0, 1, 0, 1, - xoptions=gtk.SHRINK, - yoptions=gtk.SHRINK, - xpadding=10, ypadding=10) + title_label = Gtk.Label(_("Title")) + entry_table.attach(title_label, 0, 1, 0, 1, + xoptions=Gtk.AttachOptions.SHRINK, + yoptions=Gtk.AttachOptions.SHRINK, + xpadding=10, ypadding=10) title_label.show() - self.title_entry = gtk.Entry(max=0) - entry_table.attach(self.title_entry, 1, 2, 0, 1, - xoptions=gtk.FILL|gtk.SHRINK, - yoptions=gtk.SHRINK, xpadding=10, ypadding=10) - self.title_entry.connect('key_press_event', + self.title_entry = Gtk.Entry() + self.resize_width_entry.set_max_length(4) + entry_table.attach(self.title_entry, 1, 2, 0, 1, + xoptions=Gtk.AttachOptions.FILL | + Gtk.AttachOptions.SHRINK, + yoptions=Gtk.AttachOptions.SHRINK, + xpadding=10, ypadding=10) + self.title_entry.connect('key_press_event', self.key_press_event_cb) self.title_entry.show() - description_label = gtk.Label(_("Description")) - entry_table.attach(description_label, 0, 1, 1, 2, - xoptions=gtk.SHRINK, - yoptions=gtk.SHRINK, - xpadding=10, ypadding=10) + description_label = Gtk.Label(_("Description")) + entry_table.attach(description_label, 0, 1, 1, 2, + xoptions=Gtk.AttachOptions.SHRINK, + yoptions=Gtk.AttachOptions.SHRINK, + xpadding=10, ypadding=10) description_label.show() - self.description_textview = gtk.TextView() - self.description_textview.set_wrap_mode(gtk.WRAP_WORD) - entry_table.attach(self.description_textview, 1, 2, 1, 2, - xoptions=gtk.EXPAND|gtk.FILL|gtk.SHRINK, - yoptions=gtk.EXPAND|gtk.FILL|gtk.SHRINK, - xpadding=10, ypadding=10) + self.description_textview = Gtk.TextView() + self.description_textview.set_wrap_mode(Gtk.WrapMode.WORD) + entry_table.attach(self.description_textview, 1, 2, 1, 2, + xoptions=Gtk.AttachOptions.EXPAND | + Gtk.AttachOptions.FILL | + Gtk.AttachOptions.SHRINK, + yoptions=Gtk.AttachOptions.EXPAND | + Gtk.AttachOptions.FILL | + Gtk.AttachOptions.SHRINK, + xpadding=10, ypadding=10) self.description_textview.props.accepts_tab = False - self.description_textview.connect('key_press_event', + self.description_textview.connect('key_press_event', self.key_press_event_cb) self.description_textview.show() - tags_label = gtk.Label(_("Tags")) - entry_table.attach(tags_label, 0, 1, 2, 3, - xoptions=gtk.SHRINK, - yoptions=gtk.SHRINK, - xpadding=10, ypadding=10) + tags_label = Gtk.Label(_("Tags")) + entry_table.attach(tags_label, 0, 1, 2, 3, + xoptions=Gtk.AttachOptions.SHRINK, + yoptions=Gtk.AttachOptions.SHRINK, + xpadding=10, ypadding=10) tags_label.show() - self.tags_textview = gtk.TextView() - self.tags_textview.set_wrap_mode(gtk.WRAP_WORD) - entry_table.attach(self.tags_textview, 1, 2, 2, 3, - xoptions=gtk.FILL, - yoptions=gtk.EXPAND|gtk.FILL, - xpadding=10, ypadding=10) + self.tags_textview = Gtk.TextView() + self.tags_textview.set_wrap_mode(Gtk.WrapMode.WORD) + entry_table.attach(self.tags_textview, 1, 2, 2, 3, + xoptions=Gtk.AttachOptions.FILL, + yoptions=Gtk.AttachOptions.EXPAND | + Gtk.AttachOptions.FILL, + xpadding=10, ypadding=10) self.tags_textview.props.accepts_tab = False - self.tags_textview.connect('key_press_event', + self.tags_textview.connect('key_press_event', self.key_press_event_cb) self.tags_textview.show() entry_table.show() - scroller_image = gtk.ScrolledWindow( - hadjustment=None, vadjustment=None) - scroller_image.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) + scroller_image = Gtk.ScrolledWindow( + hadjustment=None, vadjustment=None) + scroller_image.set_policy(Gtk.PolicyType.NEVER, + Gtk.PolicyType.AUTOMATIC) scroller_image.add_with_viewport(image_table) scroller_image.show() - self.scroller_entry = gtk.ScrolledWindow( - hadjustment=None, vadjustment=None) - self.scroller_entry.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) + self.scroller_entry = Gtk.ScrolledWindow( + hadjustment=None, vadjustment=None) + self.scroller_entry.set_policy(Gtk.PolicyType.NEVER, + Gtk.PolicyType.AUTOMATIC) self.scroller_entry.add_with_viewport(entry_table) self.scroller_entry.show() - column_table.attach(scroller_image, 0, 1, 0, 1, - xoptions=gtk.FILL|gtk.EXPAND|gtk.SHRINK, - yoptions=gtk.FILL|gtk.EXPAND|gtk.SHRINK, - xpadding=10, ypadding=10) - - column_table.attach(self.scroller_entry, 1, 2, 0, 1, - xoptions=gtk.FILL|gtk.EXPAND|gtk.SHRINK, - yoptions=gtk.FILL|gtk.EXPAND|gtk.SHRINK, - xpadding=10, ypadding=10) + column_table.attach(scroller_image, 0, 1, 0, 1, + xoptions=Gtk.AttachOptions.FILL | + Gtk.AttachOptions.EXPAND | + Gtk.AttachOptions.SHRINK, + yoptions=Gtk.AttachOptions.FILL | + Gtk.AttachOptions.EXPAND | + Gtk.AttachOptions.SHRINK, + xpadding=10, ypadding=10) + + column_table.attach(self.scroller_entry, 1, 2, 0, 1, + xoptions=Gtk.AttachOptions.FILL | + Gtk.AttachOptions.EXPAND | + Gtk.AttachOptions.SHRINK, + yoptions=Gtk.AttachOptions.FILL | + Gtk.AttachOptions.EXPAND | + Gtk.AttachOptions.SHRINK, + xpadding=10, ypadding=10) image_table.show() column_table.show() self.btn_resize.hide() self.resize_width_entry.hide() - vbox = gtk.VBox(homogeneous=True, spacing=5) - vbox.pack_start(column_table) - vbox.pack_end(self.list_scroller_journal) + vbox = Gtk.VBox(homogeneous=True, spacing=5) + vbox.pack_start(column_table, False, False, 0) + vbox.pack_end(self.list_scroller_journal, False, False, 0) canvas.append_page(vbox, tab1_label) - self._filechooser = gtk.FileChooserWidget( - action=gtk.FILE_CHOOSER_ACTION_OPEN, backend=None) + self._filechooser = Gtk.FileChooserWidget( + action=Gtk.FileChooserAction.OPEN, parent=None) self._filechooser.set_current_folder("/media") - self.copy_button = gtk.Button(_("Copy File To The Journal")) + self.copy_button = Gtk.Button(_("Copy File To The Journal")) self.copy_button.connect('clicked', self.create_journal_entry) self.copy_button.show() self._filechooser.set_extra_widget(self.copy_button) - preview = gtk.Image() + preview = Gtk.Image() self._filechooser.set_preview_widget(preview) - self._filechooser.connect("update-preview", + self._filechooser.connect("update-preview", self.update_preview_cb, preview) - tab2_label = gtk.Label(_("Files")) + tab2_label = Gtk.Label(_("Files")) tab2_label.set_attributes(label_attributes) tab2_label.show() canvas.append_page(self._filechooser, tab2_label) @@ -262,13 +313,15 @@ class SugarCommander(activity.Activity): self.resize_width_entry.hide() self.dimension_label.hide() - toolbox = activity.ActivityToolbox(self) - activity_toolbar = toolbox.get_activity_toolbar() - activity_toolbar.keep.props.visible = False - activity_toolbar.share.props.visible = False - self.set_toolbox(toolbox) - toolbox.show() - + toolbox = ToolbarBox() + separator = Gtk.SeparatorToolItem() + separator.set_draw(False) + separator.set_expand(True) + toolbox.toolbar.insert(separator, -1) + toolbox.toolbar.insert(StopButton(self), -1) + toolbox.show_all() + self.toolbar_box = toolbox + self.load_journal_table() bus = dbus.SessionBus() @@ -285,13 +338,13 @@ class SugarCommander(activity.Activity): try: file_mimetype = mime.get_for_file(filename) if file_mimetype.startswith('image/') and file_mimetype != 'image/vnd.djvu': - pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(filename, + pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(filename, style.zoom(320), style.zoom(240)) preview.set_from_pixbuf(pixbuf) have_preview = True elif file_mimetype == 'application/x-cbz': fname = self.extract_image(filename) - pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(fname, + pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(fname, style.zoom(320), style.zoom(240)) preview.set_from_pixbuf(pixbuf) have_preview = True @@ -305,18 +358,20 @@ class SugarCommander(activity.Activity): def key_press_event_cb(self, entry, event): self.btn_save.props.sensitive = True - + def resize_key_press_event_cb(self, entry, event): - keyname = gtk.gdk.keyval_name(event.keyval) - if ((keyname < '0' or keyname > '9') and keyname != 'BackSpace' - and keyname != 'Left' and keyname != 'Right' - and keyname != 'KP_Left' and keyname != 'KP_Right' - and keyname != 'Delete' and keyname != 'End' - and keyname != 'KP_End' and keyname != 'Home' - and keyname != 'KP_Home' and keyname != 'KP_Delete'): - return True - else: - return False + # FIXME: Reescribir + pass + #keyname = Gtk.gdk.keyval_name(event.keyval) + #if ((keyname < '0' or keyname > '9') and keyname != 'BackSpace' + # and keyname != 'Left' and keyname != 'Right' + # and keyname != 'KP_Left' and keyname != 'KP_Right' + # and keyname != 'Delete' and keyname != 'End' + # and keyname != 'KP_End' and keyname != 'Home' + # and keyname != 'KP_Home' and keyname != 'KP_Delete'): + # return True + #else: + # return False def resize_button_press_event_cb(self, entry, event): jobject = self.selected_journal_entry @@ -325,12 +380,12 @@ class SugarCommander(activity.Activity): image_width, image_height = im.get_size() resize_to_width = int(self.resize_width_entry.get_text()) if (image_width < resize_to_width): - self.alert(_('Error'), _('Image cannot be made larger, only smaller.')) + self.alert(_('Error'), _('Image cannot be made larger, only smaller.')) return tempfile = os.path.join(self.get_activity_root(), 'instance', 'tmp%i' % time.time()) try: - scaled_pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(filename, resize_to_width, ARBITRARY_LARGE_HEIGHT) + scaled_pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(filename, resize_to_width, ARBITRARY_LARGE_HEIGHT) scaled_pixbuf.save(tempfile, "jpeg", {"quality":"%d" % JPEG_QUALITY}) except: print 'File could not be converted' @@ -542,7 +597,7 @@ class SugarCommander(activity.Activity): import base64 preview_data = base64.b64decode(jobject.metadata['preview']) - loader = gtk.gdk.PixbufLoader() + loader = GdkPixbuf.PixbufLoader() loader.write(preview_data) scaled_buf = loader.get_pixbuf() loader.close() @@ -555,13 +610,13 @@ class SugarCommander(activity.Activity): def load_journal_table(self): self.btn_save.props.sensitive = False self.btn_delete.props.sensitive = False - ds_mounts = datastore.mounts() + ds_mounts = get_mounts() mountpoint_id = None if len(ds_mounts) == 1 and ds_mounts[0]['id'] == 1: pass else: for mountpoint in ds_mounts: - id = mountpoint['id'] + id = mountpoint['id'] uri = mountpoint['uri'] if uri.startswith('/home'): mountpoint_id = id @@ -569,7 +624,7 @@ class SugarCommander(activity.Activity): query = {} if mountpoint_id is not None: query['mountpoints'] = [ mountpoint_id ] - ds_objects, num_objects = datastore.find(query, properties=['uid', + ds_objects, num_objects = datastore.find(query, properties=['uid', 'title', 'mime_type']) self.ls_journal.clear() @@ -583,7 +638,8 @@ class SugarCommander(activity.Activity): size = self.get_size(ds_objects[i]) / 1024 self.ls_journal.set(iter, COLUMN_SIZE, size) - self.ls_journal.set_sort_column_id(COLUMN_TITLE, gtk.SORT_ASCENDING) + # FIXME: AttributeError: 'gi.repository.Gtk' object has no attribute 'SORT_ASCENDING' + #self.ls_journal.set_sort_column_id(COLUMN_TITLE, Gtk.SORT_ASCENDING) v_adjustment = self.list_scroller_journal.get_vadjustment() v_adjustment.value = 0 @@ -622,7 +678,7 @@ class SugarCommander(activity.Activity): journal_entry.file_path = filename datastore.write(journal_entry) self.update_log_entries += '\n' + _('File %s copied to the Journal.') % filename - self.alert(_('Success'), _('%s added to Journal.') + self.alert(_('Success'), _('%s added to Journal.') % self.make_new_filename(filename)) def alert(self, title, text=None): @@ -638,7 +694,7 @@ class SugarCommander(activity.Activity): def show_image(self, filename): "display a resized image in a preview" - scaled_buf = gtk.gdk.pixbuf_new_from_file_at_size(filename, + scaled_buf = GdkPixbuf.Pixbuf.new_from_file_at_size(filename, style.zoom(300), style.zoom(225)) self.image.set_from_pixbuf(scaled_buf) self.image.show() @@ -656,7 +712,7 @@ class SugarCommander(activity.Activity): if len(image_files) > 0: if self.save_extracted_file(zf, file_to_extract): - fname = os.path.join(self.get_activity_root(), 'instance', + fname = os.path.join(self.get_activity_root(), 'instance', extract_new_filename) return fname @@ -668,7 +724,7 @@ class SugarCommander(activity.Activity): print 'Error opening the zip file: %s' % (err) return False except KeyError, err: - self.alert('Key Error', 'Zipfile key not found: ' + self.alert('Key Error', 'Zipfile key not found: ' + str(filename)) return outfn = self.make_new_filename(filename) @@ -692,14 +748,14 @@ class SugarCommander(activity.Activity): if not file_mimetype.startswith('image/'): return '' - scaled_pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(filename, + scaled_pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(filename, style.zoom(320), style.zoom(240)) preview_data = [] def save_func(buf, data): data.append(buf) - scaled_pixbuf.save_to_callback(save_func, 'png', + scaled_pixbuf.save_to_callbackv(save_func, 'png', user_data=preview_data) preview_data = ''.join(preview_data) -- cgit v0.9.1