本文整理汇总了Python中jarabe.frame.notification.NotificationIcon.drag_source_set方法的典型用法代码示例。如果您正苦于以下问题:Python NotificationIcon.drag_source_set方法的具体用法?Python NotificationIcon.drag_source_set怎么用?Python NotificationIcon.drag_source_set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jarabe.frame.notification.NotificationIcon
的用法示例。
在下文中一共展示了NotificationIcon.drag_source_set方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ClipboardIcon
# 需要导入模块: from jarabe.frame.notification import NotificationIcon [as 别名]
# 或者: from jarabe.frame.notification.NotificationIcon import drag_source_set [as 别名]
#.........这里部分代码省略.........
self._clipboard_clear_cb,
targets)
else:
stored = SugarExt.clipboard_set_with_data(
x_clipboard,
targets,
self._clipboard_data_get_cb,
self._clipboard_clear_cb,
targets)
if not stored:
logging.error('GtkClipboard.set_with_data failed!')
else:
self.owns_clipboard = True
def _clipboard_data_get_cb(self, x_clipboard, selection, info, targets):
selection_target = selection.get_target()
entries_targets = [entry.target for entry in targets]
if not str(selection_target) in entries_targets:
logging.warning('ClipboardIcon._clipboard_data_get_cb: asked %s'
' but only have %r.', selection_target,
entries_targets)
return
data = self._cb_object.get_formats()[str(selection_target)].get_data()
selection.set(selection_target, 8, data)
def _clipboard_clear_cb(self, x_clipboard, targets):
logging.debug('ClipboardIcon._clipboard_clear_cb')
self.owns_clipboard = False
def _object_state_changed_cb(self, cb_service, cb_object):
if cb_object != self._cb_object:
return
if cb_object.get_icon():
self._icon.props.icon_name = cb_object.get_icon()
if self._notif_icon:
self._notif_icon.props.icon_name = self._icon.props.icon_name
else:
self._icon.props.icon_name = 'application-octet-stream'
child = self.get_child()
child.connect('drag-begin', self._drag_begin_cb)
child.drag_source_set(Gdk.ModifierType.BUTTON1_MASK,
self._get_targets(),
Gdk.DragAction.COPY)
if cb_object.get_percent() == 100:
self.props.sensitive = True
# Clipboard object became complete. Make it the active one.
if self._current_percent < 100 and cb_object.get_percent() == 100:
self.props.active = True
self.show_notification()
self._current_percent = cb_object.get_percent()
def _object_selected_cb(self, cb_service, object_id):
if object_id != self._cb_object.get_id():
return
self.props.active = True
self.show_notification()
logging.debug('ClipboardIcon: %r was selected', object_id)
def show_notification(self):
self._notif_icon = NotificationIcon()
self._notif_icon.props.icon_name = self._icon.props.icon_name
self._notif_icon.props.xo_color = \
XoColor('%s,%s' % (self._icon.props.stroke_color,
self._icon.props.fill_color))
frame = jarabe.frame.get_view()
self._timeout_id = frame.add_notification(
self._notif_icon, Gtk.CornerType.BOTTOM_LEFT)
self._notif_icon.connect('drag_data_get', self._drag_data_get_cb)
self._notif_icon.connect('drag-begin', self._drag_begin_cb)
self._notif_icon.drag_source_set(Gdk.ModifierType.BUTTON1_MASK,
self._get_targets(),
Gdk.DragAction.COPY)
def _drag_begin_cb(self, widget, context):
# TODO: We should get the pixbuf from the icon, with colors, etc.
GObject.source_remove(self._timeout_id)
icon_theme = Gtk.IconTheme.get_default()
pixbuf = icon_theme.load_icon(self._icon.props.icon_name,
style.STANDARD_ICON_SIZE, 0)
Gtk.drag_set_icon_pixbuf(context, pixbuf, hot_x=pixbuf.props.width / 2,
hot_y=pixbuf.props.height / 2)
def _notify_active_cb(self, widget, pspec):
if self.props.active:
self._put_in_clipboard()
else:
self.owns_clipboard = False
def _get_targets(self):
targets = []
for format_type in self._cb_object.get_formats().keys():
targets.append(Gtk.TargetEntry.new(format_type,
Gtk.TargetFlags.SAME_APP, 0))
return targets