More work on links
This commit is contained in:
parent
75b158c3d7
commit
63e12fbd5e
@ -1,3 +1,4 @@
|
|||||||
|
from sugar.p2p.Stream import Stream
|
||||||
from sugar.presence import PresenceService
|
from sugar.presence import PresenceService
|
||||||
|
|
||||||
class LinksController(object):
|
class LinksController(object):
|
||||||
|
@ -18,13 +18,13 @@ class LinksModel(gobject.GObject):
|
|||||||
gobject.GObject.__init__(self)
|
gobject.GObject.__init__(self)
|
||||||
self._links = {}
|
self._links = {}
|
||||||
|
|
||||||
def add_link(buddy, title, url):
|
def add_link(self, buddy, title, url):
|
||||||
link = Link(buddy, title, url)
|
link = Link(buddy, title, url)
|
||||||
self._links[(buddy.get_name(), url)] = link
|
self._links[(buddy.get_name(), url)] = link
|
||||||
|
|
||||||
self.emit('link-added', link)
|
self.emit('link-added', link)
|
||||||
|
|
||||||
def remove_link(buddy, url):
|
def remove_link(self, buddy, url):
|
||||||
key = (buddy.get_name(), url)
|
key = (buddy.get_name(), url)
|
||||||
if self._links.haskey(key):
|
if self._links.haskey(key):
|
||||||
link = self._links[key]
|
link = self._links[key]
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
|
import gtk
|
||||||
import hippo
|
import hippo
|
||||||
|
|
||||||
from sugar.graphics.bubble import Bubble
|
from sugar.graphics.bubble import Bubble
|
||||||
|
from sugar.graphics.iconcolor import IconColor
|
||||||
|
from sugar.graphics import style
|
||||||
|
|
||||||
class LinksView(hippo.Canvas):
|
class LinksView(hippo.Canvas):
|
||||||
def __init__(self, model):
|
def __init__(self, model):
|
||||||
@ -18,8 +21,10 @@ class LinksView(hippo.Canvas):
|
|||||||
model.connect('link_removed', self._link_removed_cb)
|
model.connect('link_removed', self._link_removed_cb)
|
||||||
|
|
||||||
def _add_link(self, link):
|
def _add_link(self, link):
|
||||||
bubble = Bubble(color=link.buddy.get_color())
|
color = IconColor(link.buddy.get_color())
|
||||||
self._box.append(link)
|
bubble = Bubble(color=color)
|
||||||
|
style.apply_stylesheet(bubble, 'bubble.Box')
|
||||||
|
self._box.append(bubble)
|
||||||
|
|
||||||
self._bubbles[link] = bubble
|
self._bubbles[link] = bubble
|
||||||
|
|
||||||
|
8
activities/web/stylesheet.py
Normal file
8
activities/web/stylesheet.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
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)
|
||||||
|
}
|
@ -67,7 +67,7 @@ class Toolbar(gtk.Toolbar):
|
|||||||
|
|
||||||
def set_links_controller(self, links_controller):
|
def set_links_controller(self, links_controller):
|
||||||
self._links_controller = links_controller
|
self._links_controller = links_controller
|
||||||
self._post.props.sensitive = False
|
self._post.props.sensitive = True
|
||||||
|
|
||||||
def _progress_changed_cb(self, embed, spec):
|
def _progress_changed_cb(self, embed, spec):
|
||||||
self._entry.props.progress = embed.props.progress
|
self._entry.props.progress = embed.props.progress
|
||||||
|
@ -4,6 +4,8 @@ import gtkmozembed
|
|||||||
|
|
||||||
from sugar.activity.Activity import Activity
|
from sugar.activity.Activity import Activity
|
||||||
from sugar import env
|
from sugar import env
|
||||||
|
from sugar.graphics import style
|
||||||
|
import web.stylesheet
|
||||||
from webbrowser import WebBrowser
|
from webbrowser import WebBrowser
|
||||||
from toolbar import Toolbar
|
from toolbar import Toolbar
|
||||||
from linksmodel import LinksModel
|
from linksmodel import LinksModel
|
||||||
@ -23,8 +25,8 @@ class WebActivity(Activity):
|
|||||||
self._browser = WebBrowser()
|
self._browser = WebBrowser()
|
||||||
self._browser.connect('notify::title', self._title_changed_cb)
|
self._browser.connect('notify::title', self._title_changed_cb)
|
||||||
|
|
||||||
links_model = LinksModel()
|
self._links_model = LinksModel()
|
||||||
links_view = LinksView(links_model)
|
links_view = LinksView(self._links_model)
|
||||||
|
|
||||||
self._toolbar = Toolbar(self._browser)
|
self._toolbar = Toolbar(self._browser)
|
||||||
vbox.pack_start(self._toolbar, False)
|
vbox.pack_start(self._toolbar, False)
|
||||||
@ -46,11 +48,14 @@ class WebActivity(Activity):
|
|||||||
|
|
||||||
self._browser.load_url(_HOMEPAGE)
|
self._browser.load_url(_HOMEPAGE)
|
||||||
|
|
||||||
|
def _setup_links_controller(self):
|
||||||
|
links_controller = LinksController(self._service, self._links_model)
|
||||||
|
self._toolbar.set_links_controller(links_controller)
|
||||||
|
|
||||||
def join(self, activity_ps):
|
def join(self, activity_ps):
|
||||||
Activity.join(self, activity_ps)
|
Activity.join(self, activity_ps)
|
||||||
|
|
||||||
links_controller = LinksController(service, links_model)
|
self._setup_links_controller()
|
||||||
self._toolbar.set_links_controller(links_controller)
|
|
||||||
|
|
||||||
url = self._service.get_published_value('URL')
|
url = self._service.get_published_value('URL')
|
||||||
if url:
|
if url:
|
||||||
@ -59,6 +64,8 @@ class WebActivity(Activity):
|
|||||||
def share(self):
|
def share(self):
|
||||||
Activity.share(self)
|
Activity.share(self)
|
||||||
|
|
||||||
|
self._setup_links_controller()
|
||||||
|
|
||||||
url = self._browser.get_location()
|
url = self._browser.get_location()
|
||||||
if url:
|
if url:
|
||||||
self._service.set_published_value('URL', url)
|
self._service.set_published_value('URL', url)
|
||||||
@ -68,3 +75,4 @@ class WebActivity(Activity):
|
|||||||
|
|
||||||
def start():
|
def start():
|
||||||
gtkmozembed.set_profile_path(env.get_profile_path(), 'gecko')
|
gtkmozembed.set_profile_path(env.get_profile_path(), 'gecko')
|
||||||
|
style.load_stylesheet(web.stylesheet)
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
|
import math
|
||||||
|
|
||||||
import gobject
|
import gobject
|
||||||
|
import gtk
|
||||||
import hippo
|
import hippo
|
||||||
|
|
||||||
class Bubble(hippo.CanvasBox, hippo.CanvasItem):
|
class Bubble(hippo.CanvasBox, hippo.CanvasItem):
|
||||||
@ -11,7 +14,7 @@ class Bubble(hippo.CanvasBox, hippo.CanvasItem):
|
|||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
self._color = None
|
self._color = None
|
||||||
self._radius = 12
|
self._radius = 8
|
||||||
|
|
||||||
hippo.CanvasBox.__init__(self, **kwargs)
|
hippo.CanvasBox.__init__(self, **kwargs)
|
||||||
|
|
||||||
@ -24,25 +27,34 @@ class Bubble(hippo.CanvasBox, hippo.CanvasItem):
|
|||||||
if pspec.name == 'color':
|
if pspec.name == 'color':
|
||||||
return self._color
|
return self._color
|
||||||
|
|
||||||
def _color_string_to_rgb(self, color_string):
|
def _string_to_rgb(self, color_string):
|
||||||
col = gtk.gdk.color_parse(color_string)
|
col = gtk.gdk.color_parse(color_string)
|
||||||
return (col.red / 65535, col.green / 65535, col.blue / 65535)
|
return (col.red / 65535.0, col.green / 65535.0, col.blue / 65535.0)
|
||||||
|
|
||||||
def do_paint_below_children(self, cr, damaged_box):
|
def do_paint_below_children(self, cr, damaged_box):
|
||||||
cairo_move_to(self._radius, 0);
|
[width, height] = self.get_allocation()
|
||||||
cr.arc(width - self._radius, self._radius,
|
|
||||||
|
line_width = 3.0
|
||||||
|
x = line_width
|
||||||
|
y = line_width
|
||||||
|
width -= line_width * 2
|
||||||
|
height -= line_width * 2
|
||||||
|
|
||||||
|
cr.move_to(x + self._radius, y);
|
||||||
|
cr.arc(x + width - self._radius, y + self._radius,
|
||||||
self._radius, math.pi * 1.5, math.pi * 2);
|
self._radius, math.pi * 1.5, math.pi * 2);
|
||||||
cr.arc(width - self._radius, height - self._radius,
|
cr.arc(x + width - self._radius, x + height - self._radius,
|
||||||
self._radius, 0, math.pi * 0.5);
|
self._radius, 0, math.pi * 0.5);
|
||||||
cr.arc(self._radius, height - self._radius,
|
cr.arc(x + self._radius, y + height - self._radius,
|
||||||
self._radius, math.pi * 0.5, math.pi);
|
self._radius, math.pi * 0.5, math.pi);
|
||||||
cr.arc(cr, self._radius, self._radius, self._radius,
|
cr.arc(x + self._radius, y + self._radius, self._radius,
|
||||||
math.pi, math.pi * 1.5);
|
math.pi, math.pi * 1.5);
|
||||||
|
|
||||||
color = self._color.get_fill_color()
|
color = self._string_to_rgb(self._color.get_fill_color())
|
||||||
cr.set_source_rgb(cr, self._color_string_to_rgb(color));
|
cr.set_source_rgb(*color)
|
||||||
cairo_fill_preserve(cr);
|
cr.fill_preserve();
|
||||||
|
|
||||||
color = self._color.get_stroke_color()
|
color = self._string_to_rgb(self._color.get_stroke_color())
|
||||||
cr.set_source_rgb(cr, self._color_string_to_rgb(color));
|
cr.set_source_rgb(*color)
|
||||||
cairo_stroke(cr);
|
cr.set_line_width(line_width)
|
||||||
|
cr.stroke();
|
||||||
|
Loading…
Reference in New Issue
Block a user