Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorflavio <fdanesse@gmail.com>2013-01-08 13:49:47 (GMT)
committer flavio <fdanesse@gmail.com>2013-01-08 13:49:47 (GMT)
commit9e65505ce3d6fa7f21b92cf8d2b2289a25fc8036 (patch)
tree9da7d7c94e366f7f2ef95d35f503b46a5044d463
parent82243047368642558eb8041554ade501d24e11ee (diff)
Port SugarMoon
-rwxr-xr-xGnomeMoonActivity.py26
-rw-r--r--Moonwidgets.py6
-rw-r--r--SugarMoonActivity.py260
3 files changed, 138 insertions, 154 deletions
diff --git a/GnomeMoonActivity.py b/GnomeMoonActivity.py
index 33931c5..e284b8f 100755
--- a/GnomeMoonActivity.py
+++ b/GnomeMoonActivity.py
@@ -25,7 +25,7 @@
# Febrero 2012
# Correcciones, Simplificación y Reestructuración Modular:
# Desarrollo de CalendarButton + MoonCalendar:
-# Instalador y Portado a gnome:
+# Instalador y Portado a gnome y Gtk 3:
# Flavio Danesse <fdanesse@gmail.com> CeibalJAM! - Uruguay - Activity Central
import os
@@ -101,7 +101,8 @@ class MoonActivity(Gtk.Window):
boton = Gtk.ToggleToolButton()
boton.connect('clicked', self.toggle_grid_clicked)
- pixbuf= GdkPixbuf.Pixbuf.new_from_file_at_size(os.path.join(MG.ICONOS,'grid-ico.svg'), 32, 32)
+ pixbuf= GdkPixbuf.Pixbuf.new_from_file_at_size(
+ os.path.join(MG.ICONOS,'grid-ico.svg'), 32, 32)
imagen = Gtk.Image()
imagen.set_from_pixbuf(pixbuf)
boton.set_icon_widget(imagen)
@@ -112,7 +113,8 @@ class MoonActivity(Gtk.Window):
boton = Gtk.ToggleToolButton()
boton.connect('clicked', self.toggle_hemisphere_clicked)
- pixbuf= GdkPixbuf.Pixbuf.new_from_file_at_size(os.path.join(MG.ICONOS,'hemi-ico.svg'), 32, 32)
+ pixbuf= GdkPixbuf.Pixbuf.new_from_file_at_size(
+ os.path.join(MG.ICONOS,'hemi-ico.svg'), 32, 32)
imagen = Gtk.Image()
imagen.set_from_pixbuf(pixbuf)
boton.set_icon_widget(imagen)
@@ -123,7 +125,8 @@ class MoonActivity(Gtk.Window):
boton = Gtk.ToggleToolButton()
boton.connect('clicked', self.switch_calendar_luna)
- pixbuf= GdkPixbuf.Pixbuf.new_from_file_at_size(os.path.join(MG.ICONOS,'calendario-ico.svg'), 32, 32)
+ pixbuf= GdkPixbuf.Pixbuf.new_from_file_at_size(
+ os.path.join(MG.ICONOS,'calendario-ico.svg'), 32, 32)
imagen = Gtk.Image()
imagen.set_from_pixbuf(pixbuf)
boton.set_icon_widget(imagen)
@@ -167,12 +170,17 @@ class MoonActivity(Gtk.Window):
def toggle_grid_clicked(self, widget= None):
self.luna_hoy.toggle_grid_clicked()
- self.mooncalendar.toggle_grid_clicked(widget= None, actualizar = self.mooncalendar in self.aspectframe.get_children())
+
+ self.mooncalendar.toggle_grid_clicked(
+ widget = None,
+ actualizar = self.mooncalendar in self.aspectframe.get_children())
def toggle_hemisphere_clicked(self, widget= None):
self.luna_hoy.toggle_hemisphere_clicked()
- self.mooncalendar.toggle_hemisphere_clicked(widget= None, actualizar = self.mooncalendar in self.aspectframe.get_children())
+ self.mooncalendar.toggle_hemisphere_clicked(
+ widget = None,
+ actualizar = self.mooncalendar in self.aspectframe.get_children())
def switch_calendar_luna(self, widget):
@@ -192,6 +200,7 @@ class MoonActivity(Gtk.Window):
def handle(self):
self.update_text_information_view()
+
if self.luna_hoy in self.aspectframe.get_children():
self.luna_hoy.actualizar()
@@ -200,11 +209,10 @@ class MoonActivity(Gtk.Window):
def repaint(self, widget= None, event= None):
rect = self.luna_hoy.get_allocation()
- anchoboton, altoboton = (rect.width, rect.height)
- tamanioboton = min( [anchoboton,altoboton] )
- self.luna_hoy.repaint(tamanioboton)
+ self.luna_hoy.repaint(min( [rect.width, rect.height] ))
def delete_event(self, widget, event, data=None):
+
sys.exit(0)
return False
diff --git a/Moonwidgets.py b/Moonwidgets.py
index f50a262..05e38cc 100644
--- a/Moonwidgets.py
+++ b/Moonwidgets.py
@@ -621,9 +621,9 @@ class MatrizMoonCalendar(Gtk.EventBox):
def repaint(self, widget= None, event= None):
if not self.fixes: return
- x,y,w,h= self.get_allocation()
- anchoboton = w/len(self.fixes[0])
- altoboton = h/len(self.fixes)
+ rect = self.get_allocation()
+ anchoboton = rect.width/len(self.fixes[0])
+ altoboton = rect.height/len(self.fixes)
tamanioboton = min( [anchoboton,altoboton] )
if self.tamanioboton != tamanioboton:
self.tamanioboton = tamanioboton
diff --git a/SugarMoonActivity.py b/SugarMoonActivity.py
index 0c21693..6afb611 100644
--- a/SugarMoonActivity.py
+++ b/SugarMoonActivity.py
@@ -22,17 +22,24 @@
# Author: gary@garycmartin.com
# Home page: http://www.garycmartin.com/
-# Febrero 2012
-# Correcciones, Simplificación y Reestructuración Modular:
-# Desarrollo de CalendarButton + MoonCalendar:
-# Instalador y Portado a gnome:
-# Flavio Danesse <fdanesse@gmail.com> CeibalJAM! - Uruguay - Activity Central
-# Traducciones a Español:
-# Ana Cichero <ana.cichero@gmail.com> CeibalJAM! - Uruguay
-
-import gtk, pygtk, time, math, gobject, sys
-from sugar.activity import activity
+import os
+import sys
+import time
+import math
+
+import gi
+from gi.repository import Gtk
+from gi.repository import Gdk
+from gi.repository import GdkPixbuf
+from gi.repository import GObject
+
+from sugar3.activity import activity
+from sugar3.graphics.toolbarbox import ToolbarBox
+from sugar3.activity.widgets import StopButton
+from sugar3.activity.widgets import ActivityToolbarButton
+
from gettext import gettext as _
+
import MoonGlobals as MG
from Moonwidgets import *
@@ -44,6 +51,7 @@ format = "%Y-%m-%d %H:%M"
try:
import json
json.dumps
+
except (ImportError, AttributeError):
import simplejson as json
@@ -54,7 +62,7 @@ class MoonActivity(activity.Activity):
activity.Activity.__init__(self, handle, True)
self.set_title(_("Luna"))
- self.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND)
+ self.modify_bg(Gtk.StateType.NORMAL, MG.BACKGROUND)
self.main_view = None
self.mooncalendar = None
@@ -75,151 +83,103 @@ class MoonActivity(activity.Activity):
self.maximize()
self.connect("delete_event", self.delete_event)
- self.luna_hoy.connect("expose_event", self.repaint)
+ self.luna_hoy.connect("draw", self.repaint)
- self.actualizador = gobject.timeout_add(1000, self.handle)
+ self.actualizador = GObject.timeout_add(1000, self.handle)
def set_layout(self):
anio, mes, fecha, hora = MG.get_date_time_now()
self.luna_hoy = CalendarButton(anio, mes, fecha, hora)
self.mooncalendar = MoonCalendar()
- self.aspectframe = gtk.AspectFrame()
- self.aspectframe.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND)
+ self.aspectframe = Gtk.AspectFrame()
+ self.aspectframe.modify_bg(Gtk.StateType.NORMAL, MG.BACKGROUND)
self.aspectframe.add(self.luna_hoy)
- cajabase = gtk.VBox()
- self.main_view = gtk.HBox()
+ cajabase = Gtk.VBox()
+ self.main_view = Gtk.HBox()
cajabase.pack_end(self.main_view, True, True, 5)
- try: # Sugar 86 en adelante
- from sugar.graphics.toolbarbox import ToolbarBox
- from sugar.activity.widgets import StopButton
- from sugar.activity.widgets import ActivityToolbarButton
-
- toolbox = ToolbarBox()
- activity_button = ActivityToolbarButton(self)
- activity_button.show()
- toolbox.toolbar.insert(activity_button, 0)
-
- boton = gtk.ToggleToolButton()
- pixbuf= gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(MG.ICONOS,'grid-ico.svg'), 32, 32)
- imagen = gtk.Image()
- imagen.set_from_pixbuf(pixbuf)
- boton.set_icon_widget(imagen)
- imagen.show()
- boton.show()
- toolbox.toolbar.insert(boton, -1)
- boton.connect("clicked", self.toggle_grid_clicked)
- boton.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND)
-
- boton = gtk.ToggleToolButton()
- pixbuf= gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(MG.ICONOS,'hemi-ico.svg'), 32, 32)
- imagen = gtk.Image()
- imagen.set_from_pixbuf(pixbuf)
- boton.set_icon_widget(imagen)
- imagen.show()
- boton.show()
- toolbox.toolbar.insert(boton, -1)
- boton.connect("clicked", self.toggle_hemisphere_clicked)
- boton.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND)
-
- boton = gtk.ToggleToolButton()
- pixbuf= gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(MG.ICONOS,'calendario-ico.svg'), 32, 32)
- imagen = gtk.Image()
- imagen.set_from_pixbuf(pixbuf)
- boton.set_icon_widget(imagen)
- imagen.show()
- boton.show()
- toolbox.toolbar.insert(boton, -1)
- boton.connect("clicked", self.switch_calendar_luna)
- boton.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND)
-
- self.label_emisferio = gtk.Label()
- item = gtk.ToolItem()
- item.add(self.label_emisferio)
- toolbox.toolbar.insert(item, -1)
- self.label_emisferio.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND)
- self.label_emisferio.modify_fg(gtk.STATE_NORMAL, MG.FOREGROUND)
- self.label_emisferio.show()
-
- separator = gtk.SeparatorToolItem()
- separator.props.draw = False
- separator.set_size_request(0, -1)
- separator.set_expand(True)
- toolbox.toolbar.insert(separator, -1)
-
- toolbox.toolbar.insert(StopButton(self), -1)
-
- self.set_toolbar_box(toolbox)
- toolbox.show_all()
-
- except: # Hasta Sugar 84
- view_tool_bar = gtk.Toolbar()
- view_tool_bar.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND)
-
- boton = gtk.ToggleToolButton()
- pixbuf= gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(MG.ICONOS,'grid-ico.svg'), 32, 32)
- imagen = gtk.Image()
- imagen.set_from_pixbuf(pixbuf)
- boton.set_icon_widget(imagen)
- imagen.show()
- boton.show()
- view_tool_bar.append_item("", "", "",boton, self.toggle_grid_clicked, user_data=None)
- boton.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND)
-
- boton = gtk.ToggleToolButton()
- pixbuf= gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(MG.ICONOS,'hemi-ico.svg'), 32, 32)
- imagen = gtk.Image()
- imagen.set_from_pixbuf(pixbuf)
- boton.set_icon_widget(imagen)
- imagen.show()
- boton.show()
- view_tool_bar.append_item("", _(""), "",boton, self.toggle_hemisphere_clicked, user_data=None)
- boton.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND)
-
- boton = gtk.ToggleToolButton()
- pixbuf= gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(MG.ICONOS,'grid-ico.svg'), 32, 32)
- imagen = gtk.Image()
- imagen.set_from_pixbuf(pixbuf)
- boton.set_icon_widget(imagen)
- imagen.show()
- boton.show()
- view_tool_bar.append_item("", "", "",boton, self.switch_calendar_luna, user_data=None)
- boton.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND)
-
- self.label_emisferio = gtk.Label()
- view_tool_bar.append_widget(self.label_emisferio, None, None)
- self.label_emisferio.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND)
- self.label_emisferio.modify_fg(gtk.STATE_NORMAL, MG.FOREGROUND)
- self.label_emisferio.show()
-
- view_tool_bar.show_all()
- toolbox = activity.ActivityToolbox(self)
- toolbox.add_toolbar(_("Luna"), view_tool_bar)
- self.set_toolbox(toolbox)
- toolbox.show()
-
- info_scroll = gtk.ScrolledWindow()
- info_scroll.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
- self.info_panel = gtk.VBox()
- self.info = gtk.TextView()
+ toolbox = ToolbarBox()
+ activity_button = ActivityToolbarButton(self)
+ activity_button.show()
+ toolbox.toolbar.insert(activity_button, 0)
+
+ boton = Gtk.ToggleToolButton()
+ pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(
+ os.path.join(MG.ICONOS,'grid-ico.svg'), 32, 32)
+ imagen = Gtk.Image()
+ imagen.set_from_pixbuf(pixbuf)
+ boton.set_icon_widget(imagen)
+ imagen.show()
+ boton.show()
+ toolbox.toolbar.insert(boton, -1)
+ boton.connect("clicked", self.toggle_grid_clicked)
+ boton.modify_bg(Gtk.StateType.NORMAL, MG.BACKGROUND)
+
+ boton = Gtk.ToggleToolButton()
+ pixbuf= GdkPixbuf.Pixbuf.new_from_file_at_size(
+ os.path.join(MG.ICONOS,'hemi-ico.svg'), 32, 32)
+ imagen = Gtk.Image()
+ imagen.set_from_pixbuf(pixbuf)
+ boton.set_icon_widget(imagen)
+ imagen.show()
+ boton.show()
+ toolbox.toolbar.insert(boton, -1)
+ boton.connect("clicked", self.toggle_hemisphere_clicked)
+ boton.modify_bg(Gtk.StateType.NORMAL, MG.BACKGROUND)
+
+ boton = Gtk.ToggleToolButton()
+ pixbuf= GdkPixbuf.Pixbuf.new_from_file_at_size(
+ os.path.join(MG.ICONOS,'calendario-ico.svg'), 32, 32)
+ imagen = Gtk.Image()
+ imagen.set_from_pixbuf(pixbuf)
+ boton.set_icon_widget(imagen)
+ imagen.show()
+ boton.show()
+ toolbox.toolbar.insert(boton, -1)
+ boton.connect("clicked", self.switch_calendar_luna)
+ boton.modify_bg(Gtk.StateType.NORMAL, MG.BACKGROUND)
+
+ self.label_emisferio = Gtk.Label()
+ item = Gtk.ToolItem()
+ item.add(self.label_emisferio)
+ toolbox.toolbar.insert(item, -1)
+ self.label_emisferio.modify_bg(Gtk.StateType.NORMAL, MG.BACKGROUND)
+ self.label_emisferio.modify_fg(Gtk.StateType.NORMAL, MG.FOREGROUND)
+ self.label_emisferio.show()
+
+ separator = Gtk.SeparatorToolItem()
+ separator.props.draw = False
+ separator.set_size_request(0, -1)
+ separator.set_expand(True)
+ toolbox.toolbar.insert(separator, -1)
+
+ toolbox.toolbar.insert(StopButton(self), -1)
+
+ self.set_toolbar_box(toolbox)
+ toolbox.show_all()
+
+ info_scroll = Gtk.ScrolledWindow()
+ info_scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
+ self.info_panel = Gtk.VBox()
+ self.info = Gtk.TextView()
self.info.set_property("sensitive", False)
- self.info.set_border_window_size(gtk.TEXT_WINDOW_TOP, 10)
- self.info.set_border_window_size(gtk.TEXT_WINDOW_LEFT, 10)
- self.info.set_border_window_size(gtk.TEXT_WINDOW_RIGHT, 10)
- self.info.set_border_window_size(gtk.TEXT_WINDOW_BOTTOM, 10)
+ self.info.set_border_window_size(Gtk.TextWindowType.TOP, 10)
+ self.info.set_border_window_size(Gtk.TextWindowType.LEFT, 10)
+ self.info.set_border_window_size(Gtk.TextWindowType.RIGHT, 10)
+ self.info.set_border_window_size(Gtk.TextWindowType.BOTTOM, 10)
self.info_panel.pack_start(self.info, False, False, 0)
info_scroll.add_with_viewport(self.info_panel)
- event = gtk.EventBox()
- event.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND)
+ event = Gtk.EventBox()
+ event.modify_bg(Gtk.StateType.NORMAL, MG.BACKGROUND)
event.add(self.aspectframe)
self.main_view.pack_start(info_scroll, False, False, 5)
self.main_view.pack_end(event, True, True, 5)
self.set_canvas(cajabase)
- self.bufferinfo = gtk.TextBuffer()
+ self.bufferinfo = Gtk.TextBuffer()
self.info.set_buffer(self.bufferinfo)
self.mooncalendar.set_mes(anio, mes, fecha, hora)
self.update_text_information_view()
@@ -231,12 +191,17 @@ class MoonActivity(activity.Activity):
def toggle_grid_clicked(self, widget= None):
self.luna_hoy.toggle_grid_clicked()
- self.mooncalendar.toggle_grid_clicked(widget= None, actualizar = self.mooncalendar in self.aspectframe.get_children())
+
+ self.mooncalendar.toggle_grid_clicked(
+ widget = None,
+ actualizar = self.mooncalendar in self.aspectframe.get_children())
def toggle_hemisphere_clicked(self, widget= None):
self.luna_hoy.toggle_hemisphere_clicked()
- self.mooncalendar.toggle_hemisphere_clicked(widget= None, actualizar = self.mooncalendar in self.aspectframe.get_children())
+ self.mooncalendar.toggle_hemisphere_clicked(
+ widget = None,
+ actualizar = self.mooncalendar in self.aspectframe.get_children())
def switch_calendar_luna(self, widget):
@@ -244,26 +209,28 @@ class MoonActivity(activity.Activity):
self.aspectframe.remove(self.mooncalendar)
self.aspectframe.add(self.luna_hoy)
self.luna_hoy.show_all()
+
elif self.luna_hoy in self.aspectframe.get_children():
self.aspectframe.remove(self.luna_hoy)
self.aspectframe.add(self.mooncalendar)
self.mooncalendar.show_all()
+
self.show_all()
self.realize()
def handle(self):
self.update_text_information_view()
+
if self.luna_hoy in self.aspectframe.get_children():
self.luna_hoy.actualizar()
+
return True
def repaint(self, widget= None, event= None):
- x,y,w,h= self.luna_hoy.get_allocation()
- anchoboton, altoboton = (w,h)
- tamanioboton = min( [anchoboton,altoboton] )
- self.luna_hoy.repaint(tamanioboton)
+ rect = self.luna_hoy.get_allocation()
+ self.luna_hoy.repaint(min( [rect.width, rect.height] ))
def delete_event(self, widget, event, data=None):
@@ -328,11 +295,15 @@ class MoonActivity(activity.Activity):
try:
read_file = open(file_path, 'r')
self.activity_state = json.loads(read_file.read())
+
if self.activity_state.has_key('hemisphereView'):
self.luna_hoy.hemisphere_view = self.activity_state['hemisphereView']
+
if self.activity_state.has_key('showGrid'):
self.luna_hoy.show_grid = self.activity_state['showGrid']
+
read_file.close()
+
except:
pass
@@ -346,13 +317,18 @@ class MoonActivity(activity.Activity):
self.activity_state['showGrid'] = self.luna_hoy.show_grid
serialised_data = json.dumps(self.activity_state)
to_journal = file(file_path, 'w')
+
try:
to_journal.write(serialised_data)
+
finally:
to_journal.close()
+
to_persistent_fs = file(os.environ['SUGAR_ACTIVITY_ROOT'] + '/data/defaults', 'w')
+
try:
to_persistent_fs.write(serialised_data)
+
finally:
to_persistent_fs.close()
\ No newline at end of file