Merge branch 'master' of git+ssh://dev.laptop.org/git/sugar
This commit is contained in:
commit
3742219d6c
@ -17,9 +17,11 @@
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <gdk/gdkx.h>
|
||||
|
||||
#include "sugar-utils.h"
|
||||
|
||||
gint
|
||||
sugar_get_screen_dpi(void)
|
||||
{
|
||||
@ -27,8 +29,8 @@ sugar_get_screen_dpi(void)
|
||||
if (val) {
|
||||
char *e;
|
||||
double d = strtod(val, &e);
|
||||
if (e != val)
|
||||
return round(d);
|
||||
if (d > 0.0)
|
||||
return (int)(d+0.5);
|
||||
}
|
||||
|
||||
return 96;
|
||||
|
@ -29,7 +29,7 @@ class TextFileType(FileType):
|
||||
return _('Text snippet')
|
||||
|
||||
def get_icon(self):
|
||||
return 'theme:activity-xbook'
|
||||
return 'theme:object-text'
|
||||
|
||||
def get_preview(self):
|
||||
for format, data in self._formats.iteritems():
|
||||
@ -57,7 +57,7 @@ class ImageFileType(FileType):
|
||||
return _('Image')
|
||||
|
||||
def get_icon(self):
|
||||
return 'theme:activity-sketch'
|
||||
return 'theme:object-image'
|
||||
|
||||
def get_preview(self):
|
||||
return ''
|
||||
@ -77,7 +77,7 @@ class UriFileType(FileType):
|
||||
return _('Web Page')
|
||||
|
||||
def get_icon(self):
|
||||
return 'theme:activity-web'
|
||||
return 'theme:object-link'
|
||||
|
||||
def get_preview(self):
|
||||
for format, data in self._formats.iteritems():
|
||||
@ -103,7 +103,7 @@ class PdfFileType(FileType):
|
||||
return _('PDF file')
|
||||
|
||||
def get_icon(self):
|
||||
return 'theme:activity-xbook'
|
||||
return 'theme:object-text'
|
||||
|
||||
def get_preview(self):
|
||||
return ''
|
||||
@ -123,7 +123,7 @@ class MsWordFileType(FileType):
|
||||
return _('MS Word file')
|
||||
|
||||
def get_icon(self):
|
||||
return 'theme:activity-abiword'
|
||||
return 'theme:object-text'
|
||||
|
||||
def get_preview(self):
|
||||
return ''
|
||||
@ -143,7 +143,7 @@ class RtfFileType(FileType):
|
||||
return _('RTF file')
|
||||
|
||||
def get_icon(self):
|
||||
return 'theme:activity-abiword'
|
||||
return 'theme:object-text'
|
||||
|
||||
def get_preview(self):
|
||||
return ''
|
||||
@ -163,7 +163,7 @@ class OOTextFileType(FileType):
|
||||
return _('OpenOffice text file')
|
||||
|
||||
def get_icon(self):
|
||||
return 'theme:activity-abiword'
|
||||
return 'theme:object-text'
|
||||
|
||||
def get_preview(self):
|
||||
return ''
|
||||
|
@ -80,7 +80,7 @@ class Menu(Popup):
|
||||
'action': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([object]))
|
||||
}
|
||||
|
||||
def __init__(self, title):
|
||||
def __init__(self, title=None):
|
||||
Popup.__init__(self)
|
||||
|
||||
self.props.background_color = color.MENU_BACKGROUND.get_int()
|
||||
|
@ -24,70 +24,27 @@ import hippo
|
||||
|
||||
from sugar.graphics import units
|
||||
from sugar.graphics.roundbox import RoundBox
|
||||
from sugar.graphics.menu import Menu, MenuItem
|
||||
from sugar.graphics import iconbutton
|
||||
from sugar.graphics import color
|
||||
from sugar.graphics import font
|
||||
from sugar.graphics.canvasicon import CanvasIcon
|
||||
|
||||
class Menu(hippo.CanvasBox, hippo.CanvasItem):
|
||||
__gtype_name__ = 'SugarMenu'
|
||||
|
||||
__gsignals__ = {
|
||||
'action': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([object]))
|
||||
}
|
||||
|
||||
class _Menu(Menu):
|
||||
def __init__(self):
|
||||
hippo.CanvasBox.__init__(self)
|
||||
self.props.background_color = color.MENU_BACKGROUND.get_int()
|
||||
self.props.border_color = color.MENU_BORDER.get_int()
|
||||
self.props.border = units.points_to_pixels(1)
|
||||
self._window = None
|
||||
|
||||
def add_item(self, action_id, label, icon_name=None, icon_color=None):
|
||||
box = hippo.CanvasBox(orientation=hippo.ORIENTATION_HORIZONTAL)
|
||||
box.props.padding = 5
|
||||
box.props.spacing = 5
|
||||
if icon_name:
|
||||
icon = CanvasIcon(icon_name=icon_name,
|
||||
scale=units.SMALL_ICON_SCALE)
|
||||
if icon_color:
|
||||
icon.props.color = icon_color
|
||||
box.append(icon)
|
||||
|
||||
canvas_text = hippo.CanvasText()
|
||||
canvas_text.props.text = label
|
||||
canvas_text.props.color = color.LABEL_TEXT.get_int()
|
||||
canvas_text.props.font_desc = font.DEFAULT.get_pango_desc()
|
||||
box.append(canvas_text)
|
||||
|
||||
box.connect('button-press-event', self._item_button_press_event_cb,
|
||||
[action_id, label])
|
||||
self.append(box)
|
||||
|
||||
def add_separator(self):
|
||||
box = hippo.CanvasBox()
|
||||
box.props.background_color = color.MENU_SEPARATOR.get_int()
|
||||
box.props.box_height = units.points_to_pixels(1)
|
||||
self.append(box)
|
||||
|
||||
def show(self, x, y):
|
||||
if not self._window:
|
||||
self._window = hippo.CanvasWindow(gtk.WINDOW_POPUP)
|
||||
self._window.move(x, y)
|
||||
self._window.set_root(self)
|
||||
self._window.show()
|
||||
|
||||
def hide(self):
|
||||
if self._window:
|
||||
self._window.destroy()
|
||||
self._window = None
|
||||
|
||||
def _item_button_press_event_cb(self, item, event, data):
|
||||
self.emit('action', data)
|
||||
self.hide()
|
||||
Menu.__init__(self)
|
||||
self._is_visible = False
|
||||
|
||||
def is_visible(self):
|
||||
return self._window != None
|
||||
return self._is_visible
|
||||
|
||||
def popup(self, x, y):
|
||||
Menu.popup(self, x, y)
|
||||
self._is_visible = True
|
||||
|
||||
def popdown(self):
|
||||
Menu.popdown(self)
|
||||
self._is_visible = False
|
||||
|
||||
class OptionMenu(hippo.CanvasBox, hippo.CanvasItem):
|
||||
__gtype_name__ = 'SugarOptionMenu'
|
||||
@ -122,8 +79,9 @@ class OptionMenu(hippo.CanvasBox, hippo.CanvasItem):
|
||||
arrow.props.xalign = hippo.ALIGNMENT_START
|
||||
self._round_box.append(arrow)
|
||||
|
||||
self._menu = Menu()
|
||||
self._menu = _Menu()
|
||||
self._menu.connect('action', self._menu_action_cb)
|
||||
self._menu.connect('action-completed', self._menu_action_completed_cb)
|
||||
|
||||
self.connect('button-press-event', self._button_press_event_cb)
|
||||
|
||||
@ -135,19 +93,19 @@ class OptionMenu(hippo.CanvasBox, hippo.CanvasItem):
|
||||
if pspec.name == 'value':
|
||||
return self._value
|
||||
|
||||
def add_option(self, action_id, label, icon_name=None, icon_color=None):
|
||||
def add_item(self, menu_item):
|
||||
if not self._value:
|
||||
self._value = action_id
|
||||
self._canvas_text.props.text = label
|
||||
self._value = menu_item.props.action_id
|
||||
self._canvas_text.props.text = menu_item.props.label
|
||||
|
||||
self._menu.add_item(action_id, label, icon_name, icon_color)
|
||||
self._menu.add_item(menu_item)
|
||||
|
||||
def add_separator(self):
|
||||
self._menu.add_separator()
|
||||
|
||||
def _button_press_event_cb(self, box, event):
|
||||
if self._menu.is_visible():
|
||||
self._menu.hide()
|
||||
self._menu.popdown()
|
||||
else:
|
||||
context = self._round_box.get_context()
|
||||
[x, y] = context.translate_to_screen(self._round_box)
|
||||
@ -156,11 +114,16 @@ class OptionMenu(hippo.CanvasBox, hippo.CanvasItem):
|
||||
self._menu.props.box_width = self.get_width_request()
|
||||
|
||||
[width, height] = self._round_box.get_allocation()
|
||||
self._menu.show(x, y + height)
|
||||
self._menu.popup(x, y + height)
|
||||
|
||||
def _menu_action_cb(self, menu, data):
|
||||
[action_id, label] = data
|
||||
def _menu_action_cb(self, menu, menu_item):
|
||||
action_id = menu_item.props.action_id
|
||||
label = menu_item.props.label
|
||||
|
||||
if action_id != self._value:
|
||||
self._value = action_id
|
||||
self._canvas_text.props.text = label
|
||||
self.emit('changed')
|
||||
|
||||
def _menu_action_completed_cb(self, menu):
|
||||
self._menu.popdown()
|
||||
|
@ -24,6 +24,7 @@ import hippo
|
||||
|
||||
from sugar.graphics.toolbar import Toolbar
|
||||
from sugar.graphics.optionmenu import OptionMenu
|
||||
from sugar.graphics.menu import MenuItem
|
||||
from sugar.graphics.iconbutton import IconButton
|
||||
|
||||
def _option_menu_changed_cb(option_menu):
|
||||
@ -56,11 +57,11 @@ OPTION_WRITE = 3
|
||||
OPTION_CHAT = 4
|
||||
|
||||
option_menu = OptionMenu()
|
||||
option_menu.add_option(OPTION_ANYTHING, _('Anything'))
|
||||
option_menu.add_item(MenuItem(OPTION_ANYTHING, _('Anything')))
|
||||
option_menu.add_separator()
|
||||
option_menu.add_option(OPTION_DRAW, _('Draw'), 'theme:stock-close')
|
||||
option_menu.add_option(OPTION_WRITE, _('Write'))
|
||||
option_menu.add_option(OPTION_CHAT, _('Chat'))
|
||||
option_menu.add_item(MenuItem(OPTION_DRAW, _('Draw'), 'theme:stock-close'))
|
||||
option_menu.add_item(MenuItem(OPTION_WRITE, _('Write')))
|
||||
option_menu.add_item(MenuItem(OPTION_CHAT, _('Chat')))
|
||||
option_menu.connect('changed', _option_menu_changed_cb)
|
||||
toolbar.append(option_menu)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user