Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/toolbar.py
diff options
context:
space:
mode:
authorGonzalo Odiard <godiard@sugarlabs.org>2011-03-20 05:50:43 (GMT)
committer Gonzalo Odiard <godiard@sugarlabs.org>2011-03-20 05:50:43 (GMT)
commitdbfdfbb8e5a08afb021cb732c85010a841c46152 (patch)
tree8be874e44f37842892ad912023a711410f05822e /toolbar.py
parent9d3be29ed69d46d32fed668a85d5ebda1fb8f7c9 (diff)
pep8 fixes in toolbar.py
Diffstat (limited to 'toolbar.py')
-rw-r--r--toolbar.py192
1 files changed, 100 insertions, 92 deletions
diff --git a/toolbar.py b/toolbar.py
index 47b6f1f..2151252 100644
--- a/toolbar.py
+++ b/toolbar.py
@@ -20,11 +20,10 @@ from gettext import gettext as _
import logging
import os
import time
-
-import gtk, pango, pangocairo
-
+import gtk
+import pango
+import pangocairo
import globos
-
from sugar.graphics.icon import Icon
from sugar.graphics.toolbutton import ToolButton
from sugar.graphics.toggletoolbutton import ToggleToolButton
@@ -35,38 +34,40 @@ from sugar.graphics.objectchooser import ObjectChooser
WITH_COLOR_BUTTON = True
try:
from sugar.graphics.colorbutton import ColorToolButton
-
+
##Class to manage the Text Color
class TextButtonColor(ColorToolButton):
##The Constructor
def __init__(self, page):
ColorToolButton.__init__(self)
self._page = page
-
+
self.connect('color-set', self._color_button_cb)
-
+
def _color_button_cb(self, widget):
color = self.get_color()
self.set_text_color(color)
-
+
def alloc_color(self, color):
colormap = self._page.get_colormap()
return colormap.alloc_color(color.red, color.green, color.blue)
-
+
def set_text_color(self, color):
globo_activo = self._page.get_globo_activo()
if (globo_activo != None):
newcolor = self.alloc_color(color)
texto = globo_activo.texto
- texto.color_r,texto.color_g,texto.color_b = (newcolor.red / 65535.0),(newcolor.green / 65535.0),(newcolor.blue / 65535.0)
- self._page.get_active_box().queue_draw()
-
+ texto.color_r = newcolor.red / 65535.0
+ texto.color_g = newcolor.green / 65535.0
+ texto.color_b = newcolor.blue / 65535.0
+ self._page.get_active_box().queue_draw()
+
except:
WITH_COLOR_BUTTON = False
-
logger = logging.getLogger('fototoon-activity')
+
class GlobesManager():
def __init__(self, toolbar, page, activity):
@@ -89,31 +90,31 @@ class GlobesManager():
self.b_agregar.connect('clicked', self.agrega_gnormal)
self.b_agregar.set_tooltip(_('Add Globe'))
toolbar.insert(self.b_agregar, -1)
-
+
#agrega nube
self.b_agregar = ToolButton('add-nube')
self.b_agregar.connect('clicked', self.agrega_gpensar)
self.b_agregar.set_tooltip(_('Add Think'))
toolbar.insert(self.b_agregar, -1)
-
+
# agrega susurro
self.b_agregar = ToolButton('add-susurro')
self.b_agregar.connect('clicked', self.agrega_gdespacio)
self.b_agregar.set_tooltip(_('Add Whisper'))
toolbar.insert(self.b_agregar, -1)
-
+
# agrega grito
self.b_agregar = ToolButton('add-grito')
self.b_agregar.connect('clicked', self.agrega_ggrito)
self.b_agregar.set_tooltip(_('Add Exclamation'))
toolbar.insert(self.b_agregar, -1)
-
+
# agrega caja
self.b_agregar = ToolButton('add-box')
self.b_agregar.connect('clicked', self.agrega_grect)
self.b_agregar.set_tooltip(_('Add Box'))
toolbar.insert(self.b_agregar, -1)
-
+
separator = gtk.SeparatorToolItem()
separator.set_draw(True)
toolbar.insert(separator, -1)
@@ -130,23 +131,21 @@ class GlobesManager():
self.b_borrar.set_tooltip(_('Delete'))
toolbar.insert(self.b_borrar, -1)
-
-
def agrega_gnormal(self, boton):
self._page.get_active_box().add_globo(60, 60)
def agrega_gpensar(self, boton):
self._page.get_active_box().add_nube(60, 60)
-
+
def agrega_gdespacio(self, boton):
- self._page.get_active_box().add_globo(60, 60,gmodo="despacio")
-
+ self._page.get_active_box().add_globo(60, 60, gmodo="despacio")
+
def agrega_ggrito(self, boton):
self._page.get_active_box().add_grito(60, 60)
-
+
def agrega_grect(self, boton):
self._page.get_active_box().add_rectangulo(60, 60)
-
+
def agrega_imagen(self, boton):
self._page.get_active_box().add_imagen(60, 60)
@@ -157,20 +156,20 @@ class GlobesManager():
if (box.get_globo_activo() != None):
print "globo activo",
globe = box.get_globo_activo()
- if (globe.__class__ != globos.Rectangulo):
+ if (globe.__class__ != globos.Rectangulo):
if (globe.direccion == globos.DIR_ABAJO):
- globe.direccion = globos.DIR_IZQ
+ globe.direccion = globos.DIR_IZQ
elif (globe.direccion == globos.DIR_IZQ):
- globe.direccion = globos.DIR_ARRIBA
+ globe.direccion = globos.DIR_ARRIBA
elif (globe.direccion == globos.DIR_ARRIBA):
- globe.direccion = globos.DIR_DER
+ globe.direccion = globos.DIR_DER
elif (globe.direccion == globos.DIR_DER):
- globe.direccion = globos.DIR_ABAJO
- globe.punto[0],globe.punto[1] = globe.punto[1],globe.punto[0]
-
+ globe.direccion = globos.DIR_ABAJO
+ globe.punto[0] = globe.punto[1]
+ globe.punto[1] = globe.punto[0]
box.queue_draw()
def borrar(self, boton):
@@ -181,21 +180,20 @@ class GlobesManager():
box.globos.remove(box.get_globo_activo())
box.set_globo_activo(None)
box.queue_draw()
-
else:
# Borrar un box es mas complicado
print "borrando box"
pos_box = self._page.boxs.index(box)
if (len(self._page.boxs) > pos_box):
- for i in range(pos_box,len(self._page.boxs)-1):
+ for i in range(pos_box, len(self._page.boxs) - 1):
box1 = self._page.boxs[i]
- box2 = self._page.boxs[i+1]
+ box2 = self._page.boxs[i + 1]
box1.image = None
box1.image_name = box2.image_name
box1.globos = []
box1.globos.extend(box2.globos)
box1.queue_draw()
- last_box = self._page.boxs[-1]
+ last_box = self._page.boxs[-1]
last_box.image = None
last_box.image_name = ""
last_box.globos = []
@@ -203,22 +201,26 @@ class GlobesManager():
self._page.boxs.pop()
def _image_cb(self, button):
-
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(_('Choose image'), self._activity,
- # gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT)
+ 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)
try:
result = chooser.run()
print result, gtk.RESPONSE_ACCEPT
if result == gtk.RESPONSE_ACCEPT:
- logging.debug('ObjectChooser: %r' % chooser.get_selected_object())
+ logging.debug('ObjectChooser: %r' %
+ chooser.get_selected_object())
jobject = chooser.get_selected_object()
if jobject and jobject.file_path:
- print "imagen seleccionada:",jobject.file_path
- tempfile_name = os.path.join(self._activity.get_activity_root(), 'instance', 'tmp%i' % time.time())
+ print "imagen seleccionada:", jobject.file_path
+ tempfile_name = \
+ os.path.join(self._activity.get_activity_root(),
+ 'instance', 'tmp%i' % time.time())
os.link(jobject.file_path, tempfile_name)
self._page.add_box_from_journal_image(tempfile_name)
finally:
@@ -226,7 +228,6 @@ class GlobesManager():
del chooser
-
class TextToolbar(gtk.Toolbar):
def __init__(self, page):
@@ -250,7 +251,8 @@ class TextToolbar(gtk.Toolbar):
"""
self._underline = ToggleToolButton('format-text-underline')
self._underline.set_tooltip(_('Underline'))
- self._underline_id = self._underline.connect('clicked', self._underline_cb)
+ self._underline_id = self._underline.connect('clicked',
+ self._underline_cb)
self.insert(self._underline, -1)
self._underline.show()
"""
@@ -263,33 +265,37 @@ class TextToolbar(gtk.Toolbar):
self.insert(item, -1)
else:
self._text_color = gtk.ColorButton()
- self._text_color_id = self._text_color.connect('color-set', self._text_color_cb)
+ self._text_color_id = self._text_color.connect('color-set',
+ self._text_color_cb)
tool_item = gtk.ToolItem()
tool_item.add(self._text_color)
self.insert(tool_item, -1)
tool_item.show_all()
-
+
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)
+ # tamanio
+ self._font_size_icon = Icon(icon_name="format-text-size",
+ icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR)
tool_item = gtk.ToolItem()
tool_item.add(self._font_size_icon)
self.insert(tool_item, -1)
self._font_size_combo = ComboBox()
- self._font_sizes = ['8', '10', '12', '14', '16', '20', '22', '24', '26', '28', '36', '48', '72']
- self._font_size_changed_id = self._font_size_combo.connect('changed', self._font_size_changed_cb)
+ self._font_sizes = ['8', '10', '12', '14', '16', '20', '22', '24', \
+ '26', '28', '36', '48', '72']
+ self._font_size_changed_id = self._font_size_combo.connect('changed',
+ self._font_size_changed_cb)
for i, s in enumerate(self._font_sizes):
self._font_size_combo.append_item(i, s, None)
if s == '12':
self._font_size_combo.set_active(i)
tool_item = ToolComboBox(self._font_size_combo)
- self.insert(tool_item, -1);
+ self.insert(tool_item, -1)
- # font
+ # font
self._has_custom_fonts = False
self._fonts = []
@@ -297,15 +303,16 @@ class TextToolbar(gtk.Toolbar):
for family in pango_context.list_families():
self._fonts.append(family.get_name())
self._fonts.sort()
-
+
self._font_combo = ComboBox()
- self._fonts_changed_id = self._font_combo.connect('changed', self._font_changed_cb)
+ self._fonts_changed_id = self._font_combo.connect('changed',
+ self._font_changed_cb)
for i, f in enumerate(self._fonts):
self._font_combo.append_item(i, f, None)
if f == 'Times New Roman':
self._font_combo.set_active(i)
tool_item = ToolComboBox(self._font_combo)
- self.insert(tool_item, -1);
+ self.insert(tool_item, -1)
separator = gtk.SeparatorToolItem()
separator.set_draw(True)
@@ -318,10 +325,8 @@ class TextToolbar(gtk.Toolbar):
def _add_widget(self, widget, expand=False):
tool_item = gtk.ToolItem()
tool_item.set_expand(expand)
-
tool_item.add(widget)
widget.show()
-
self.insert(tool_item, -1)
tool_item.show()
@@ -329,22 +334,24 @@ class TextToolbar(gtk.Toolbar):
globo_activo = self._page.get_globo_activo()
if (globo_activo != None):
globo_activo.texto.bold = not globo_activo.texto.bold
- self._page.get_active_box().queue_draw()
+ self._page.get_active_box().queue_draw()
def _italic_cb(self, button):
globo_activo = self._page.get_globo_activo()
if (globo_activo != None):
globo_activo.texto.italic = not globo_activo.texto.italic
- self._page.get_active_box().queue_draw()
+ self._page.get_active_box().queue_draw()
- # para la version 0.82
+ # para la version 0.82
def _text_color_cb(self, button):
globo_activo = self._page.get_globo_activo()
if (globo_activo != None):
newcolor = self._text_color.get_color()
texto = globo_activo.texto
- texto.color_r,texto.color_g,texto.color_b = (newcolor.red / 65535.0),(newcolor.green / 65535.0),(newcolor.blue / 65535.0)
- self._page.get_active_box().queue_draw()
+ texto.color_r = newcolor.red / 65535.0
+ texto.color_g = newcolor.green / 65535.0
+ texto.color_b = newcolor.blue / 65535.0
+ self._page.get_active_box().queue_draw()
def _font_size_changed_cb(self, combobox):
if self._font_size_combo.get_active() != -1:
@@ -354,45 +361,48 @@ class TextToolbar(gtk.Toolbar):
if (globo_activo != None):
globo_activo.texto.font_size = size
globo_activo.texto.alto_renglon = size
- self._page.get_active_box().queue_draw()
+ self._page.get_active_box().queue_draw()
def _font_changed_cb(self, combobox):
if self._font_combo.get_active() != -1:
- logger.debug('Setting font name: %s', self._fonts[self._font_combo.get_active()])
+ logger.debug('Setting font name: %s',
+ self._fonts[self._font_combo.get_active()])
globo_activo = self._page.get_globo_activo()
if (globo_activo != None):
- globo_activo.texto.font_type = self._fonts[self._font_combo.get_active()]
- self._page.get_active_box().queue_draw()
-
-
-
-
- """
- Estos son los metodos para setear los contrles de la barra en base a el texto del globo
- como el globo va a tener un solo font seleccionado, voy a hacer un solo metodo
-
- """
-
- def setToggleButtonState(self,button,b,id):
+ globo_activo.texto.font_type = \
+ self._fonts[self._font_combo.get_active()]
+ self._page.get_active_box().queue_draw()
+
+ """
+ Estos son los metodos para setear los contrles de la barra en base a el
+ texto del globo como el globo va a tener un solo font seleccionado, voy
+ a hacer un solo metodo
+ """
+ def setToggleButtonState(self, button, b, id):
button.handler_block(id)
button.set_active(b)
button.handler_unblock(id)
- def setToolbarState(self,globeText):
+ def setToolbarState(self, globeText):
# seteo bold
- self.setToggleButtonState(self._bold,globeText.bold ,self._bold_id)
+ self.setToggleButtonState(self._bold, globeText.bold, self._bold_id)
# seteo italic
- self.setToggleButtonState(self._italic, globeText.italic, self._italic_id)
+ self.setToggleButtonState(self._italic, globeText.italic,
+ self._italic_id)
# color
- self._text_color.set_color(gtk.gdk.Color(int(globeText.color_r * 65535), int(globeText.color_g * 65535), int(globeText.color_b * 65535)))
+ self._text_color.set_color(gtk.gdk.Color(
+ int(globeText.color_r * 65535),
+ int(globeText.color_g * 65535),
+ int(globeText.color_b * 65535)))
# font size
for i, s in enumerate(self._font_sizes):
if int(s) == int(globeText.font_size):
self._font_size_combo.handler_block(self._font_size_changed_id)
self._font_size_combo.set_active(i)
- self._font_size_combo.handler_unblock(self._font_size_changed_id)
- break;
-
+ self._font_size_combo.handler_unblock(
+ self._font_size_changed_id)
+ break
+
# font seleccionada
font_family = globeText.font_type
font_index = -1
@@ -401,7 +411,7 @@ class TextToolbar(gtk.Toolbar):
for i, f in enumerate(self._fonts):
if f == font_family:
font_index = i
- break;
+ break
# if we don't know this font yet, then add it (temporary) to the list
if font_index == -1:
@@ -409,7 +419,7 @@ class TextToolbar(gtk.Toolbar):
if not self._has_custom_fonts:
# add a separator to seperate the non-available fonts from
# the available ones
- self._fonts.append('') # ugly
+ self._fonts.append('') # ugly
self._font_combo.append_separator()
self._has_custom_fonts = True
# add the new font
@@ -419,12 +429,10 @@ class TextToolbar(gtk.Toolbar):
model = self._font_combo.get_model()
num_children = model.iter_n_children(None)
logger.debug('Number of fonts in the list: %d', num_children)
- font_index = num_children-1
+ font_index = num_children - 1
# activate the found font
if (font_index > -1):
self._font_combo.handler_block(self._fonts_changed_id)
self._font_combo.set_active(font_index)
self._font_combo.handler_unblock(self._fonts_changed_id)
-
-