Add back colors in the toolbar. Layout/appeareance sucks atm

This commit is contained in:
Marco Pesenti Gritti 2006-06-18 15:35:44 -04:00
parent 3fe0d7a580
commit b129956aba
4 changed files with 35 additions and 66 deletions

View File

@ -54,7 +54,7 @@ class Chat(gtk.VBox):
self._mode = Chat.TEXT_MODE
self._editor = ChatEditor(self, ChatEditor.TEXT_MODE)
toolbar = ChatToolbar(self._editor.get_buffer())
toolbar = ChatToolbar(self._editor)
self.pack_start(toolbar, False)
toolbar.show()

View File

@ -45,6 +45,9 @@ class ChatEditor(gtk.HBox):
self.set_mode(mode)
def set_color(self, color):
self._sketchpad.set_color(color)
def get_buffer(self):
return self._text_view.get_buffer()

View File

@ -3,19 +3,22 @@ pygtk.require('2.0')
import gtk
from sugar.chat.Emoticons import Emoticons
from sugar.chat.sketchpad.Toolbox import Toolbox
import richtext
class ChatToolbar(gtk.HBox):
def __init__(self, rich_buf):
def __init__(self, editor):
gtk.HBox.__init__(self)
self._editor = editor
self._emt_popup = None
spring = gtk.Label('')
self.pack_start(spring, True)
spring.show()
# spring = gtk.Label('')
# self.pack_start(spring, True)
# spring.show()
toolbar = richtext.RichTextToolbar(rich_buf)
toolbar = richtext.RichTextToolbar(editor.get_buffer())
toolbar.set_show_arrow(False)
item = gtk.ToolButton()
@ -36,22 +39,30 @@ class ChatToolbar(gtk.HBox):
toolbar.insert(item, -1)
item.show()
separator = gtk.SeparatorToolItem()
toolbar.insert(separator, -1)
separator.show()
# separator = gtk.SeparatorToolItem()
# toolbar.insert(separator, -1)
# separator.show()
item = gtk.MenuToolButton(None, "Links")
item.set_menu(gtk.Menu())
item.connect("show-menu", self.__show_link_menu_cb)
toolbar.insert(item, -1)
item.show()
# item = gtk.MenuToolButton(None, "Links")
# item.set_menu(gtk.Menu())
# item.connect("show-menu", self.__show_link_menu_cb)
# toolbar.insert(item, -1)
# item.show()
self.pack_start(toolbar)
toolbar.show()
spring = gtk.Label('')
self.pack_start(spring, True)
spring.show()
toolbox = Toolbox()
toolbox.connect('color-selected', self._color_selected)
self.pack_start(toolbox, False)
toolbox.show()
# spring = gtk.Label('')
# self.pack_start(spring, True)
# spring.show()
def _color_selected(self, toolbox, color):
self._editor.set_color(color)
def __link_activate_cb(self, item, link):
buf = self._editor.get_buffer()
@ -68,8 +79,7 @@ class ChatToolbar(gtk.HBox):
menu.append(item)
item.show()
button.set_menu(menu)
button.set_menu(menu)
def _create_emoticons_popup(self):
model = gtk.ListStore(gtk.gdk.Pixbuf, str)

View File

@ -31,75 +31,31 @@ class ColorButton(gtk.RadioButton):
return False
class Toolbox(gtk.VBox):
class Toolbox(gtk.HBox):
__gsignals__ = {
'tool-selected': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_STRING])),
'color-selected': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT]))
}
def __init__(self):
gtk.VBox.__init__(self, False, 12)
gtk.HBox.__init__(self, False, 6)
self._tools_group = None
self._colors_group = None
self._tool_hbox = gtk.HBox(False, 2)
spring = gtk.Label()
self._tool_hbox.pack_start(spring, True)
spring.show()
self._add_tool('stock_draw-text', 'text')
self._add_tool('stock_draw-freeform-line', 'freehand')
spring = gtk.Label()
self._tool_hbox.pack_start(spring, True)
spring.show()
self.pack_start(self._tool_hbox)
self._tool_hbox.show()
self._color_hbox = gtk.HBox(False, 2)
self._add_color([0, 0, 0])
self._add_color([1, 0, 0])
self._add_color([0, 1, 0])
self._add_color([0, 0, 1])
self.pack_start(self._color_hbox)
self._color_hbox.show()
def _add_tool(self, icon, tool_id):
image = gtk.Image()
image.set_from_icon_name(icon, gtk.ICON_SIZE_LARGE_TOOLBAR)
tool = gtk.RadioButton(self._tools_group)
tool.set_mode(False)
tool.set_relief(gtk.RELIEF_NONE)
tool.set_image(image)
tool.connect('clicked', self.__tool_clicked_cb, tool_id)
self._tool_hbox.pack_start(tool, False)
if self._tools_group == None:
self._tools_group = tool
tool.show()
def _add_color(self, rgb):
color = ColorButton(self._colors_group, rgb)
color.connect('clicked', self.__color_clicked_cb, rgb)
self._color_hbox.pack_start(color, False)
self.pack_start(color, False)
if self._colors_group == None:
self._colors_group = color
color.show()
def __tool_clicked_cb(self, button, tool_id):
self.emit("tool-selected", tool_id)
def __color_clicked_cb(self, button, rgb):
self.emit("color-selected", button.color())