[kupfer: 8/51] Port uiutils and show_text to wants_context
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [kupfer: 8/51] Port uiutils and show_text to wants_context
- Date: Mon, 28 Mar 2011 15:01:45 +0000 (UTC)
commit 336bd4035276bdec2f67083c6905baf6fd63b9e8
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Mon Mar 28 16:51:41 2011 +0200
Port uiutils and show_text to wants_context
kupfer/plugin/show_text.py | 15 +++++++++++----
kupfer/uiutils.py | 27 +++++++++++++++++++++------
2 files changed, 32 insertions(+), 10 deletions(-)
---
diff --git a/kupfer/plugin/show_text.py b/kupfer/plugin/show_text.py
index 8bfcecc..4c3a026 100644
--- a/kupfer/plugin/show_text.py
+++ b/kupfer/plugin/show_text.py
@@ -17,8 +17,12 @@ class ShowText (Action):
def __init__(self):
Action.__init__(self, _("Show Text"))
- def activate(self, leaf):
- uiutils.show_text_result(leaf.get_text_representation(), title=_("Show Text"))
+ def wants_context(self):
+ return True
+
+ def activate(self, leaf, ctx):
+ uiutils.show_text_result(leaf.get_text_representation(),
+ title=_("Show Text"), ctx=ctx)
def item_types(self):
yield TextLeaf
@@ -32,8 +36,11 @@ class LargeType (Action):
def __init__(self):
Action.__init__(self, _("Large Type"))
- def activate(self, leaf):
- uiutils.show_large_type(leaf.get_text_representation())
+ def wants_context(self):
+ return True
+
+ def activate(self, leaf, ctx):
+ uiutils.show_large_type(leaf.get_text_representation(), ctx)
def item_types(self):
yield Leaf
diff --git a/kupfer/uiutils.py b/kupfer/uiutils.py
index 62a8e44..ee4fdc5 100644
--- a/kupfer/uiutils.py
+++ b/kupfer/uiutils.py
@@ -46,7 +46,7 @@ def builder_get_objects_from_file(fname, attrs, autoconnect_to=None):
if autoconnect_to:
builder.connect_signals(autoconnect_to, user_data=names)
-def show_text_result(text, title=None):
+def show_text_result(text, title=None, ctx=None):
"""
Show @text in a result window.
@@ -88,6 +88,9 @@ def show_text_result(text, title=None):
if title:
window.set_title(title)
+ if ctx:
+ ctx.environment.present_window(window)
+
window.show_all()
# Fix Sizing:
@@ -105,7 +108,10 @@ def show_text_result(text, title=None):
hsize = int(min(wid + (winwid - oldwid) + 5, max_hsize))
window.resize(hsize, vsize)
- window.present_with_time(uievents.current_event_time())
+ if ctx:
+ ctx.environment.present_window(window)
+ else:
+ window.present_with_time(uievents.current_event_time())
def _wrap_paragraphs(text):
"""
@@ -114,7 +120,7 @@ def _wrap_paragraphs(text):
import textwrap
return u"\n\n".join(textwrap.fill(par) for par in text.split("\n\n"))
-def show_large_type(text):
+def show_large_type(text, ctx=None):
"""
Show @text, large, in a result window.
"""
@@ -136,8 +142,14 @@ def show_large_type(text):
size = 72.0
set_font_size(label, size)
- maxwid = gtk.gdk.screen_width() - 50
- maxhei = gtk.gdk.screen_height() - 100
+ if ctx:
+ screen = ctx.environment.get_screen()
+ window.set_screen(screen)
+ else:
+ screen = gtk.gdk.screen_get_default()
+
+ maxwid = screen.get_width() - 50
+ maxhei = screen.get_height() - 100
wid, hei = label.size_request()
# If the text contains long lines, we try to
@@ -167,7 +179,10 @@ def show_large_type(text):
return True
window.connect("key-press-event", _window_destroy)
window.show_all()
- window.present_with_time(uievents.current_event_time())
+ if ctx:
+ ctx.environment.present_window(window)
+ else:
+ window.present_with_time(uievents.current_event_time())
SERVICE_NAME = "org.freedesktop.Notifications"
OBJECT_PATH = "/org/freedesktop/Notifications"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]