Basic functionalities mostly working
This commit is contained in:
parent
63e12fbd5e
commit
62fd4dcd89
@ -1,20 +1,30 @@
|
||||
from sugar.p2p.Stream import Stream
|
||||
from sugar.presence import PresenceService
|
||||
|
||||
class _Marshaller(object):
|
||||
def marshal(self, title, address):
|
||||
return title + '\n' + address
|
||||
|
||||
def demarshal(self, message):
|
||||
return message.split('\n')
|
||||
|
||||
class LinksController(object):
|
||||
def __init__(self, service, model):
|
||||
self._model = model
|
||||
|
||||
self._pservice = PresenceService.get_instance()
|
||||
self._marshaller = _Marshaller()
|
||||
|
||||
self._stream = Stream.new_from_service(service)
|
||||
self._stream.set_data_listener(self._recv_message)
|
||||
self._stream_writer = self._stream.new_writer()
|
||||
|
||||
def post_link(self, title, address):
|
||||
self._stream_writer.write('test')
|
||||
message = self._marshaller.marshal(title, address)
|
||||
self._stream_writer.write(message)
|
||||
|
||||
def _recv_message(self, address, msg):
|
||||
buddy = self._pservice.get_buddy_by_address(address)
|
||||
if buddy:
|
||||
self._model.add_link(buddy, 'Test title', 'Test address')
|
||||
link = self._marshaller.demarshal(msg)
|
||||
self._model.add_link(buddy, *link)
|
||||
|
@ -6,10 +6,11 @@ from sugar.graphics.iconcolor import IconColor
|
||||
from sugar.graphics import style
|
||||
|
||||
class LinksView(hippo.Canvas):
|
||||
def __init__(self, model):
|
||||
def __init__(self, model, browser):
|
||||
hippo.Canvas.__init__(self)
|
||||
|
||||
self._bubbles = {}
|
||||
self._browser = browser
|
||||
|
||||
self._box = hippo.CanvasBox(background_color=0x414141ff)
|
||||
self.set_root(self._box)
|
||||
@ -22,10 +23,16 @@ class LinksView(hippo.Canvas):
|
||||
|
||||
def _add_link(self, link):
|
||||
color = IconColor(link.buddy.get_color())
|
||||
|
||||
bubble = Bubble(color=color)
|
||||
style.apply_stylesheet(bubble, 'bubble.Box')
|
||||
style.apply_stylesheet(bubble, 'bubble.Bubble')
|
||||
self._box.append(bubble)
|
||||
|
||||
text = hippo.CanvasLink(text=link.title)
|
||||
text.connect('activated', self._link_activated_cb, link)
|
||||
style.apply_stylesheet(text, 'bubble.Text')
|
||||
bubble.append(text, hippo.PACK_EXPAND)
|
||||
|
||||
self._bubbles[link] = bubble
|
||||
|
||||
def _remove_link(self, link):
|
||||
@ -39,3 +46,6 @@ class LinksView(hippo.Canvas):
|
||||
|
||||
def _link_removed_cb(self, model, link):
|
||||
self._removed_link(link)
|
||||
|
||||
def _link_activated_cb(self, link_item, link):
|
||||
self._browser.load_url(link.url)
|
||||
|
@ -2,7 +2,11 @@ import gtk
|
||||
|
||||
_screen_factor = gtk.gdk.screen_width() / 1200.0
|
||||
|
||||
bubble_Box = {
|
||||
'box-width' : int(150.0 * _screen_factor),
|
||||
'box-height' : int(50.0 * _screen_factor)
|
||||
bubble_Bubble = {
|
||||
'box-width' : int(250.0 * _screen_factor)
|
||||
}
|
||||
|
||||
bubble_Text = {
|
||||
'color' : 0x000000FF,
|
||||
'font' : '14px'
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ class WebActivity(Activity):
|
||||
self._browser.connect('notify::title', self._title_changed_cb)
|
||||
|
||||
self._links_model = LinksModel()
|
||||
links_view = LinksView(self._links_model)
|
||||
links_view = LinksView(self._links_model, self._browser)
|
||||
|
||||
self._toolbar = Toolbar(self._browser)
|
||||
vbox.pack_start(self._toolbar, False)
|
||||
|
@ -10,7 +10,7 @@ class PanelWindow(gtk.Window):
|
||||
|
||||
canvas = hippo.Canvas()
|
||||
|
||||
self._bg = hippo.CanvasBox(background_color=0x4f4f4fff)
|
||||
self._bg = hippo.CanvasBox(background_color=0x414141ff)
|
||||
canvas.set_root(self._bg)
|
||||
|
||||
self.add(canvas)
|
||||
|
Loading…
Reference in New Issue
Block a user