#3119: Implement some basic search capabilities in the mesh view.
This commit is contained in:
parent
45c740fb93
commit
32fc5d3161
2
NEWS
2
NEWS
@ -1,3 +1,5 @@
|
|||||||
|
* #3119: Implement some basic search capabilities in the mesh view. (tomeu)
|
||||||
|
|
||||||
Snapshot d456f6c633
|
Snapshot d456f6c633
|
||||||
|
|
||||||
* New experimental screenshot code. (marco)
|
* New experimental screenshot code. (marco)
|
||||||
|
@ -15,7 +15,6 @@ sugar_PYTHON = \
|
|||||||
palettegroup.py \
|
palettegroup.py \
|
||||||
panel.py \
|
panel.py \
|
||||||
roundbox.py \
|
roundbox.py \
|
||||||
spreadlayout.py \
|
|
||||||
style.py \
|
style.py \
|
||||||
toggletoolbutton.py \
|
toggletoolbutton.py \
|
||||||
toolbox.py \
|
toolbox.py \
|
||||||
|
@ -22,9 +22,9 @@ from view.BuddyMenu import BuddyMenu
|
|||||||
|
|
||||||
class BuddyIcon(CanvasIcon):
|
class BuddyIcon(CanvasIcon):
|
||||||
def __init__(self, shell, buddy, size=style.STANDARD_ICON_SIZE):
|
def __init__(self, shell, buddy, size=style.STANDARD_ICON_SIZE):
|
||||||
CanvasIcon.__init__(self, icon_name='computer-xo',
|
CanvasIcon.__init__(self, icon_name='computer-xo', size=size)
|
||||||
xo_color=buddy.get_color(), size=size)
|
|
||||||
|
|
||||||
|
self._greyed_out = False
|
||||||
self._shell = shell
|
self._shell = shell
|
||||||
self._buddy = buddy
|
self._buddy = buddy
|
||||||
self._buddy.connect('appeared', self._buddy_presence_change_cb)
|
self._buddy.connect('appeared', self._buddy_presence_change_cb)
|
||||||
@ -34,7 +34,21 @@ class BuddyIcon(CanvasIcon):
|
|||||||
palette = BuddyMenu(shell, buddy)
|
palette = BuddyMenu(shell, buddy)
|
||||||
self.set_palette(palette)
|
self.set_palette(palette)
|
||||||
|
|
||||||
|
self._update_color()
|
||||||
|
|
||||||
def _buddy_presence_change_cb(self, buddy, color=None):
|
def _buddy_presence_change_cb(self, buddy, color=None):
|
||||||
# Update the icon's color when the buddy comes and goes
|
# Update the icon's color when the buddy comes and goes
|
||||||
self.props.xo_color = buddy.get_color()
|
self._update_color()
|
||||||
|
|
||||||
|
def _update_color(self):
|
||||||
|
if self._greyed_out:
|
||||||
|
self.props.stroke_color = style.COLOR_INACTIVE_STROKE.get_svg()
|
||||||
|
self.props.fill_color = style.COLOR_INACTIVE_FILL.get_svg()
|
||||||
|
else:
|
||||||
|
self.props.xo_color = self._buddy.get_color()
|
||||||
|
|
||||||
|
def set_filter(self, query):
|
||||||
|
self._greyed_out = (self._buddy.get_nick().lower().find(query) == -1) \
|
||||||
|
and not self._buddy.is_owner()
|
||||||
|
self._update_color()
|
||||||
|
|
||||||
|
@ -20,12 +20,12 @@ import hippo
|
|||||||
import gobject
|
import gobject
|
||||||
|
|
||||||
from sugar import profile
|
from sugar import profile
|
||||||
from sugar.graphics.spreadlayout import SpreadLayout
|
|
||||||
from sugar.graphics import style
|
from sugar.graphics import style
|
||||||
from sugar.graphics.icon import CanvasIcon
|
from sugar.graphics.icon import CanvasIcon
|
||||||
from sugar.graphics.palette import Palette
|
from sugar.graphics.palette import Palette
|
||||||
|
|
||||||
from view.home.FriendView import FriendView
|
from view.home.FriendView import FriendView
|
||||||
|
from view.home.spreadlayout import SpreadLayout
|
||||||
|
|
||||||
class FriendsBox(hippo.CanvasBox):
|
class FriendsBox(hippo.CanvasBox):
|
||||||
__gtype_name__ = 'SugarFriendsBox'
|
__gtype_name__ = 'SugarFriendsBox'
|
||||||
|
@ -10,4 +10,5 @@ sugar_PYTHON = \
|
|||||||
MyIcon.py \
|
MyIcon.py \
|
||||||
proc_smaps.py \
|
proc_smaps.py \
|
||||||
snowflakelayout.py \
|
snowflakelayout.py \
|
||||||
|
spreadlayout.py \
|
||||||
transitionbox.py
|
transitionbox.py
|
||||||
|
@ -15,19 +15,19 @@
|
|||||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
import random
|
import random
|
||||||
|
from gettext import gettext as _
|
||||||
|
import logging
|
||||||
|
|
||||||
import hippo
|
import hippo
|
||||||
import gobject
|
import gobject
|
||||||
import gtk
|
import gtk
|
||||||
from gettext import gettext as _
|
|
||||||
|
|
||||||
from sugar.graphics.spreadlayout import SpreadLayout
|
|
||||||
from sugar.graphics.icon import CanvasIcon
|
from sugar.graphics.icon import CanvasIcon
|
||||||
from sugar.graphics import style
|
from sugar.graphics import style
|
||||||
from sugar.graphics import xocolor
|
|
||||||
from sugar.graphics.icon import get_icon_state
|
from sugar.graphics.icon import get_icon_state
|
||||||
from sugar.graphics import style
|
from sugar.graphics import style
|
||||||
from sugar.graphics import palette
|
from sugar.graphics import palette
|
||||||
|
from sugar.graphics import iconentry
|
||||||
from sugar import profile
|
from sugar import profile
|
||||||
|
|
||||||
from model import accesspointmodel
|
from model import accesspointmodel
|
||||||
@ -38,6 +38,7 @@ from hardware import nmclient
|
|||||||
from view.BuddyIcon import BuddyIcon
|
from view.BuddyIcon import BuddyIcon
|
||||||
from view.pulsingicon import PulsingIcon
|
from view.pulsingicon import PulsingIcon
|
||||||
from view.home.snowflakelayout import SnowflakeLayout
|
from view.home.snowflakelayout import SnowflakeLayout
|
||||||
|
from view.home.spreadlayout import SpreadLayout
|
||||||
|
|
||||||
from hardware.nmclient import NM_802_11_CAP_PROTO_WEP, NM_802_11_CAP_PROTO_WPA, NM_802_11_CAP_PROTO_WPA2
|
from hardware.nmclient import NM_802_11_CAP_PROTO_WEP, NM_802_11_CAP_PROTO_WPA, NM_802_11_CAP_PROTO_WPA2
|
||||||
|
|
||||||
@ -50,6 +51,7 @@ class AccessPointView(PulsingIcon):
|
|||||||
self._model = model
|
self._model = model
|
||||||
self._meshdev = mesh_device
|
self._meshdev = mesh_device
|
||||||
self._disconnect_item = None
|
self._disconnect_item = None
|
||||||
|
self._greyed_out = False
|
||||||
|
|
||||||
self.connect('activated', self._activate_cb)
|
self.connect('activated', self._activate_cb)
|
||||||
|
|
||||||
@ -146,11 +148,21 @@ class AccessPointView(PulsingIcon):
|
|||||||
if self._disconnect_item:
|
if self._disconnect_item:
|
||||||
self._disconnect_item.hide()
|
self._disconnect_item.hide()
|
||||||
self.props.pulse_time = 0.0
|
self.props.pulse_time = 0.0
|
||||||
|
|
||||||
|
if self._greyed_out:
|
||||||
|
self.props.colors = [
|
||||||
|
[ style.COLOR_INACTIVE_STROKE.get_svg(),
|
||||||
|
style.COLOR_INACTIVE_FILL.get_svg() ]
|
||||||
|
]
|
||||||
|
else:
|
||||||
self.props.colors = [
|
self.props.colors = [
|
||||||
[ style.Color(self._device_stroke).get_svg(),
|
[ style.Color(self._device_stroke).get_svg(),
|
||||||
style.Color(self._device_fill).get_svg() ]
|
style.Color(self._device_fill).get_svg() ]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def set_filter(self, query):
|
||||||
|
self._greyed_out = self._model.props.name.lower().find(query) == -1
|
||||||
|
self._update_state()
|
||||||
|
|
||||||
_MESH_ICON_NAME = 'network-mesh'
|
_MESH_ICON_NAME = 'network-mesh'
|
||||||
|
|
||||||
@ -277,9 +289,81 @@ class ActivityView(hippo.CanvasBox):
|
|||||||
bundle_id = self._model.get_bundle_id()
|
bundle_id = self._model.get_bundle_id()
|
||||||
self._shell.join_activity(bundle_id, self._model.get_id())
|
self._shell.join_activity(bundle_id, self._model.get_id())
|
||||||
|
|
||||||
|
def set_filter(self, query):
|
||||||
|
if self._model.activity.props.name.lower().find(query) == -1:
|
||||||
|
self._icon.xo_color = [style.COLOR_INACTIVE_STROKE.get_svg(),
|
||||||
|
style.COLOR_INACTIVE_FILL.get_svg()]
|
||||||
|
else:
|
||||||
|
self._icon.xo_color = self._model.get_color()
|
||||||
|
|
||||||
|
_AUTOSEARCH_TIMEOUT = 1000
|
||||||
|
|
||||||
|
class MeshToolbar(gtk.Toolbar):
|
||||||
|
__gtype_name__ = 'MeshToolbar'
|
||||||
|
|
||||||
|
__gsignals__ = {
|
||||||
|
'query-changed': (gobject.SIGNAL_RUN_FIRST,
|
||||||
|
gobject.TYPE_NONE,
|
||||||
|
([str]))
|
||||||
|
}
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
gtk.Toolbar.__init__(self)
|
||||||
|
|
||||||
|
self._query = None
|
||||||
|
self._autosearch_timer = None
|
||||||
|
|
||||||
|
self._add_separator()
|
||||||
|
|
||||||
|
tool_item = gtk.ToolItem()
|
||||||
|
tool_item.set_expand(True)
|
||||||
|
self.insert(tool_item, -1)
|
||||||
|
tool_item.show()
|
||||||
|
|
||||||
|
self._search_entry = iconentry.IconEntry()
|
||||||
|
self._search_entry.set_icon_from_name(iconentry.ICON_ENTRY_PRIMARY, 'system-search')
|
||||||
|
self._search_entry.add_clear_button()
|
||||||
|
self._search_entry.connect('activate', self._entry_activated_cb)
|
||||||
|
self._search_entry.connect('changed', self._entry_changed_cb)
|
||||||
|
tool_item.add(self._search_entry)
|
||||||
|
self._search_entry.show()
|
||||||
|
|
||||||
|
self._add_separator()
|
||||||
|
|
||||||
|
def _add_separator(self):
|
||||||
|
separator = gtk.SeparatorToolItem()
|
||||||
|
separator.set_size_request(style.GRID_CELL_SIZE, style.GRID_CELL_SIZE)
|
||||||
|
separator.props.draw = False
|
||||||
|
self.insert(separator, -1)
|
||||||
|
separator.show()
|
||||||
|
|
||||||
|
def _entry_activated_cb(self, entry):
|
||||||
|
if self._autosearch_timer:
|
||||||
|
gobject.source_remove(self._autosearch_timer)
|
||||||
|
new_query = entry.props.text
|
||||||
|
if self._query != new_query:
|
||||||
|
self._query = new_query
|
||||||
|
self.emit('query-changed', self._query)
|
||||||
|
|
||||||
|
def _entry_changed_cb(self, entry):
|
||||||
|
if not entry.props.text:
|
||||||
|
entry.activate()
|
||||||
|
return
|
||||||
|
|
||||||
|
if self._autosearch_timer:
|
||||||
|
gobject.source_remove(self._autosearch_timer)
|
||||||
|
self._autosearch_timer = gobject.timeout_add(_AUTOSEARCH_TIMEOUT,
|
||||||
|
self._autosearch_timer_cb)
|
||||||
|
|
||||||
|
def _autosearch_timer_cb(self):
|
||||||
|
logging.debug('_autosearch_timer_cb')
|
||||||
|
self._autosearch_timer = None
|
||||||
|
self._search_entry.activate()
|
||||||
|
return False
|
||||||
|
|
||||||
class MeshBox(hippo.CanvasBox):
|
class MeshBox(hippo.CanvasBox):
|
||||||
def __init__(self, shell):
|
def __init__(self, shell):
|
||||||
hippo.CanvasBox.__init__(self, background_color=0xe2e2e2ff)
|
hippo.CanvasBox.__init__(self)
|
||||||
|
|
||||||
self._shell = shell
|
self._shell = shell
|
||||||
self._model = shell.get_model().get_mesh()
|
self._model = shell.get_model().get_mesh()
|
||||||
@ -289,9 +373,18 @@ class MeshBox(hippo.CanvasBox):
|
|||||||
self._mesh = {}
|
self._mesh = {}
|
||||||
self._buddy_to_activity = {}
|
self._buddy_to_activity = {}
|
||||||
self._suspended = True
|
self._suspended = True
|
||||||
|
self._query = ''
|
||||||
|
|
||||||
self._layout = SpreadLayout()
|
self._toolbar = MeshToolbar()
|
||||||
self.set_layout(self._layout)
|
self._toolbar.connect('query-changed', self._toolbar_query_changed_cb)
|
||||||
|
self.append(hippo.CanvasWidget(widget=self._toolbar))
|
||||||
|
|
||||||
|
self._layout_box = hippo.CanvasBox(background_color=0xe2e2e2ff)
|
||||||
|
self.append(self._layout_box, hippo.PACK_EXPAND)
|
||||||
|
|
||||||
|
center_vertical_offset = - style.GRID_CELL_SIZE
|
||||||
|
self._layout = SpreadLayout(center_vertical_offset)
|
||||||
|
self._layout_box.set_layout(self._layout)
|
||||||
|
|
||||||
for buddy_model in self._model.get_buddies():
|
for buddy_model in self._model.get_buddies():
|
||||||
self._add_alone_buddy(buddy_model)
|
self._add_alone_buddy(buddy_model)
|
||||||
@ -377,6 +470,9 @@ class MeshBox(hippo.CanvasBox):
|
|||||||
else:
|
else:
|
||||||
self._layout.add(icon)
|
self._layout.add(icon)
|
||||||
|
|
||||||
|
if hasattr(icon, 'set_filter'):
|
||||||
|
icon.set_filter(self._query)
|
||||||
|
|
||||||
self._buddies[buddy_model.get_key()] = icon
|
self._buddies[buddy_model.get_key()] = icon
|
||||||
|
|
||||||
def _remove_alone_buddy(self, buddy_model):
|
def _remove_alone_buddy(self, buddy_model):
|
||||||
@ -441,3 +537,10 @@ class MeshBox(hippo.CanvasBox):
|
|||||||
self._suspended = False
|
self._suspended = False
|
||||||
for ap in self._access_points.values():
|
for ap in self._access_points.values():
|
||||||
ap.props.paused = False
|
ap.props.paused = False
|
||||||
|
|
||||||
|
def _toolbar_query_changed_cb(self, toolbar, query):
|
||||||
|
self._query = query.lower()
|
||||||
|
for icon in self._layout_box.get_children():
|
||||||
|
if hasattr(icon, 'set_filter'):
|
||||||
|
icon.set_filter(self._query)
|
||||||
|
|
||||||
|
@ -167,11 +167,13 @@ class _Grid(gobject.GObject):
|
|||||||
self._array[col + row * self.width] = value
|
self._array[col + row * self.width] = value
|
||||||
|
|
||||||
|
|
||||||
class SpreadLayout(gobject.GObject,hippo.CanvasLayout):
|
class SpreadLayout(gobject.GObject, hippo.CanvasLayout):
|
||||||
__gtype_name__ = 'SugarSpreadLayout'
|
__gtype_name__ = 'SugarSpreadLayout'
|
||||||
def __init__(self):
|
def __init__(self, center_vertical_offset=0):
|
||||||
gobject.GObject.__init__(self)
|
gobject.GObject.__init__(self)
|
||||||
|
|
||||||
|
self._center_vertical_offset = center_vertical_offset
|
||||||
|
|
||||||
min_width, width = self.do_get_width_request()
|
min_width, width = self.do_get_width_request()
|
||||||
min_height, height = self.do_get_height_request(width)
|
min_height, height = self.do_get_height_request(width)
|
||||||
|
|
||||||
@ -225,9 +227,10 @@ class SpreadLayout(gobject.GObject,hippo.CanvasLayout):
|
|||||||
else:
|
else:
|
||||||
min_w, child_width = child.get_width_request()
|
min_w, child_width = child.get_width_request()
|
||||||
min_h, child_height = child.get_height_request(child_width)
|
min_h, child_height = child.get_height_request(child_width)
|
||||||
child.allocate(x + (width - child_width) / 2,
|
child_x = x + (width - child_width) / 2
|
||||||
y + (height - child_height) / 2,
|
child_y = y + (height - child_height + self._center_vertical_offset) / 2
|
||||||
child_width, child_height, origin_changed)
|
child.allocate(child_x, child_y, child_width, child_height,
|
||||||
|
origin_changed)
|
||||||
|
|
||||||
def _get_child_grid_size(self, child):
|
def _get_child_grid_size(self, child):
|
||||||
min_width, width = child.get_width_request()
|
min_width, width = child.get_width_request()
|
@ -19,9 +19,9 @@ import gobject
|
|||||||
|
|
||||||
from sugar.graphics import style
|
from sugar.graphics import style
|
||||||
from sugar.graphics import animator
|
from sugar.graphics import animator
|
||||||
from sugar.graphics.spreadlayout import SpreadLayout
|
|
||||||
|
|
||||||
from view.home.MyIcon import MyIcon
|
from view.home.MyIcon import MyIcon
|
||||||
|
from view.home.spreadlayout import SpreadLayout
|
||||||
|
|
||||||
class _Animation(animator.Animation):
|
class _Animation(animator.Animation):
|
||||||
def __init__(self, icon, start_size, end_size):
|
def __init__(self, icon, start_size, end_size):
|
||||||
|
Loading…
Reference in New Issue
Block a user