Merge branch 'master' of git+ssh://danw@dev.laptop.org/git/sugar

This commit is contained in:
Dan Winship 2007-08-08 09:30:50 -04:00
commit 7b21f752ad
21 changed files with 208 additions and 245 deletions

View File

@ -64,7 +64,7 @@ services/console/Makefile
services/console/interface/Makefile services/console/interface/Makefile
services/console/interface/xo/Makefile services/console/interface/xo/Makefile
services/console/interface/memphis/plugins/clean_size/Makefile services/console/interface/memphis/plugins/clean_size/Makefile
services/console/interface/memphis/plugins/dirty_size/Makefile services/console/interface/memphis/plugins/smaps/Makefile
services/console/interface/memphis/plugins/Makefile services/console/interface/memphis/plugins/Makefile
services/console/interface/memphis/plugins/memphis_init/Makefile services/console/interface/memphis/plugins/memphis_init/Makefile
services/console/interface/memphis/plugins/cpu/Makefile services/console/interface/memphis/plugins/cpu/Makefile

View File

@ -28,54 +28,21 @@ static void sugar_menu_init (SugarMenu *menu);
G_DEFINE_TYPE(SugarMenu, sugar_menu, GTK_TYPE_MENU) G_DEFINE_TYPE(SugarMenu, sugar_menu, GTK_TYPE_MENU)
void void
sugar_menu_popup(SugarMenu *menu, sugar_menu_set_active(SugarMenu *menu, gboolean active)
int x,
int y)
{ {
GtkWidget *window; GTK_MENU_SHELL(menu)->active = active;
window = GTK_MENU(menu)->toplevel;
g_return_if_fail(window != NULL);
GTK_MENU_SHELL(menu)->active = TRUE;
gtk_widget_show(GTK_WIDGET(menu));
gtk_window_move(GTK_WINDOW(window), x, y);
gtk_widget_show(window);
} }
void void
sugar_menu_popdown(SugarMenu *menu) sugar_menu_embed(SugarMenu *menu, GtkContainer *parent)
{ {
GtkWidget *window; GTK_MENU(menu)->toplevel = gtk_widget_get_toplevel(GTK_WIDGET(parent));
gtk_widget_reparent(GTK_WIDGET(menu), GTK_WIDGET(parent));
window = GTK_MENU(menu)->toplevel;
g_return_if_fail(window != NULL);
GTK_MENU_SHELL(menu)->active = FALSE;
gtk_widget_hide(GTK_WIDGET(menu));
gtk_widget_hide(window);
}
static void
sugar_menu_size_request (GtkWidget *widget,
GtkRequisition *requisition)
{
SugarMenu *menu = SUGAR_MENU(widget);
(* GTK_WIDGET_CLASS (sugar_menu_parent_class)->size_request) (widget, requisition);
requisition->width = MAX(requisition->width, menu->min_width);
} }
static void static void
sugar_menu_class_init(SugarMenuClass *menu_class) sugar_menu_class_init(SugarMenuClass *menu_class)
{ {
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(menu_class);
widget_class->size_request = sugar_menu_size_request;
} }
static void static void

View File

@ -44,13 +44,11 @@ struct _SugarMenuClass {
GtkMenuClass base_class; GtkMenuClass base_class;
}; };
GType sugar_menu_get_type (void); GType sugar_menu_get_type (void);
void sugar_menu_popup (SugarMenu *menu, void sugar_menu_set_active (SugarMenu *menu,
int x, gboolean active);
int y); void sugar_menu_embed (SugarMenu *menu,
void sugar_menu_set_min_width (SugarMenu *menu, GtkContainer *parent);
int min_width);
void sugar_menu_popdown (SugarMenu *menu);
G_END_DECLS G_END_DECLS

View File

