#!/usr/bin/env python # -*- coding: utf-8 -*- # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # 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 # toolbar.py por: # Flavio Danesse # CeibalJAM! - Uruguay # Basado en código de: Keshav Sharma & Vaibhav Sharma import gtk, pygtk, gobject, os from gettext import gettext as _ DIRECTORIO_BASE= os.path.dirname(__file__) ICONOS= os.path.join(DIRECTORIO_BASE, "icons/") class ViewToolbar(gtk.Toolbar): __gtype_name__ = 'ViewToolbar' __gsignals__ = {'abrir_archivo':(gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), 'guardar_archivo':(gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), 'zoom_in': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), 'zoom_out': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), 'zoom_to_fit': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), 'rotate_clockwise': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), 'rotate_anticlockwise': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), 'undo': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), 'redo': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), 'cam_cb': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,([]))} def __init__(self): gtk.Toolbar.__init__(self) open_button = IPButtonStock(gtk.STOCK_OPEN) open_button.connect('clicked', self.abrir_archivo) self.insert(open_button, -1) open_button.show() save_button = IPButtonStock(gtk.STOCK_SAVE) save_button.connect('clicked', self.guardar_archivo) self.insert(save_button, -1) save_button.show() save_as_button = IPButtonStock(gtk.STOCK_SAVE_AS) #self._zoom_out_button.connect('clicked', self.zoom_out_cb) self.insert(save_as_button, -1) save_as_button.show() separator = gtk.SeparatorToolItem() separator.props.draw = False separator.set_size_request(0, -1) separator.set_expand(True) self.insert(separator, -1) zoom_out_button = IPButtonStock(gtk.STOCK_ZOOM_OUT) zoom_out_button.connect('clicked', self.zoom_out_cb) self.insert(zoom_out_button, -1) zoom_out_button.show() zoom_in_button = IPButtonStock(gtk.STOCK_ZOOM_IN) zoom_in_button.connect('clicked', self.zoom_in_cb) self.insert(zoom_in_button, -1) zoom_in_button.show() zoom_tofit_button = IPButtonStock(gtk.STOCK_ZOOM_FIT) zoom_tofit_button.connect('clicked', self.zoom_to_fit_cb) self.insert(zoom_tofit_button, -1) zoom_tofit_button.show() separator = gtk.SeparatorToolItem() separator.props.draw = False separator.set_size_request(0, -1) separator.set_expand(True) self.insert(separator, -1) rotate_anticlockwise_button = IPButton('rotate_anticlockwise.svg') rotate_anticlockwise_button.connect('clicked', self.rotate_anticlockwise_cb) self.insert(rotate_anticlockwise_button, -1) rotate_anticlockwise_button.show() rotate_clockwise_button = IPButton('rotate_clockwise.svg') rotate_clockwise_button.connect('clicked', self.rotate_clockwise_cb) self.insert(rotate_clockwise_button, -1) rotate_clockwise_button.show() separator = gtk.SeparatorToolItem() separator.props.draw = False separator.set_size_request(0, -1) separator.set_expand(True) self.insert(separator, -1) undo_button = IPButtonStock(gtk.STOCK_UNDO) undo_button.connect('clicked', self.undo_cb) self.insert(undo_button, -1) undo_button.show() redo_button = IPButtonStock(gtk.STOCK_REDO) redo_button.connect('clicked', self.redo_cb) self.insert(redo_button, -1) redo_button.show() separator = gtk.SeparatorToolItem() separator.props.draw = False separator.set_size_request(0, -1) separator.set_expand(True) self.insert(separator, -1) cam_button = IPButton('foto.png') cam_button.connect('clicked', self.cam_cb) self.insert(cam_button, -1) cam_button.show() separator = gtk.SeparatorToolItem() separator.props.draw = False separator.set_size_request(0, -1) separator.set_expand(True) self.insert(separator, -1) def abrir_archivo(self, button): self.emit('abrir_archivo') def guardar_archivo(self, button): self.emit('guardar_archivo') def zoom_in_cb(self, button): self.emit('zoom_in') def zoom_out_cb(self, button): self.emit('zoom_out') def zoom_to_fit_cb(self, button): self.emit('zoom_to_fit') def rotate_clockwise_cb(self, button): self.emit('rotate_clockwise') def rotate_anticlockwise_cb(self, button): self.emit('rotate_anticlockwise') def undo_cb(self, button): self.emit('undo') def redo_cb(self, button): self.emit('redo') def cam_cb(self, button): self.emit('cam_cb') class EditToolbar(gtk.Toolbar): __gtype_name__ = 'EditToolbar' __gsignals__ = {'grey': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,([])), 'blur': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), 'transpose': (gobject.SIGNAL_RUN_FIRST,gobject.TYPE_NONE, ([])), 'offset': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), 'contour': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), 'text': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,([])), 'finedges': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,([])), 'solarize': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), 'invert': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,([])), 'ambross': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,([])), 'left_top': (gobject.SIGNAL_RUN_FIRST,gobject.TYPE_NONE,([])), 'right_top': (gobject.SIGNAL_RUN_FIRST,gobject.TYPE_NONE,([])), 'left_bottom': (gobject.SIGNAL_RUN_FIRST,gobject.TYPE_NONE,([])), 'right_bottom': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,([])), 'sharpen': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,([]))} def __init__(self): gtk.Toolbar.__init__(self) self.grey = IPButton('grey.png') self.grey.connect('clicked', self.grey_cb) self.insert(self.grey, -1) self.grey.show() self.blur = IPButton('blur.png') self.blur.connect('clicked', self.blur_cb) self.insert(self.blur, -1) self.blur.show() self.transpose = IPButton('mirror.png') self.transpose.connect('clicked', self.transpose_cb) self.insert(self.transpose, -1) self.transpose.show() self.offset = IPButton('offset.png') self.offset.connect('clicked', self.offset_cb) self.insert(self.offset, -1) self.offset.show() self.contour = IPButton('contour.png') self.contour.connect('clicked', self.contour_cb) self.insert(self.contour, -1) self.contour.show() self.finedges = IPButton('finedges.png') self.finedges.connect('clicked', self.finedges_cb) self.insert(self.finedges, -1) self.finedges.show() self.solarize = IPButton('solarize.png') self.solarize.connect('clicked', self.solarize_cb) self.insert(self.solarize, -1) self.solarize.show() self.invert = IPButton('invert.png') self.invert.connect('clicked', self.invert_cb) self.insert(self.invert, -1) self.invert.show() self.ambross = IPButton('embross.png') self.ambross.connect('clicked', self.ambross_cb) self.insert(self.ambross, -1) self.ambross.show() self.sharpen = IPButton('sharpen.png') self.sharpen.connect('clicked', self.sharpen_cb) self.insert(self.sharpen, -1) self.sharpen.show() def grey_cb(self, button): self.emit('grey') def blur_cb(self, button): self.emit('blur') def transpose_cb(self, button): self.emit('transpose') def offset_cb(self, button): self.emit('offset') def contour_cb(self, button): self.emit('contour') def finedges_cb(self, button): self.emit('finedges') def solarize_cb(self, button): self.emit('solarize') def invert_cb(self, button): self.emit('invert') def ambross_cb(self, button): self.emit('ambross') def sharpen_cb(self, button): self.emit('sharpen') class IPButton(gtk.ToggleToolButton): def __init__(self, archivo): gtk.ToggleToolButton.__init__(self) imagen = gtk.Image() pixbuf= gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(ICONOS,archivo), 32, 32) imagen.set_from_pixbuf(pixbuf) self.set_icon_widget(imagen) imagen.show() self.show() class IPButtonStock(gtk.ToggleToolButton): def __init__(self, nombre): gtk.ToggleToolButton.__init__(self) imagen = gtk.Image() imagen.set_from_stock(nombre, gtk.ICON_SIZE_BUTTON) self.set_icon_widget(imagen) imagen.show() self.show()