diff options
author | Ignacio Rodríguez <ignaciorodriguez@sugarlabs.org> | 2012-12-17 00:59:15 (GMT) |
---|---|---|
committer | Ignacio Rodríguez <ignaciorodriguez@sugarlabs.org> | 2012-12-17 00:59:15 (GMT) |
commit | 06ca79d5196ed19d94527b0662c76d9009a1dd3a (patch) | |
tree | bfc5aef5186049cc906bb23b3b98b14648f96c86 | |
parent | 2b1fe95de2cba0d17dbcfd48a9b3bc456167bf3f (diff) |
Agregado soporte para sugar, en vez de gtk.MessageDialog se usan alertas.
-rw-r--r-- | Compress.py | 142 | ||||
-rw-r--r-- | CompressCanvas.py | 216 |
2 files changed, 178 insertions, 180 deletions
diff --git a/Compress.py b/Compress.py index 85d6b42..5d26227 100644 --- a/Compress.py +++ b/Compress.py @@ -17,100 +17,54 @@ # 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 -try: # gtk3 - from sugar30.activity import activity - from sugar3.activity.widgets import StopButton - from sugar3.activity.widgets import ActivityToolbarButton - from sugar3.graphics.toolbutton import ToolButton - from sugar3.graphics.toolbarbox import ToolbarBox - from gettext import gettext as _ # Traduccion - import utils3 as utils - from utils3 import Boton - from gi.repository import Gtk - Abrir = Boton(_("Abrir"),"Abrir") - Arriba = Boton(_('Arriba'),'up') - Home = Boton(_('Directorio Zip'),'gtk-home') - #open_from_journal = Boton(_("Open from journal"),"open-from-journal") - Add = Boton(_('Añadir archivo'),"add") - save = Boton(_('Guardar archivo:')) - Barra = ToolbarBox() - from CompressCanvas3 import Canvas_box as PyApp - from CompressCanvas3 import * - class Compress(activity.Activity): - def __init__(self, handle): - activity.Activity.__init__(self, handle, True) - canvas = PyApp() - Actividad = ActivityToolbarButton(self) - Parar = StopButton(self) - Parar.set_tooltip(_('Parar - Gtk3')) - #<-------------Separadores-------------># - Separador = Gtk.SeparatorToolItem() - Separador2 = Gtk.SeparatorToolItem() - Separador3 = Gtk.SeparatorToolItem() - Separador3.set_expand(True) - Separador3.props.draw = False - Barra.toolbar.insert(Actividad, 0) - Barra.toolbar.insert(Separador2, 1) - Barra.toolbar.insert(Add, 2) - Barra.toolbar.insert(Home,3) - Barra.toolbar.insert(Arriba,4) - Barra.toolbar.insert(Separador3, 5) - Barra.toolbar.insert(Abrir, 6) - Barra.toolbar.insert(save,7) - Barra.toolbar.insert(Separador3, 8) - Barra.toolbar.insert(Parar, 9) - - self.set_toolbar_box(Barra) # Barra - self.set_canvas(canvas) - self.show_all() - save.hide() -except ImportError: - import gtk - from sugar.activity import activity - from sugar.activity.widgets import StopButton - from sugar.activity.widgets import ActivityToolbarButton - from sugar.graphics.toolbutton import ToolButton - from sugar.graphics.toolbarbox import ToolbarBox - from gettext import gettext as _ # Traduccion - import utils - from utils import Boton - Abrir = Boton(_("Abrir"),"Abrir") - Arriba = Boton(_('Arriba'),'up') - Home = Boton(_('Directorio Zip'),'gtk-home') - #open_from_journal = Boton(_("Open from journal"),"open-from-journal") - Add = Boton(_('Añadir archivo'),"add") - save = Boton(_('Guardar archivo:')) - Barra = ToolbarBox() - from CompressCanvas import Canvas_box as PyApp - from CompressCanvas import * - class Compress(activity.Activity): - def __init__(self, handle): - activity.Activity.__init__(self, handle, True) - canvas = PyApp() - Actividad = ActivityToolbarButton(self) - Parar = StopButton(self) - Parar.set_tooltip(_('Parar - Gtk2')) - #<-------------Separadores-------------># - Separador = gtk.SeparatorToolItem() - Separador2 = gtk.SeparatorToolItem() - Separador3 = gtk.SeparatorToolItem() - Separador3.set_expand(True) - Separador3.props.draw = False - Barra.toolbar.insert(Actividad, 0) - Barra.toolbar.insert(Separador2, 1) - Barra.toolbar.insert(Add, 2) - Barra.toolbar.insert(Home,3) - Barra.toolbar.insert(Arriba,4) - Barra.toolbar.insert(Separador3, 5) - Barra.toolbar.insert(Abrir, 6) - Barra.toolbar.insert(save,7) - Barra.toolbar.insert(Separador3, 8) - Barra.toolbar.insert(Parar, 9) - - self.set_toolbar_box(Barra) # Barra - self.set_canvas(canvas) - self.show_all() - save.hide() +import gtk +from sugar.activity import activity +from sugar.activity.widgets import StopButton +from sugar.activity.widgets import ActivityToolbarButton +from sugar.graphics.toolbutton import ToolButton +from sugar.graphics.toolbarbox import ToolbarBox +from gettext import gettext as _ # Traduccion +import utils +from utils import Boton +Abrir = Boton(_("Abrir"), "Abrir") +Arriba = Boton(_('Arriba'), 'up') +Home = Boton(_('Directorio Zip'), 'gtk-home') +#open_from_journal = Boton(_("Open from journal"),"open-from-journal") +Add = Boton(_('Añadir archivo'), "add") +save = Boton(_('Guardar archivo:')) +newdirectory = Boton(_('New directory'),'nuevodirectorio') +Barra = ToolbarBox() +from CompressCanvas import Canvas_box as PyApp +from CompressCanvas import * +class Compress(activity.Activity): + def __init__(self, handle): + activity.Activity.__init__(self, handle, True) + canvas = PyApp(self) + Actividad = ActivityToolbarButton(self) + Parar = StopButton(self) + Parar.set_tooltip(_('Parar - Gtk2')) + #<-------------Separadores-------------># + Separador = gtk.SeparatorToolItem() + Separador2 = gtk.SeparatorToolItem() + Separador3 = gtk.SeparatorToolItem() + Separador3.set_expand(True) + Separador3.props.draw = False + Barra.toolbar.insert(Actividad, 0) + Barra.toolbar.insert(Separador2, 1) + Barra.toolbar.insert(Add, 2) + Barra.toolbar.insert(Home,3) + Barra.toolbar.insert(Arriba,4) + Barra.toolbar.insert(Separador3, 5) + Barra.toolbar.insert(newdirectory, 6) + Barra.toolbar.insert(Separador3, 7) + Barra.toolbar.insert(Abrir, 8) + Barra.toolbar.insert(save,9) + Barra.toolbar.insert(Separador3, 10) + Barra.toolbar.insert(Parar, 11) + self.set_toolbar_box(Barra) # Barra + self.set_canvas(canvas) + self.show_all() + save.hide() diff --git a/CompressCanvas.py b/CompressCanvas.py index 11bd0c3..af211fa 100644 --- a/CompressCanvas.py +++ b/CompressCanvas.py @@ -21,7 +21,9 @@ try: from Compress import * import utils import gtk,os,shutil,gobject,pygtk + from sugar.graphics.alert import NotifyAlert,Alert from sugar.graphics.objectchooser import ObjectChooser + from sugar.graphics.icon import Icon from sugar.datastore import datastore shutil.rmtree('/tmp/Compress') os.mkdir('/tmp/Compress') @@ -31,7 +33,6 @@ except: from gettext import gettext as _ Archivo = None # CONSTANTES # -Directorio = _("Nuevo directorio") Hboxx = gtk.HBox() Uri = gtk.Entry() Uri.set_text(os.getcwd()) @@ -42,17 +43,18 @@ entrada = gtk.Entry() entrada.props.secondary_icon_stock = 'gtk-apply' entrada.props.secondary_icon_activatable = True botons = gtk.Button(gtk.STOCK_OK) -save = utils.Boton(_('Guardar archivo'),'document-save') -entrada.set_text(_("Para que los cambios se guarden presione la tecla '↵' o el icono √ ")) +save = utils.Boton(_('Save file'),'document-save') +entrada.set_text(_("For the changes be saved press the '↵' key or the √ icon ")) +entry = gtk.Entry() ### - class Canvas(gtk.TreeView): - def __init__(self): + def __init__(self, actividad): self.modelo = None self.treeview_arbol = None self.barra_de_estado = None gtk.TreeView.__init__(self) + self.actividad = actividad try: Home.connect('clicked',self.home) Abrir.connect('clicked',self.open,True) @@ -60,11 +62,11 @@ class Canvas(gtk.TreeView): save.connect('clicked',self.copiar_al_diario) # open_from_journal.connect('clicked',self.open_diario) Add.connect('clicked',self.anadir) + newdirectory.connect('clicked',self.new_directory) except: pass Uri.connect('activate',self.change) Uri.connect("icon-press", self.change) - self.set_tooltip_text(_('Archivos en el directorio')) self.set_property("rules-hint", True) entrada.connect('icon-press',self.update,entrada) entrada.connect('activate',self.update_e,entrada) @@ -106,6 +108,38 @@ class Canvas(gtk.TreeView): Uri.set_text(os.getcwd()) Uri.show() self.set_model(self.construir_lista()) + def new_directory(self,widget): + alerta = Alert() + hbox = alerta._hbox + hbox.pack_end(entry) + alerta.props.title = _('New directory') + alerta.props.msg = _("Write a name for the directory") + ok_icon = Icon(icon_name='dialog-ok') + cancel_icon = Icon(icon_name='dialog-cancel') + hbox.show_all() + alerta.add_button(gtk.RESPONSE_OK,_('Ok'), ok_icon) + alerta.add_button(gtk.RESPONSE_CANCEL,_('Cancel'), cancel_icon) + alerta.connect('response',self.quehacemos) + self.actividad.add_alert(alerta) + def quehacemos(self,widget,respuesta): + if respuesta == gtk.RESPONSE_CANCEL: + entry.set_text("") + entry.show() + self.actividad.remove_alert(widget) + if entry.get_text() != "": + self.actividad.remove_alert(widget) + direccion = str(entry.get_text()) + os.mkdir(direccion) + entry.set_text("") + entry.show() + self.set_model(self.construir_lista()) + if entry.get_text == "" and respuesta == gtk.RESPONSE_OK: + self.actividad.remove_alert(widget) + alerta = NotifyAlert(10) + alerta.props.msg = _('Please specify a directory') + alerta.connect('response', lambda w, + i: self.actividad.remove_alert(w)) + self.actividad.add_alert(alerta) def archivo_clickeado(self, seleccion, modelo, archivo, seleccionado, a): # Cuando se selecciona iter= modelo.get_iter(archivo) directorio = modelo.get_value(iter,0) @@ -114,20 +148,24 @@ class Canvas(gtk.TreeView): if 'image' in estado: self.icon_name = 'imagen' - save.set_tooltip(_('Guardar imagen: '+utils.Archivos+' al diario')) + save.set_tooltip(_('Save image: '+utils.Archivos+' to journal')) if 'text' in estado: self.icon_name = 'texto' - save.set_tooltip(_('Guardar texto: '+utils.Archivos+' al diario')) + save.set_tooltip(_('Save text: '+utils.Archivos+' to journal')) if 'audio' in estado: self.icon_name = 'audio' - save.set_tooltip(_('Guardar audio: '+utils.Archivos+' al diario')) + save.set_tooltip(_('Save audio: '+utils.Archivos+' to journal')) if 'video' in estado: self.icon_name = 'video' save.set_tooltip(_('Guardar: '+utils.Archivos+' al diario')) if not 'directory' in estado and not 'no read permission' in estado: - save.set_icon_name(self.icon_name) - save.show() + try: + save.set_icon_name(self.icon_name) + save.show() + except: + save.set_icon(self.icon_name) + save.show() else: save.hide() return True @@ -165,13 +203,12 @@ class Canvas(gtk.TreeView): utils.decompress(Archivo,Hboxx,'/tmp/Compress/Work','Abrir',True) except IOError: - Mensaje = _("""Oh..Parece que no selecciono un archivo zip""") - info = gtk.MessageDialog(type=gtk.MESSAGE_WARNING, buttons=gtk.BUTTONS_OK,message_format=Mensaje) - a = info.run() - if a == gtk.RESPONSE_OK: - info.destroy() - self.set_model(self.construir_lista()) - Uri.set_text(os.getcwd()) + alerta = NotifyAlert(10) + alerta.props.msg = _('Error when trying cut: %s')%utils.Archivos + alerta.connect('response', lambda w, + i,z,e: self.actividad.remove_alert(w), self.set_model(self.construir_lista()),Uri.set_text(os.getcwd())) + self.actividad.add_alert(alerta) + def construir_lista(self): store = gtk.ListStore(str) dirList=os.listdir(os.getcwd()) @@ -189,8 +226,7 @@ class Canvas(gtk.TreeView): return store def descomprimir_en(self,widget=None): if not self.presentado: - label = gtk.Label(_('Carpeta:')) - + label = gtk.Label(_('Directory:')) #entrada.set_text('/tmp/Compress/Work') boton = gtk.Button(gtk.STOCK_OPEN) botona = gtk.Button(gtk.STOCK_CANCEL) @@ -221,7 +257,7 @@ class Canvas(gtk.TreeView): self.descomprimir_en() Estado = True def construir_columnas(self): - columna= gtk.TreeViewColumn(_('Archivos en el directorio')) + columna= gtk.TreeViewColumn(_('Files in the directory')) celda_de_texto = gtk.CellRendererText() # para el texto columna.pack_start(celda_de_texto, True) self.append_column (columna) @@ -244,7 +280,7 @@ class Canvas(gtk.TreeView): image.show() ventana.show() except IOError: - self.ops(_('imagen')) + self.ops(_('image')) if not 'binary' in Archivo: try: ventana.set_size_request(gtk.gdk.screen_width()/2,gtk.gdk.screen_height()/2) @@ -257,19 +293,19 @@ class Canvas(gtk.TreeView): ventana.add(texta) ventana.show_all() except IOError: - self.ops(_('archivo')) + self.ops(_('file')) else: try: os.chdir(os.getcwd()+target) self.set_model(self.construir_lista()) except: - self.ops(_('directorio')) + self.ops(_('directory')) Uri.set_text(os.getcwd()) Uri.show() def create_columns(self, treeView): rendererText = gtk.CellRendererText() img = celda_de_imagen = gtk.CellRendererPixbuf() - column = gtk.TreeViewColumn(_('Archivos en el directorio')) + column = gtk.TreeViewColumn(_('Files in the directory')) column.set_sort_column_id(0) column.pack_start(rendererText,False) column.set_attributes(rendererText, text=0) @@ -287,26 +323,26 @@ class Canvas(gtk.TreeView): if Boton == 3: if utils.Archivo_d == None: if 'zip' in Archivo: - Abrir = gtk.MenuItem(_('Abrir zip')) + Abrir = gtk.MenuItem(_('Open zip')) Abrir.connect('activate',self.open) Menu.append(Abrir) else: pass else: - Close = gtk.MenuItem(_('Cerrar zip: %s'%utils.Archivo_d)) + Close = gtk.MenuItem(_('Close zip: %s'%utils.Archivo_d)) Close.connect('activate',self.close) Menu.append(Close) Menu.append(gtk.SeparatorMenuItem()) Copy = gtk.MenuItem(_('Copiar')) Copy.connect('activate',self.copy) if 'zip' in Archivo: - Des = gtk.MenuItem(_('Descomprimir')) + Des = gtk.MenuItem(_('Uncompress')) Des.connect('activate',self.descomprimir) - Cut = gtk.MenuItem(_('Cortar')) + Cut = gtk.MenuItem(_('Cut')) Cut.connect('activate',self.cut) - Delete = gtk.MenuItem(_('Borrar')) + Delete = gtk.MenuItem(_('Delete')) Delete.connect('activate',self.sure) - CompressFile= gtk.MenuItem(_('Comprimir este archivo')) + CompressFile= gtk.MenuItem(_('Compress this file')) CompressFile.connect('activate',self.compress_file,utils.Archivos) Menu.append(CompressFile) try: @@ -315,7 +351,7 @@ class Canvas(gtk.TreeView): pass Menu.append(gtk.SeparatorMenuItem()) if utils.Archivo_d != None: - Copyw = gtk.MenuItem(_('Copiar al zip')) + Copyw = gtk.MenuItem(_('Copy to zip')) Copyw.connect('activate',self.copy,True) Menu.append(Copyw) Menu.append(Copy) @@ -324,7 +360,7 @@ class Canvas(gtk.TreeView): Back = gtk.MenuItem(_('Atras')) Back.connect('activate',self.back) if os.listdir('/tmp/Compress/') != ['Work']: - Paste = gtk.MenuItem(_('Pegar')) + Paste = gtk.MenuItem(_('Paste')) Paste.connect('activate',self.paste) Menu.append(Paste) Menu.append(gtk.SeparatorMenuItem()) @@ -338,16 +374,19 @@ class Canvas(gtk.TreeView): self.back() if Boton == 65535: # Solo existe en la 1.5 y en las magallanes self.sure() - def delete(self,widget=None): - try: + def delete(self,widget=None,estado=None): + if estado == gtk.RESPONSE_CANCEL: + self.actividad.remove_alert(widget) + else: + self.actividad.remove_alert(widget) try: - os.remove(os.getcwd()+"/"+utils.Archivos) + try: + os.remove(os.getcwd()+"/"+utils.Archivos) + except: + shutil.rmtree(os.getcwd()+utils.Archivos) except: - shutil.rmtree(os.getcwd()+utils.Archivos) - except: - self.errores('Desconocido') - - self.set_model(self.construir_lista()) + self.errores('Desconocido') + self.set_model(self.construir_lista()) def cut(self,widget): try: self.Copiado = utils.Archivos @@ -378,7 +417,7 @@ class Canvas(gtk.TreeView): os.chdir(widget.get_text()) self.set_model(self.construir_lista()) except: - self.ops(_('directorio')) + self.ops(_('directory')) def copy(self,widget,W=False): try: self.Copiado = utils.Archivos @@ -399,36 +438,36 @@ class Canvas(gtk.TreeView): except: self.errores('Copiar') def sure(self,widget=None): - info = gtk.MessageDialog(type=gtk.MESSAGE_WARNING, buttons=gtk.BUTTONS_YES_NO, - message_format=_("Seguro que desea borrar el archivo: %s" %utils.Archivos)) - respuesta = info.run() - if respuesta == gtk.RESPONSE_YES: - self.delete() - info.destroy() - else: - info.destroy() + alerta = Alert() + alerta.props.title = _('Sure?') + alerta.props.msg = _("Are you sure you want to delete this file: %s ?" %utils.Archivos) + ok_icon = Icon(icon_name='dialog-ok') + cancel_icon = Icon(icon_name='dialog-cancel') + alerta.add_button(gtk.RESPONSE_OK,_('Ok'), ok_icon) + alerta.add_button(gtk.RESPONSE_CANCEL,_('Cancel'), cancel_icon) + alerta.connect('response',self.delete) + self.actividad.add_alert(alerta) def ops(self,donde): - info = gtk.MessageDialog(type=gtk.MESSAGE_WARNING, buttons=gtk.BUTTONS_OK, - message_format=_("Error al acceder al "+donde+" razón:\n%s" %self.razon(str(Uri.get_text()),donde))) - respuesta = info.run() - if respuesta == gtk.RESPONSE_OK: - Ant = os.getcwd() - os.chdir(Ant) - Uri.set_text(os.getcwd()) - Uri.show() - info.destroy() + alerta = NotifyAlert(10) + alerta.props.msg = _('Error accessing to '+donde+' razón:\n%s' %self.razon(str(Uri.get_text()),donde)) + Ant = os.getcwd() + alerta.connect('response', lambda w, + i,z,x,d: self.actividad.remove_alert(w),os.chdir(Ant),Uri.set_text(os.getcwd()),Uri.show()) + self.actividad.add_alert(alerta) + +### def razon(self,directorio,razon): if not os.path.exists(directorio): - return _("El "+razon+" no existe") + return _("The "+razon+" no exist") else: try: open(directorio) except: - return _("No tiene acceso a ese "+razon ) + return _("You have not got access for this "+razon ) try: open(directorio+"/") except: - return _(directorio+" no es un directorio") + return _(directorio+" It is not a directory") def home(self,widget=None): os.chdir('/tmp/Compress/Work') Uri.set_text(os.getcwd()) @@ -446,39 +485,44 @@ class Canvas(gtk.TreeView): acopiar.destroy() def errores(self,Evento=None): if Evento == "Copiar": - info = gtk.MessageDialog(type=gtk.MESSAGE_WARNING, buttons=gtk.BUTTONS_OK,message_format=_("Error al intentar copiar: %s "%utils.Archivos)) + info = gtk.MessageDialog(type=gtk.MESSAGE_WARNING, buttons=gtk.BUTTONS_OK,message_format=_("Error when trying copy: %s "%utils.Archivos)) a = info.run() if a == gtk.RESPONSE_OK: info.destroy() if Evento == "Cortar": - info = gtk.MessageDialog(type=gtk.MESSAGE_WARNING, buttons=gtk.BUTTONS_OK,message_format=_("Error al intentar cortar: %s "%utils.Archivos)) - a = info.run() - if a == gtk.RESPONSE_OK: - info.destroy() + alerta = NotifyAlert(10) + alerta.props.msg = _('Error when trying cut: %s')%utils.Archivos + alerta.connect('response', lambda w, + i: self.actividad.remove_alert(w)) + self.actividad.add_alert(alerta) if Evento == "Pegar_None": - info = gtk.MessageDialog(type=gtk.MESSAGE_WARNING, buttons=gtk.BUTTONS_OK,message_format=_("Error: No hay nada en el portapapeles" )) - a = info.run() - if a == gtk.RESPONSE_OK: - info.destroy() + alerta = NotifyAlert(10) + alerta.props.msg = _('Error: It is not nothing in the clipboard') + alerta.connect('response', lambda w, + i: self.actividad.remove_alert(w)) + self.actividad.add_alert(alerta) if Evento == "Pegar": - info = gtk.MessageDialog(type=gtk.MESSAGE_WARNING, buttons=gtk.BUTTONS_OK,message_format=_("Error al intentar pegar un archivo" )) - a = info.run() - if a == gtk.RESPONSE_OK: - info.destroy() + alerta = NotifyAlert(10) + alerta.props.msg = _('Error when trying paste a file') + alerta.connect('response', lambda w, + i: self.actividad.remove_alert(w)) + self.actividad.add_alert(alerta) if Evento == 'Copiar_a_nada': - info = gtk.MessageDialog(type=gtk.MESSAGE_WARNING, buttons=gtk.BUTTONS_OK,message_format=_("¡Ups! Parece que aún no abrio ningun archivo")) - a = info.run() - if a == gtk.RESPONSE_OK: - info.destroy() + alerta = NotifyAlert(10) + alerta.props.msg = _('Ups! Seems not yet opened any file') + alerta.connect('response', lambda w, + i: self.actividad.remove_alert(w)) + self.actividad.add_alert(alerta) if Evento == 'Desconocido': - info = gtk.MessageDialog(type=gtk.MESSAGE_WARNING, buttons=gtk.BUTTONS_OK,message_format=_("Error desconocido")) - a = info.run() - if a == gtk.RESPONSE_OK: - info.destroy() + alerta = NotifyAlert(10) + alerta.props.msg = _('Unknown error') + alerta.connect('response', lambda w, + i: self.actividad.remove_alert(w)) + self.actividad.add_alert(alerta) class Canvas_box(gtk.EventBox): - def __init__(self): + def __init__(self, actividad): gtk.EventBox.__init__(self) - + self.actividad = actividad vbox = gtk.VBox(False, 8) xhbox = gtk.HBox() sw = gtk.ScrolledWindow() @@ -491,7 +535,7 @@ class Canvas_box(gtk.EventBox): Logo = gtk.Image() Logo.set_from_file('icons/ceibaljam.svg') hbox.pack_start(sw, True, True, 0) - sw.add(Canvas()) + sw.add(Canvas(self.actividad)) hx = gtk.HBox() Logo2 = gtk.Image() Logo.set_tooltip_text('http://www.ceibaljam.org') |