@ -130,15 +130,14 @@ class Data:
treeview.set_model(self.store) treeview.set_model(self.store)
def _start_memphis(self, button): def _start_memphis(self, button):
# Update information every 1.5 second # Update information every 1.5 second
button.hide() button.hide()
self.interface.button_stop.show() self.interface.button_stop.show()
self._running_status = True self._running_status = True
gobject.timeout_add(1500, self.load_data, self.treeview) self._gid = gobject.timeout_add(1500, self.load_data, self.treeview)
def _stop_memphis(self, button): def _stop_memphis(self, button):
gobject.source_remove(self._gid)
self._running_status = False self._running_status = False
button.hide() button.hide()
self.interface.button_start.show() self.interface.button_start.show()

View File

@ -1,4 +1,4 @@
SUBDIRS = clean_size cpu dirty_size memphis_init SUBDIRS = clean_size cpu smaps memphis_init
sugardir = $(pkgdatadir)/services/console/interface/memphis/plugins sugardir = $(pkgdatadir)/services/console/interface/memphis/plugins
sugar_PYTHON = sugar_PYTHON =

View File

@ -1,17 +0,0 @@
import info
INTERNALS = {
# Basic information
'PLGNAME': "Dirty Size",
'TABNAME': None, # No tabbed plugin
'AUTHOR': "Eduardo Silva",
'DESC': "Get dirty size memory usage",
# Plugin API
'Plg': None, # Plugin object
'top_data': [int], # Top data types needed by memphis core plugin
'top_cols': ["PDRSS (kb)"]
}

View File

@ -11,3 +11,4 @@ def plg_on_top_data_refresh(self, ppinfo):
data = [ppinfo['pid'], ppinfo['name'], ppinfo['state_name']] data = [ppinfo['pid'], ppinfo['name'], ppinfo['state_name']]
return data return data

View File

@ -0,0 +1,17 @@
import info
INTERNALS = {
# Basic information
'PLGNAME': "SMaps",
'TABNAME': None, # No tabbed plugin
'AUTHOR': "Eduardo Silva",
'DESC': "Get dirty size and reference memory usage",
# Plugin API
'Plg': None, # Plugin object
'top_data': [int, int], # Top data types needed by memphis core plugin
'top_cols': ["PDRSS (kb)", "Referenced (kb)"]
}

View File

@ -8,13 +8,12 @@
def plg_on_top_data_refresh(self, ppinfo): def plg_on_top_data_refresh(self, ppinfo):
smaps = get_data(self, ppinfo['pid'])
dirty_sizes = get_dirty(self, ppinfo['pid'])
# memhis need an array # memphis need an array
return [dirty_sizes['private']] return [smaps['private_dirty'], smaps['referenced']]
def get_dirty(pself, pid): def get_data(pself, pid):
ProcAnalysis = pself.INTERNALS['Plg'].proc_analysis(pid) ProcAnalysis = pself.INTERNALS['Plg'].proc_analysis(pid)
return ProcAnalysis.DirtyRSS() return ProcAnalysis.SMaps()

View File

@ -7,20 +7,22 @@ class Analysis:
def __init__(self, pid): def __init__(self, pid):
self.pid = pid self.pid = pid
def DirtyRSS(self): def SMaps(self):
smaps = proc_smaps.ProcSmaps(self.pid) smaps = proc_smaps.ProcSmaps(self.pid)
dirty = [] private_dirty = 0
shared_dirty = 0
referenced = 0
private = 0
shared = 0
for map in smaps.mappings: for map in smaps.mappings:
private += map.private_dirty private_dirty += map.private_dirty
shared += map.shared_dirty shared_dirty += map.shared_dirty
referenced += map.referenced
dirty = {"private": int(private), "shared": int(shared)} smaps = {"private_dirty": int(private_dirty), \
"shared_dirty": int(shared_dirty),\
"referenced": int(referenced)}
return dirty return smaps
def ApproxRealMemoryUsage(self): def ApproxRealMemoryUsage(self):
maps = proc_smaps.ProcMaps(self.pid) maps = proc_smaps.ProcMaps(self.pid)

View File

