Get sketches back to work, add a send button
This commit is contained in:
parent
be051b2726
commit
3fe0d7a580
@ -131,7 +131,7 @@ class Chat(gtk.VBox):
|
|||||||
|
|
||||||
self._message_inserted()
|
self._message_inserted()
|
||||||
|
|
||||||
def _insert_sketch(self, nick, svgdata):
|
def _insert_sketch(self, buddy, svgdata):
|
||||||
"""Insert a sketch object into the chat buffer."""
|
"""Insert a sketch object into the chat buffer."""
|
||||||
pbl = gtk.gdk.PixbufLoader("svg")
|
pbl = gtk.gdk.PixbufLoader("svg")
|
||||||
pbl.write(svgdata)
|
pbl.write(svgdata)
|
||||||
@ -140,7 +140,7 @@ class Chat(gtk.VBox):
|
|||||||
|
|
||||||
buf = self._chat_view.get_buffer()
|
buf = self._chat_view.get_buffer()
|
||||||
|
|
||||||
self._insert_buddy(buf, nick)
|
self._insert_buddy(buf, buddy)
|
||||||
|
|
||||||
rise = int(pbuf.get_height() / 3) * -1
|
rise = int(pbuf.get_height() / 3) * -1
|
||||||
sha_hash = sha.new()
|
sha_hash = sha.new()
|
||||||
@ -218,7 +218,7 @@ class Chat(gtk.VBox):
|
|||||||
return
|
return
|
||||||
self._stream_writer.write(self.serialize_message(svgdata))
|
self._stream_writer.write(self.serialize_message(svgdata))
|
||||||
owner = PresenceService.get_instance().get_owner()
|
owner = PresenceService.get_instance().get_owner()
|
||||||
self._insert_sketch(owner.get_nick_name(), svgdata)
|
self._insert_sketch(owner, svgdata)
|
||||||
|
|
||||||
def send_text_message(self, text):
|
def send_text_message(self, text):
|
||||||
"""Send a chat message and insert it into the local buffer."""
|
"""Send a chat message and insert it into the local buffer."""
|
||||||
|
@ -5,18 +5,19 @@ import gtk
|
|||||||
from sugar.chat.sketchpad.SketchPad import SketchPad
|
from sugar.chat.sketchpad.SketchPad import SketchPad
|
||||||
import richtext
|
import richtext
|
||||||
|
|
||||||
class ChatEditor(gtk.Notebook):
|
class ChatEditor(gtk.HBox):
|
||||||
TEXT_MODE = 0
|
TEXT_MODE = 0
|
||||||
SKETCH_MODE = 1
|
SKETCH_MODE = 1
|
||||||
|
|
||||||
def __init__(self, chat, mode):
|
def __init__(self, chat, mode):
|
||||||
gtk.Notebook.__init__(self)
|
gtk.HBox.__init__(self, False, 6)
|
||||||
|
|
||||||
self._chat = chat
|
self._chat = chat
|
||||||
|
|
||||||
self.set_show_tabs(False)
|
self._notebook = gtk.Notebook()
|
||||||
self.set_show_border(False)
|
self._notebook.set_show_tabs(False)
|
||||||
self.set_size_request(-1, 70)
|
self._notebook.set_show_border(False)
|
||||||
|
self._notebook.set_size_request(-1, 70)
|
||||||
|
|
||||||
chat_view_sw = gtk.ScrolledWindow()
|
chat_view_sw = gtk.ScrolledWindow()
|
||||||
chat_view_sw.set_shadow_type(gtk.SHADOW_IN)
|
chat_view_sw.set_shadow_type(gtk.SHADOW_IN)
|
||||||
@ -26,28 +27,49 @@ class ChatEditor(gtk.Notebook):
|
|||||||
chat_view_sw.add(self._text_view)
|
chat_view_sw.add(self._text_view)
|
||||||
self._text_view.show()
|
self._text_view.show()
|
||||||
|
|
||||||
self.append_page(chat_view_sw)
|
self._notebook.append_page(chat_view_sw)
|
||||||
chat_view_sw.show()
|
chat_view_sw.show()
|
||||||
|
|
||||||
self._sketchpad = SketchPad()
|
self._sketchpad = SketchPad()
|
||||||
self.append_page(self._sketchpad)
|
self._notebook.append_page(self._sketchpad)
|
||||||
self._sketchpad.show()
|
self._sketchpad.show()
|
||||||
|
|
||||||
self.set_mode(mode)
|
self.pack_start(self._notebook)
|
||||||
|
self._notebook.show()
|
||||||
|
|
||||||
def set_mode(self, mode):
|
send_button = gtk.Button("Send")
|
||||||
self._mode = mode
|
send_button.set_border_width(6)
|
||||||
if self._mode == ChatEditor.SKETCH_MODE:
|
send_button.connect('clicked', self.__send_button_clicked_cb)
|
||||||
self.set_current_page(1)
|
self.pack_start(send_button, False, True)
|
||||||
elif self._mode == ChatEditor.TEXT_MODE:
|
send_button.show()
|
||||||
self.set_current_page(0)
|
|
||||||
|
self.set_mode(mode)
|
||||||
|
|
||||||
def get_buffer(self):
|
def get_buffer(self):
|
||||||
return self._text_view.get_buffer()
|
return self._text_view.get_buffer()
|
||||||
|
|
||||||
def __key_press_event_cb(self, text_view, event):
|
def set_mode(self, mode):
|
||||||
if event.keyval == gtk.keysyms.Return:
|
self._mode = mode
|
||||||
buf = text_view.get_buffer()
|
if self._mode == ChatEditor.SKETCH_MODE:
|
||||||
|
self._notebook.set_current_page(1)
|
||||||
|
elif self._mode == ChatEditor.TEXT_MODE:
|
||||||
|
self._notebook.set_current_page(0)
|
||||||
|
|
||||||
|
def __send_button_clicked_cb(self, button):
|
||||||
|
self._send()
|
||||||
|
|
||||||
|
def _send(self):
|
||||||
|
if self._mode == ChatEditor.SKETCH_MODE:
|
||||||
|
self._send_sketch()
|
||||||
|
elif self._mode == ChatEditor.TEXT_MODE:
|
||||||
|
self._send_text()
|
||||||
|
|
||||||
|
def _send_sketch(self):
|
||||||
|
self._chat.send_sketch(self._sketchpad.to_svg())
|
||||||
|
self._sketchpad.clear()
|
||||||
|
|
||||||
|
def _send_text(self):
|
||||||
|
buf = self._text_view.get_buffer()
|
||||||
text = buf.get_text(buf.get_start_iter(), buf.get_end_iter())
|
text = buf.get_text(buf.get_start_iter(), buf.get_end_iter())
|
||||||
if len(text.strip()) > 0:
|
if len(text.strip()) > 0:
|
||||||
serializer = richtext.RichTextSerializer()
|
serializer = richtext.RichTextSerializer()
|
||||||
@ -57,4 +79,7 @@ class ChatEditor(gtk.Notebook):
|
|||||||
buf.set_text("")
|
buf.set_text("")
|
||||||
buf.place_cursor(buf.get_start_iter())
|
buf.place_cursor(buf.get_start_iter())
|
||||||
|
|
||||||
|
def __key_press_event_cb(self, text_view, event):
|
||||||
|
if event.keyval == gtk.keysyms.Return:
|
||||||
|
self._send()
|
||||||
return True
|
return True
|
||||||
|
Loading…
Reference in New Issue
Block a user