diff options
-rw-r--r-- | fontcombobox.py | 29 | ||||
-rw-r--r-- | globos.py | 26 | ||||
-rw-r--r-- | historietaactivity.py | 117 | ||||
-rw-r--r-- | persistencia.py | 2 | ||||
-rwxr-xr-x | setup.py | 2 | ||||
-rw-r--r-- | toolbar.py | 58 |
6 files changed, 106 insertions, 128 deletions
diff --git a/fontcombobox.py b/fontcombobox.py index 58f9140..9de5e34 100644 --- a/fontcombobox.py +++ b/fontcombobox.py @@ -15,21 +15,22 @@ # 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 -import gtk +from gi.repository import Gtk +from gi.repository import GObject FONT_BLACKLIST = ['cmex10', 'cmmi10', 'cmr10', 'cmsy10', 'esint10', 'eufm10', 'msam10', 'msbm10', 'rsfs10', 'wasy10'] -class FontComboBox(gtk.ComboBox): +class FontComboBox(Gtk.ComboBox): def __init__(self): - gtk.ComboBox.__init__(self) - font_renderer = gtk.CellRendererText() - self.pack_start(font_renderer) + GObject.GObject.__init__(self) + font_renderer = Gtk.CellRendererText() + self.pack_start(font_renderer, True) self.add_attribute(font_renderer, 'text', 0) self.add_attribute(font_renderer, 'font', 0) - font_model = gtk.ListStore(str) + font_model = Gtk.ListStore(str) context = self.get_pango_context() font_index = 0 @@ -39,15 +40,15 @@ class FontComboBox(gtk.ComboBox): name = family.get_name() if name not in FONT_BLACKLIST: font_model.append([name]) - font_faces = [] - for face in family.list_faces(): - face_name = face.get_face_name() - font_faces.append(face_name) - self.faces[name] = font_faces + # TODO gtk3 +# font_faces = [] +# for face in family.list_faces(): +# face_name = face.get_face_name() +# font_faces.append(face_name) +# self.faces[name] = font_faces - sorter = gtk.TreeModelSort(font_model) - sorter.set_sort_column_id(0, gtk.SORT_ASCENDING) - self.set_model(sorter) + font_model.set_sort_column_id(0, Gtk.SortType.ASCENDING) + self.set_model(font_model) self.show() def set_font_name(self, font_name): @@ -2,12 +2,12 @@ import os import math -import gtk +from gi.repository import Gtk, Gdk import cairo -from sugar.activity import activity -from sugar.graphics.icon import _IconBuffer -from sugar.graphics import style +from sugar3.activity import activity +from sugar3.graphics.icon import _IconBuffer +from sugar3.graphics import style ANCHO_LINEAS_CONTROLES = 2 SIZE_RESIZE_AREA = style.GRID_CELL_SIZE / 2 @@ -930,29 +930,24 @@ class CuadroTexto: self.double_key = None if self.texto: - - if keyval == gtk.gdk.keyval_from_name('BackSpace'): + if keyval == Gdk.keyval_from_name('BackSpace'): if self.cursor >= 1: self.texto = self.texto[0:self.cursor - 1] + \ self.texto[self.cursor:len(self.texto)] self.cursor -= 1 self.redimensionar(context) - - elif keyval == gtk.gdk.keyval_from_name('Return'): + elif keyval == Gdk.keyval_from_name('Return'): self.texto = self.texto[0:self.cursor] + "\n" + \ self.texto[self.cursor:len(self.texto)] self.cursor += 1 self.redimensionar(context) - - elif keyval == gtk.gdk.keyval_from_name('Right'): + elif keyval == Gdk.keyval_from_name('Right'): if self.cursor < len(self.texto): self.cursor += 1 - - elif keyval == gtk.gdk.keyval_from_name('Left'): + elif keyval == Gdk.keyval_from_name('Left'): if self.cursor > 0: self.cursor -= 1 - - elif keyval == gtk.gdk.keyval_from_name('Up'): + elif keyval == Gdk.keyval_from_name('Up'): sum_ren = 0 #se averigua en que renglon esta el cursor for i in range(len(self.renglones)): @@ -968,8 +963,7 @@ class CuadroTexto: break else: sum_ren += (len(self.renglones[i]) + self.esp_reg[i]) - - elif keyval == gtk.gdk.keyval_from_name('Down'): + elif keyval == Gdk.keyval_from_name('Down'): sum_ren = 0 #se averigua en que renglon esta el cursor for i in range(len(self.renglones)): diff --git a/historietaactivity.py b/historietaactivity.py index f46567d..0ca0f1d 100644 --- a/historietaactivity.py +++ b/historietaactivity.py @@ -1,29 +1,31 @@ # -*- coding: UTF-8 -*- import os -import gtk +from gi.repository import Gtk +from gi.repository import Gdk +from gi.repository import GdkPixbuf import cairo import globos import persistencia -from sugar.activity import activity +from sugar3.activity import activity from gettext import gettext as _ -from sugar.graphics.toolbarbox import ToolbarBox, ToolbarButton -from sugar.activity.widgets import StopButton -from sugar.activity.widgets import ActivityToolbarButton +from sugar3.graphics.toolbarbox import ToolbarBox, ToolbarButton +from sugar3.activity.widgets import StopButton +from sugar3.activity.widgets import ActivityToolbarButton -from sugar.graphics.toolbutton import ToolButton +from sugar3.graphics.toolbutton import ToolButton from toolbar import TextToolbar from toolbar import GlobesManager import time -from sugar.datastore import datastore -from sugar import profile -from sugar.graphics import style -from sugar.graphics.alert import Alert -from sugar.graphics.icon import Icon +from sugar3.datastore import datastore +from sugar3 import profile +from sugar3.graphics import style +from sugar3.graphics.alert import Alert +from sugar3.graphics.icon import Icon import dbus import logging @@ -61,7 +63,7 @@ class HistorietaActivity(activity.Activity): text_button.props.label = _('Text') toolbar_box.toolbar.insert(text_button, -1) - separator = gtk.SeparatorToolItem() + separator = Gtk.SeparatorToolItem() separator.props.draw = False separator.set_expand(True) toolbar_box.toolbar.insert(separator, -1) @@ -73,7 +75,7 @@ class HistorietaActivity(activity.Activity): # add export button - separator_2 = gtk.SeparatorToolItem() + separator_2 = Gtk.SeparatorToolItem() separator_2.show() activity_toolbar.insert(separator_2, -1) @@ -87,8 +89,8 @@ class HistorietaActivity(activity.Activity): activity_button.page.title.connect("focus-in-event", self.on_title) - scrolled = gtk.ScrolledWindow() - scrolled.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS) + scrolled = Gtk.ScrolledWindow() + scrolled.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.ALWAYS) scrolled.add_with_viewport(self.page) scrolled.show_all() self.set_canvas(scrolled) @@ -222,9 +224,9 @@ class HistorietaActivity(activity.Activity): _stop_alert = Alert() _stop_alert.props.title = title _stop_alert.props.msg = msg - _stop_alert.add_button(gtk.RESPONSE_APPLY, + _stop_alert.add_button(Gtk.ResponseType.APPLY, _('Show in Journal'), Icon(icon_name='zoom-activity')) - _stop_alert.add_button(gtk.RESPONSE_OK, _('Ok'), + _stop_alert.add_button(Gtk.ResponseType.OK, _('Ok'), Icon(icon_name='dialog-ok')) # Remove other alerts for alert in self._alerts: @@ -235,14 +237,14 @@ class HistorietaActivity(activity.Activity): _stop_alert.show_all() def __stop_response_cb(self, alert, response_id): - if response_id is gtk.RESPONSE_APPLY: + if response_id is Gtk.ResponseType.APPLY: activity.show_object_in_journal(self._object_id) self.remove_alert(alert) def _get_preview_image(self, file_name): preview_width, preview_height = style.zoom(300), style.zoom(225) - pixbuf = gtk.gdk.pixbuf_new_from_file(file_name) + pixbuf = GdkPixbuf.Pixbuf.new_from_file(file_name) width, height = pixbuf.get_width(), pixbuf.get_height() scale = 1 @@ -251,7 +253,7 @@ class HistorietaActivity(activity.Activity): scale_y = preview_height / float(height) scale = min(scale_x, scale_y) - pixbuf2 = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, \ + pixbuf2 = GdkPixbuf.Pixbuf(GdkPixbuf.Colorspace.RGB, \ pixbuf.get_has_alpha(), \ pixbuf.get_bits_per_sample(), \ preview_width, preview_height) @@ -264,7 +266,7 @@ class HistorietaActivity(activity.Activity): preview_width - (margin_x * 2), \ preview_height - (margin_y * 2), \ margin_x, margin_y, scale, scale, \ - gtk.gdk.INTERP_BILINEAR) + GdkPixbuf.InterpType.BILINEAR) preview_data = [] @@ -278,15 +280,15 @@ class HistorietaActivity(activity.Activity): DEF_SPACING = 6 DEF_WIDTH = 4 -SCREEN_HEIGHT = gtk.gdk.screen_height() -SCREEN_WIDTH = gtk.gdk.screen_width() +SCREEN_HEIGHT = Gdk.Screen.height() +SCREEN_WIDTH = Gdk.Screen.width() BOX_HEIGHT = 450 -class Page(gtk.VBox): +class Page(Gtk.VBox): def __init__(self): - gtk.VBox.__init__(self, False, 0) + Gtk.VBox.__init__(self, False, 0) self.set_homogeneous(False) self.boxs = [] @@ -301,17 +303,17 @@ class Page(gtk.VBox): self.title_box.show() self.title_box.set_size_request(SCREEN_WIDTH, 100) self.title_box.width, self.title_box.height = SCREEN_WIDTH, 100 - self.pack_start(self.title_box, False) + self.pack_start(self.title_box, False, False, 0) self.set_active_box(self.title_box) self.boxs.append(self.title_box) self.title_box.page = self # Agrego tabla para las fotos - self.table = gtk.Table(10, 2, True) + self.table = Gtk.Table(10, 2, True) self.table.set_homogeneous(True) self.table.set_row_spacings(DEF_SPACING) self.table.set_col_spacings(DEF_SPACING) - self.pack_start(self.table) + self.pack_start(self.table, False, False, 0) def add_box_from_journal_image(self, image_file_name): posi = len(self.boxs) - 1 @@ -348,16 +350,16 @@ class Page(gtk.VBox): return None -class ComicBox(gtk.DrawingArea): +class ComicBox(Gtk.DrawingArea): def __init__(self, image_file_name, posi): print ('Cuadro INIT') - gtk.DrawingArea.__init__(self) + Gtk.DrawingArea.__init__(self) #se agregan los eventos de pulsacion y movimiento del raton - self.add_events(gtk.gdk.POINTER_MOTION_MASK | \ - gtk.gdk.BUTTON_PRESS_MASK | \ - gtk.gdk.BUTTON_RELEASE_MASK | \ - gtk.gdk.BUTTON1_MOTION_MASK) + self.add_events(Gdk.EventMask.POINTER_MOTION_MASK | + Gdk.EventMask.BUTTON_PRESS_MASK | + Gdk.EventMask.BUTTON_RELEASE_MASK | + Gdk.EventMask.BUTTON_MOTION_MASK) #self.globos es una lista que contiene los globos de ese cuadro self.globos = [] @@ -383,7 +385,7 @@ class ComicBox(gtk.DrawingArea): self.set_size_request(-1, BOX_HEIGHT) - self.connect("expose_event", self.expose) + self.connect("draw", self.draw) self.connect("button_press_event", self.pressing) self.connect("motion_notify_event", self.mouse_move) self.connect("motion_notify_event", self.moving) @@ -439,8 +441,7 @@ class ComicBox(gtk.DrawingArea): self._globo_activo = globo self.queue_draw() - def expose(self, widget, event): - self.context = widget.window.cairo_create() + def draw(self, widget, context): # check if is the title box and is a new page if self.page.title_box == self and self.page.empty_page: @@ -454,20 +455,9 @@ class ComicBox(gtk.DrawingArea): self.title_globe = self.globos[0] self.title_globe.texto.set_text(_('Title:')) - self.draw(self.context, event.area, widget.window) + self.draw_in_context(context) return False - """ - que hace esto? nadie lo llama... - def set_sink(self, sink): - assert self.window.xid - self.imagesink = sink - self.imagesink.set_xwindow_id(self.window.xid) - """ - - def draw(self, ctx, area, window): - self.draw_in_context(ctx) - def draw_in_context(self, ctx): # Dibujamos la foto ctx.set_line_width(DEF_WIDTH) @@ -482,10 +472,10 @@ class ComicBox(gtk.DrawingArea): # de historieta ya grabado, # si viene con path, es una imagen que se tomo del journal if (not self.image_name.startswith(instance_path)): - pixbuf = gtk.gdk.pixbuf_new_from_file( + pixbuf = GdkPixbuf.Pixbuf.new_from_file( os.path.join(instance_path, self.image_name)) else: - pixbuf = gtk.gdk.pixbuf_new_from_file(self.image_name) + pixbuf = GdkPixbuf.Pixbuf.new_from_file(self.image_name) width_pxb = pixbuf.get_width() height_pxb = pixbuf.get_height() scale = (self.width) / (1.0 * width_pxb) @@ -497,24 +487,22 @@ class ComicBox(gtk.DrawingArea): # que venga del journal y tenga el tamanio justo, # es decir con scale = 1 pixb_scaled = pixbuf.scale_simple(int(self.width), - int(self.image_height), gtk.gdk.INTERP_BILINEAR) + int(self.image_height), GdkPixbuf.InterpType.BILINEAR) ct = cairo.Context(self.image) - gtk_ct = gtk.gdk.CairoContext(ct) - gtk_ct.set_source_pixbuf(pixb_scaled, 0, 0) - gtk_ct.paint() + Gdk.cairo_set_source_pixbuf(ct, pixb_scaled, 0, 0) + ct.paint() if (not self.image_saved): self.image_saved = True # print instance_path - image_file_name = 'image' + str(self.posi) + '.jpg' - pixb_scaled.save(os.path.join(instance_path, - image_file_name), 'jpeg') + image_file_name = 'image' + str(self.posi) + '.png' + self.image.write_to_png(os.path.join(instance_path, + image_file_name)) # grabamos el nombre de la imagen sin el path self.image_name = image_file_name else: ct = cairo.Context(self.image) - gtk_ct = gtk.gdk.CairoContext(ct) - gtk_ct.set_source_pixbuf(pixbuf, 0, 0) - gtk_ct.paint() + Gdk.cairo_set_source_pixbuf(ct, pixbuf, 0, 0) + ct.paint() if (self.image != None): ctx.set_source_surface(self.image, 0, 0) @@ -591,9 +579,10 @@ class ComicBox(gtk.DrawingArea): if self._globo_activo != None: over_state = self._globo_activo.get_over_state(event.x, event.y) cursor = None - if over_state != None: - cursor = gtk.gdk.Cursor(gtk.gdk.__dict__[over_state]) - self.window.set_cursor(cursor) + # TODO: Gtk3 + #if over_state != None: + # cursor = Gdk.Cursor(gtk.gdk.__dict__[over_state]) + #self.window.set_cursor(cursor) def moving(self, widget, event): if self.is_dimension: diff --git a/persistencia.py b/persistencia.py index f8d62c1..43c1185 100644 --- a/persistencia.py +++ b/persistencia.py @@ -1,7 +1,7 @@ import os import simplejson import globos -from sugar.activity import activity +from sugar3.activity import activity import zipfile @@ -1,3 +1,3 @@ #!/usr/bin/env python -from sugar.activity import bundlebuilder +from sugar3.activity import bundlebuilder bundlebuilder.start() @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- # copiado de la actividad write # Copyright (C) 2006, Martin Sevior # Copyright (C) 2006-2007, Marc Maurer <uwog@uwog.net> @@ -20,22 +21,23 @@ from gettext import gettext as _ import logging import os import time -import gtk -from sugar.graphics.icon import Icon -from sugar.graphics.toolbutton import ToolButton -from sugar.graphics.toggletoolbutton import ToggleToolButton -from sugar.graphics.combobox import ComboBox -from sugar.graphics.toolcombobox import ToolComboBox -from sugar.graphics.objectchooser import ObjectChooser -from sugar.activity.widgets import RadioMenuButton -from sugar.graphics.menuitem import MenuItem +# Gtk3 +from gi.repository import Gtk, Gdk, GdkPixbuf +from sugar3.graphics.icon import Icon +from sugar3.graphics.toolbutton import ToolButton +from sugar3.graphics.toggletoolbutton import ToggleToolButton +from sugar3.graphics.combobox import ComboBox +from sugar3.graphics.toolcombobox import ToolComboBox +from sugar3.graphics.objectchooser import ObjectChooser +from sugar3.activity.widgets import RadioMenuButton +from sugar3.graphics.menuitem import MenuItem from fontcombobox import FontComboBox import globos WITH_COLOR_BUTTON = True try: - from sugar.graphics.colorbutton import ColorToolButton + from sugar3.graphics.colorbutton import ColorToolButton ##Class to manage the Text Color class TextButtonColor(ColorToolButton): @@ -84,7 +86,7 @@ class GlobesManager(): self.add_photo.set_tooltip(_('Add Photo')) toolbar.insert(self.add_photo, -1) - separator = gtk.SeparatorToolItem() + separator = Gtk.SeparatorToolItem() separator.set_draw(True) toolbar.insert(separator, -1) @@ -138,7 +140,7 @@ class GlobesManager(): menu_item.show() toolbar.insert(self._lines_menu, -1) - separator = gtk.SeparatorToolItem() + separator = Gtk.SeparatorToolItem() separator.set_draw(True) toolbar.insert(separator, -1) @@ -227,18 +229,10 @@ class GlobesManager(): self._page.boxs.pop() def add_image(self): - try: - chooser = ObjectChooser(_('Choose image'), - self._activity, gtk.DIALOG_MODAL | - gtk.DIALOG_DESTROY_WITH_PARENT, what_filter='Image') - except: - chooser = ObjectChooser(_('Choose image'), - self._activity, gtk.DIALOG_MODAL | - gtk.DIALOG_DESTROY_WITH_PARENT) + chooser = ObjectChooser(self._activity, what_filter='Image') try: result = chooser.run() - print result, gtk.RESPONSE_ACCEPT - if result == gtk.RESPONSE_ACCEPT: + if result == Gtk.ResponseType.ACCEPT: logging.debug('ObjectChooser: %r' % chooser.get_selected_object()) jobject = chooser.get_selected_object() @@ -254,12 +248,12 @@ class GlobesManager(): del chooser -class TextToolbar(gtk.Toolbar): +class TextToolbar(Gtk.Toolbar): def __init__(self, page): self._colorseldlg = None - gtk.Toolbar.__init__(self) + Gtk.Toolbar.__init__(self) self._page = page page._text_toolbar = self @@ -286,26 +280,26 @@ class TextToolbar(gtk.Toolbar): if WITH_COLOR_BUTTON: self._text_color = TextButtonColor(page) self._text_color.set_title(_('Text Color')) - item = gtk.ToolItem() + item = Gtk.ToolItem() item.add(self._text_color) self.insert(item, -1) else: - self._text_color = gtk.ColorButton() + self._text_color = Gtk.ColorButton() self._text_color_id = self._text_color.connect('color-set', self._text_color_cb) - tool_item = gtk.ToolItem() + tool_item = Gtk.ToolItem() tool_item.add(self._text_color) self.insert(tool_item, -1) tool_item.show_all() - separator = gtk.SeparatorToolItem() + separator = Gtk.SeparatorToolItem() separator.set_draw(True) self.insert(separator, -1) # tamanio self._font_size_icon = Icon(icon_name="format-text-size", - icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR) - tool_item = gtk.ToolItem() + icon_size=Gtk.IconSize.LARGE_TOOLBAR) + tool_item = Gtk.ToolItem() tool_item.add(self._font_size_icon) self.insert(tool_item, -1) @@ -335,7 +329,7 @@ class TextToolbar(gtk.Toolbar): return self._text_selected_handler def _add_widget(self, widget, expand=False): - tool_item = gtk.ToolItem() + tool_item = Gtk.ToolItem() tool_item.set_expand(expand) tool_item.add(widget) widget.show() @@ -402,7 +396,7 @@ class TextToolbar(gtk.Toolbar): self.setToggleButtonState(self._italic, globeText.italic, self._italic_id) # color - self._text_color.set_color(gtk.gdk.Color( + self._text_color.set_color(Gdk.Color( int(globeText.color_r * 65535), int(globeText.color_g * 65535), int(globeText.color_b * 65535))) |