@ -1,4 +1,6 @@
import sys, os import os
import re
import sys
import string import string
class ProcInfo: class ProcInfo:
@ -36,10 +38,12 @@ class ProcInfo:
return None return None
# Parsing data , check 'man 5 proc' for details # Parsing data , check 'man 5 proc' for details
data = infile.read().split() stat_data = infile.read()
infile.close() infile.close()
process_name = self._get_process_name(stat_data)
data = self._get_safe_split(stat_data)
state_dic = { state_dic = {
'R': 'Running', 'R': 'Running',
'S': 'Sleeping', 'S': 'Sleeping',
@ -48,27 +52,34 @@ class ProcInfo:
'T': 'Traced/Stopped', 'T': 'Traced/Stopped',
'W': 'Paging' 'W': 'Paging'
} }
# user and group owners # user and group owners
pidstat = os.stat(pidfile) pidstat = os.stat(pidfile)
info = { info = {
'pid': int(data[0]), # Process ID 'pid': int(data[0]), # Process ID
'name': data[1].strip('()'), # Process name 'name': process_name,
'state': data[2], # Process State, ex: R|S|D|Z|T|W 'state': data[2], # Process State, ex: R|S|D|Z|T|W
'state_name': state_dic[data[2]], # Process State name, ex: Running, sleeping, Zombie, etc 'state_name': state_dic[data[2]], # Process State name, ex: Running, sleeping, Zombie, etc
'ppid': int(data[3]), # Parent process ID 'ppid': int(data[3]), # Parent process ID
'utime': int(data[13]), # Used jiffies in user mode 'utime': int(data[13]), # Used jiffies in user mode
'stime': int(data[14]), # Used jiffies in kernel mode 'stime': int(data[14]), # Used jiffies in kernel mode
'start_time': int(data[21]), # Process time from system boot (jiffies) 'start_time': int(data[21]), # Process time from system boot (jiffies)
'vsize': int(data[22]), # Virtual memory size used (bytes) 'vsize': int(data[22]), # Virtual memory size used (bytes)
'rss': int(data[23])*4, # Resident Set Size (bytes) 'rss': int(data[23])*4, # Resident Set Size (bytes)
'user_id': pidstat.st_uid, # process owner 'user_id': pidstat.st_uid, # process owner
'group_id': pidstat.st_gid # owner group 'group_id': pidstat.st_gid # owner group
} }
return info return info
# Return the process name
def _get_process_name(self, data):
m = re.search("\(.*\)", data)
return m.string[m.start()+1:m.end()-1]
def _get_safe_split(self, data):
new_data = re.sub("\(.*\)", '()', data)
return new_data.split()
# Returns the CPU usage expressed in Jiffies # Returns the CPU usage expressed in Jiffies
def get_CPU_usage(self, cpu_hz, used_jiffies, start_time): def get_CPU_usage(self, cpu_hz, used_jiffies, start_time):

View File

@ -36,7 +36,8 @@ class ProcSmaps:
# Shared_Dirty: 0 kB # Shared_Dirty: 0 kB
# Private_Clean: 8 kB # Private_Clean: 8 kB
# Private_Dirty: 0 kB # Private_Dirty: 0 kB
# Referenced: 4 kb -> Introduced in kernel 2.6.22
while num_lines > 0: while num_lines > 0:
fields = lines[line_idx].split (" ", 5) fields = lines[line_idx].split (" ", 5)
if len (fields) == 6: if len (fields) == 6:
@ -51,13 +52,20 @@ class ProcSmaps:
shared_dirty = self.parse_smaps_size_line (lines[line_idx + 4]) shared_dirty = self.parse_smaps_size_line (lines[line_idx + 4])
private_clean = self.parse_smaps_size_line (lines[line_idx + 5]) private_clean = self.parse_smaps_size_line (lines[line_idx + 5])
private_dirty = self.parse_smaps_size_line (lines[line_idx + 6]) private_dirty = self.parse_smaps_size_line (lines[line_idx + 6])
referenced = self.parse_smaps_size_line (lines[line_idx + 7])
name = name.strip () name = name.strip ()
mapping = Mapping (size, rss, shared_clean, shared_dirty, private_clean, private_dirty, permissions, name) mapping = Mapping (size, rss, shared_clean, shared_dirty, \
private_clean, private_dirty, referenced, permissions, name)
self.mappings.append (mapping) self.mappings.append (mapping)
num_lines -= 7 num_lines -= 8
line_idx += 7 line_idx += 8
self._clear_reference(pid)
def _clear_reference(self, pid):
os.system("echo 1 > /proc/%s/clear_refs" % pid)
# Parses a line of the form "foo: 42 kB" and returns an integer for the "42" field # Parses a line of the form "foo: 42 kB" and returns an integer for the "42" field
def parse_smaps_size_line (self, line): def parse_smaps_size_line (self, line):
@ -66,13 +74,15 @@ class ProcSmaps:
return int(fields[1]) return int(fields[1])
class Mapping: class Mapping:
def __init__ (self, size, rss, shared_clean, shared_dirty, private_clean, private_dirty, permissions, name): def __init__ (self, size, rss, shared_clean, shared_dirty, \
private_clean, private_dirty, referenced, permissions, name):
self.size = size self.size = size
self.rss = rss self.rss = rss
self.shared_clean = shared_clean self.shared_clean = shared_clean
self.shared_dirty = shared_dirty self.shared_dirty = shared_dirty
self.private_clean = private_clean self.private_clean = private_clean
self.private_dirty = private_dirty self.private_dirty = private_dirty
self.referenced = referenced
self.permissions = permissions self.permissions = permissions
self.name = name self.name = name

View File

@ -85,7 +85,8 @@ class BuddyMenu(Palette):
else: else:
menu_item = MenuItem(_('Make friend'), 'stock-add') menu_item = MenuItem(_('Make friend'), 'stock-add')
menu_item.connect('activate', self._make_friend_cb) menu_item.connect('activate', self._make_friend_cb)
self.append_menu_item(menu_item)
self.menu.append(menu_item)
menu_item.show() menu_item.show()
activity = self._shell.get_current_activity() activity = self._shell.get_current_activity()
@ -96,7 +97,7 @@ class BuddyMenu(Palette):
menu_item = MenuItem(_('Invite'), 'stock-invite') menu_item = MenuItem(_('Invite'), 'stock-invite')
menu_item.connect('activate', self._invite_friend_cb) menu_item.connect('activate', self._invite_friend_cb)
self.append_menu_item(menu_item) self.menu.append(menu_item)
menu_item.show() menu_item.show()
def _buddy_icon_changed_cb(self, buddy): def _buddy_icon_changed_cb(self, buddy):

View File

@ -73,9 +73,9 @@ class ClipboardIcon(CanvasIcon):
self._selected = selected self._selected = selected
if selected: if selected:
if not self._hover: if not self._hover:
self.props.background_color = style.COLOR_PANEL_GREY.get_int() self.props.background_color = style.COLOR_SELECTION_GREY.get_int()
else: else:
self.props.background_color = style.COLOR_TOOLBAR_GREY.get_int() self.props.background_color = style.COLOR_PANEL_GREY.get_int()
def set_state(self, name, percent, icon_name, preview, activity): def set_state(self, name, percent, icon_name, preview, activity):
cb_service = clipboardservice.get_instance() cb_service = clipboardservice.get_instance()
@ -107,11 +107,11 @@ class ClipboardIcon(CanvasIcon):
def prelight(self, enter): def prelight(self, enter):
if enter: if enter:
self._hover = True self._hover = True
self.props.background_color = color.BLACK.get_int() self.props.background_color = style.COLOR_BLACK.get_int()
else: else:
self._hover = False self._hover = False
if self._selected: if self._selected:
self.props.background_color = color.DESKTOP_BACKGROUND.get_int() self.props.background_color = style.COLOR_SELECTION_GREY.get_int()
else: else:
self.props.background_color = color.TOOLBAR_BACKGROUND.get_int() self.props.background_color = style.COLOR_PANEL_GREY.get_int()

View File

@ -130,7 +130,7 @@ class HomeMyIcon(MyIcon):
shutdown_menu_item = gtk.MenuItem(_('Shutdown')) shutdown_menu_item = gtk.MenuItem(_('Shutdown'))
shutdown_menu_item.connect('activate', self._shutdown_activate_cb) shutdown_menu_item.connect('activate', self._shutdown_activate_cb)
palette.append_menu_item(shutdown_menu_item) palette.menu.append(shutdown_menu_item)
shutdown_menu_item.show() shutdown_menu_item.show()
self.set_palette(palette) self.set_palette(palette)

View File

@ -88,14 +88,14 @@ class ActivityIcon(CanvasIcon):
resume_menu_item = gtk.MenuItem(_('Resume')) resume_menu_item = gtk.MenuItem(_('Resume'))
resume_menu_item.connect('activate', self._resume_activate_cb) resume_menu_item.connect('activate', self._resume_activate_cb)
palette.append_menu_item(resume_menu_item) palette.menu.append(resume_menu_item)
resume_menu_item.show() resume_menu_item.show()
# FIXME: kludge # FIXME: kludge
if self._activity.get_type() != "org.laptop.JournalActivity": if self._activity.get_type() != "org.laptop.JournalActivity":
stop_menu_item = gtk.MenuItem(_('Stop')) stop_menu_item = gtk.MenuItem(_('Stop'))
stop_menu_item.connect('activate', self._stop_activate_cb) stop_menu_item.connect('activate', self._stop_activate_cb)
palette.append_menu_item(stop_menu_item) palette.menu.append(stop_menu_item)
stop_menu_item.show() stop_menu_item.show()
def _launching_changed_cb(self, activity, pspec): def _launching_changed_cb(self, activity, pspec):

View File

@ -26,20 +26,22 @@
;; From sugar-menu.h ;; From sugar-menu.h
(define-method popup (define-method set_active
(of-object "SugarMenu") (of-object "SugarMenu")
(c-name "sugar_menu_popup") (c-name "sugar_menu_set_active")
(return-type "none") (return-type "none")
(parameters (parameters
'("gint" "x") '("gboolean" "active")
'("gint" "y")
) )
) )
(define-method popdown (define-method embed
(of-object "SugarMenu") (of-object "SugarMenu")
(c-name "sugar_menu_popdown") (c-name "sugar_menu_embed")
(return-type "none") (return-type "none")
(parameters
'("GtkContainer" "container")
)
) )
;; From sugar-key-grabber.h ;; From sugar-key-grabber.h

View File

@ -18,6 +18,7 @@ modulename _sugarext
import gobject.GObject as PyGObject_Type import gobject.GObject as PyGObject_Type
import gtk.Entry as PyGtkEntry_Type import gtk.Entry as PyGtkEntry_Type
import gtk.Menu as PyGtkMenu_Type import gtk.Menu as PyGtkMenu_Type
import gtk.Container as PyGtkContainer_Type
import gtk.gdk.Window as PyGdkWindow_Type import gtk.gdk.Window as PyGdkWindow_Type
%% %%
ignore-glob ignore-glob

View File

@ -36,7 +36,7 @@ _RIGHT_TOP = 5
_TOP_LEFT = 6 _TOP_LEFT = 6
_TOP_RIGHT = 7 _TOP_RIGHT = 7
class Palette(gobject.GObject): class Palette(gtk.Window):
DEFAULT = 0 DEFAULT = 0
AT_CURSOR = 1 AT_CURSOR = 1
AROUND = 2 AROUND = 2
@ -65,12 +65,16 @@ class Palette(gobject.GObject):
} }
def __init__(self, label, accel_path=None): def __init__(self, label, accel_path=None):
gobject.GObject.__init__(self) gtk.Window.__init__(self)
self.set_decorated(False)
self.set_resizable(False)
self.connect('realize', self._realize_cb)
self._full_request = [0, 0] self._full_request = [0, 0]
self._cursor_x = 0 self._cursor_x = 0
self._cursor_y = 0 self._cursor_y = 0
self._state = self._SECONDARY self._state = self._PRIMARY
self._invoker = None self._invoker = None
self._group_id = None self._group_id = None
self._up = False self._up = False
@ -86,60 +90,60 @@ class Palette(gobject.GObject):
self._popdown_anim = animator.Animator(0.6, 10) self._popdown_anim = animator.Animator(0.6, 10)
self._popdown_anim.add(_PopdownAnimation(self)) self._popdown_anim.add(_PopdownAnimation(self))
self._menu = _sugaruiext.Menu() vbox = gtk.VBox()
vbox.set_border_width(style.DEFAULT_PADDING)
self._primary = _PrimaryMenuItem(label, accel_path) self._label = gtk.Label()
self._menu.append(self._primary) vbox.pack_start(self._label, False)
self._primary.show()
self._separator = gtk.SeparatorMenuItem() self._secondary_box = gtk.VBox()
self._menu.append(self._separator) vbox.pack_start(self._secondary_box)
self._content = _ContentMenuItem() self._separator = gtk.HSeparator()
self._menu.append(self._content) self._secondary_box.pack_start(self._separator)
self._button_bar = _ButtonBarMenuItem() menu_box = gtk.VBox()
self._menu.append(self._button_bar) self._secondary_box.pack_start(menu_box)
menu_box.show()
self._menu.connect('enter-notify-event', self._content = gtk.VBox()
self._enter_notify_event_cb) self._secondary_box.pack_start(self._content)
self._menu.connect('leave-notify-event', self._content.show()
self._leave_notify_event_cb)
self.action_bar = PaletteActionBar()
self._secondary_box.pack_start(self.action_bar)
self.action_bar.show()
self.add(vbox)
vbox.show()
self.menu = _Menu(self)
self.menu.embed(menu_box)
self.menu.show()
self.connect('enter-notify-event',
self._enter_notify_event_cb)
self.connect('leave-notify-event',
self._leave_notify_event_cb)
self.set_primary_text(label, accel_path)
def is_up(self): def is_up(self):
return self._up return self._up
def set_primary_text(self, label, accel_path=None): def set_primary_text(self, label, accel_path=None):
self._primary.set_label(label, accel_path) self._label.set_text(label)
self._label.show()
def append_menu_item(self, item):
self._separator.show()
self._menu.insert(item, len(self._menu.get_children()) - 2)
def insert_menu_item(self, item, index=-1):
self._separator.show()
if index < 0:
self._menu.insert(item, len(self._menu.get_children()) - 2)
else:
self._menu.insert(item, index + 2)
def remove_menu_item(self, index):
if index > len(self._menu.get_children()) - 4:
raise ValueError('index %i out of range' % index)
self._menu.remove(self._menu.get_children()[index + 2])
if len(self._menu.get_children()) == 0:
self._separator.hide()
def menu_item_count(self):
return len(self._menu.get_children()) - 4
def set_content(self, widget): def set_content(self, widget):
self._content.set_widget(widget) if len(self._content.get_children()) > 0:
self._content.show() self.remove(self._content.get_children()[0])
def append_button(self, button): if widget is not None:
self._button_bar.append_button(button) self._content.add(widget)
self._button_bar.show()
self._update_accept_focus()
self._update_separator()
def set_group_id(self, group_id): def set_group_id(self, group_id):
if self._group_id: if self._group_id:
@ -154,7 +158,6 @@ class Palette(gobject.GObject):
self._invoker = value self._invoker = value
self._invoker.connect('mouse-enter', self._invoker_mouse_enter_cb) self._invoker.connect('mouse-enter', self._invoker_mouse_enter_cb)
self._invoker.connect('mouse-leave', self._invoker_mouse_leave_cb) self._invoker.connect('mouse-leave', self._invoker_mouse_leave_cb)
self._invoker.connect('focus-out', self._invoker_focus_out_cb)
elif pspec.name == 'position': elif pspec.name == 'position':
self._position = value self._position = value
else: else:
@ -168,6 +171,20 @@ class Palette(gobject.GObject):
else: else:
raise AssertionError raise AssertionError
def _update_separator(self):
visible = len(self.menu.get_children()) > 0 or \
len(self._content.get_children()) > 0
self._separator.props.visible = visible
def _update_accept_focus(self):
accept_focus = len(self._content.get_children())
if self.window:
self.window.set_accept_focus(accept_focus)
def _realize_cb(self, widget):
self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
self._update_accept_focus()
def _in_screen(self, x, y): def _in_screen(self, x, y):
[width, height] = self._full_request [width, height] = self._full_request
screen_area = self._invoker.get_screen_area() screen_area = self._invoker.get_screen_area()
@ -182,7 +199,7 @@ class Palette(gobject.GObject):
if inv_rect == None: if inv_rect == None:
inv_rect = self._invoker.get_rect() inv_rect = self._invoker.get_rect()
palette_width, palette_height = self._menu.size_request() palette_width, palette_height = self.size_request()
x = inv_rect.x + inv_rect.width * invoker_halign + \ x = inv_rect.x + inv_rect.width * invoker_halign + \
palette_width * palette_halign palette_width * palette_halign
@ -241,12 +258,12 @@ class Palette(gobject.GObject):
def _update_full_request(self): def _update_full_request(self):
state = self._state state = self._state
self._menu.set_size_request(-1, -1) self.set_size_request(-1, -1)
self._set_state(self._SECONDARY) self._set_state(self._SECONDARY)
self._full_request = self._menu.size_request() self._full_request = self.size_request()
self._menu.set_size_request(self._full_request[0], -1) self.set_size_request(self._full_request[0], -1)
self._set_state(state) self._set_state(state)
@ -282,7 +299,7 @@ class Palette(gobject.GObject):
elif position == self.TOP: elif position == self.TOP:
x, y = self._get_top_position() x, y = self._get_top_position()
self._menu.popup(x, y) self.move(x, y)
def _show(self): def _show(self):
if self._up: if self._up:
@ -291,11 +308,12 @@ class Palette(gobject.GObject):
self._update_cursor_position() self._update_cursor_position()
self._update_full_request() self._update_full_request()
self._invoker.connect_to_parent() self._palette_popup_sid = _palette_observer.connect(
self._palette_popup_sid = _palette_observer.connect('popup', 'popup', self._palette_observer_popup_cb)
self._palette_observer_popup_cb)
self._update_position() self._update_position()
self.menu.set_active(True)
self.show()
self._up = True self._up = True
_palette_observer.emit('popup', self) _palette_observer.emit('popup', self)
@ -305,7 +323,8 @@ class Palette(gobject.GObject):
if not self._palette_popup_sid is None: if not self._palette_popup_sid is None:
_palette_observer.disconnect(self._palette_popup_sid) _palette_observer.disconnect(self._palette_popup_sid)
self._palette_popup_sid = None self._palette_popup_sid = None
self._menu.popdown() self.menu.set_active(False)
self.hide()
self._up = False self._up = False
self.emit('popdown') self.emit('popdown')
@ -329,25 +348,9 @@ class Palette(gobject.GObject):
return return
if state == self._PRIMARY: if state == self._PRIMARY:
self._primary.show() self._secondary_box.hide()
for menu_item in self._menu.get_children()[1:]:
menu_item.hide()
elif state == self._SECONDARY: elif state == self._SECONDARY:
middle_menu_items = self._menu.get_children() self._secondary_box.show()
middle_menu_items = middle_menu_items[2:len(middle_menu_items) - 2]
if middle_menu_items or \
not self._content.is_empty() or \
not self._button_bar.is_empty():
self._separator.show()
for menu_item in middle_menu_items:
menu_item.show()
if not self._content.is_empty():
self._content.show()
if not self._button_bar.is_empty():
self._button_bar.show()
self._state = state self._state = state
@ -357,68 +360,44 @@ class Palette(gobject.GObject):
def _invoker_mouse_leave_cb(self, invoker): def _invoker_mouse_leave_cb(self, invoker):
self.popdown() self.popdown()
def _invoker_focus_out_cb(self, invoker):
self._hide()
def _enter_notify_event_cb(self, widget, event): def _enter_notify_event_cb(self, widget, event):
if event.detail == gtk.gdk.NOTIFY_NONLINEAR: if event.detail != gtk.gdk.NOTIFY_INFERIOR:
self._popdown_anim.stop() self._popdown_anim.stop()
self._secondary_anim.start() self._secondary_anim.start()
def _leave_notify_event_cb(self, widget, event): def _leave_notify_event_cb(self, widget, event):
if event.detail == gtk.gdk.NOTIFY_NONLINEAR: if event.detail != gtk.gdk.NOTIFY_INFERIOR:
self.popdown() self.popdown()
def _palette_observer_popup_cb(self, observer, palette): def _palette_observer_popup_cb(self, observer, palette):
if self != palette: if self != palette:
self._hide() self._hide()
class _PrimaryMenuItem(gtk.MenuItem): class PaletteActionBar(gtk.HButtonBox):
def __init__(self, label, accel_path): def add_action(label, icon_name=None):
gtk.MenuItem.__init__(self) button = Button(label)
self.set_border_width(style.DEFAULT_PADDING)
self._set_label(label, accel_path)
def set_label(self, label, accel_path): if icon_name:
self.remove(self._label) icon = Icon(icon_name)
self._set_label(label, accel_path) button.set_image(icon)
icon.show()
def _set_label(self, label, accel_path): self.pack_start(button)
self._label = gtk.AccelLabel(label) button.show()
self._label.set_accel_widget(self)
if accel_path: class _Menu(_sugaruiext.Menu):
self.set_accel_path(accel_path) __gtype_name__ = 'SugarPaletteMenu'
self._label.set_alignment(0.0, 0.5)
self.add(self._label) def __init__(self, palette):
self._label.show() _sugaruiext.Menu.__init__(self)
self._palette = palette
class _ContentMenuItem(gtk.MenuItem):
def __init__(self):
gtk.MenuItem.__init__(self)
def set_widget(self, widget): def do_insert(self, item, position):
if self.child: _sugaruiext.Menu.do_insert(self, item, position)
self.remove(self.child) self._palette._update_separator()
self.add(widget)
def is_empty(self): def do_deactivate(self):
return self.child is None or not self.child.props.visible self._palette._hide()
class _ButtonBarMenuItem(gtk.MenuItem):
def __init__(self):
gtk.MenuItem.__init__(self)
self._hbar = gtk.HButtonBox()
self.add(self._hbar)
self._hbar.show()
def append_button(self, button):
self._hbar.pack_start(button)
def is_empty(self):
return len(self._hbar.get_children()) == 0
class _PopupAnimation(animator.Animation): class _PopupAnimation(animator.Animation):
def __init__(self, palette): def __init__(self, palette):
@ -469,13 +448,6 @@ class Invoker(gobject.GObject):
height = gtk.gdk.screen_height() height = gtk.gdk.screen_height()
return gtk.gdk.Rectangle(0, 0, width, height) return gtk.gdk.Rectangle(0, 0, width, height)
def connect_to_parent(self):
window = self.get_toplevel()
window.connect('focus-out-event', self._window_focus_out_event_cb)
def _window_focus_out_event_cb(self, widget, event):
self.emit('focus-out')
class WidgetInvoker(Invoker): class WidgetInvoker(Invoker):
def __init__(self, widget): def __init__(self, widget):
Invoker.__init__(self) Invoker.__init__(self)