Exemplo n.º 1
0
def launch_application(app_info,
                       files=(),
                       uris=(),
                       paths=(),
                       track=True,
                       activate=True,
                       desktop_file=None,
                       screen=None):
    """
    Launch @app_rec correctly, using a startup notification

    you may pass in either a list of Gio.Files in @files, or 
    a list of @uris or @paths

    if @track, it is a user-level application
    if @activate, activate rather than start a new version

    @app_rec is either an GAppInfo or (GAppInfo, desktop_file_path) tuple

    Raises SpawnError on failed program start.
    """
    assert app_info

    if paths:
        files = [Gio.File.new_for_path(p) for p in paths]
    if uris:
        files = [Gio.File.new_for_uri(p) for p in uris]

    svc = GetApplicationsMatcherService()
    app_id = application_id(app_info, desktop_file)

    if activate and svc.application_is_running(app_id):
        svc.application_to_front(app_id)
        return True

    # An launch callback closure for the @app_id
    def application_launch_callback(argv, pid, notify_id, files, timestamp):
        is_terminal = terminal.is_known_terminal_executable(argv[0])
        if not is_terminal:
            svc.launched_application(app_id, pid)

    if track:
        launch_callback = application_launch_callback
    else:
        launch_callback = None

    try:
        desktop_launch.launch_app_info(app_info,
                                       files,
                                       timestamp=uievents.current_event_time(),
                                       desktop_file=desktop_file,
                                       launch_cb=launch_callback,
                                       screen=screen)
    except SpawnError:
        raise
    return True
Exemplo n.º 2
0
Arquivo: launch.py Projeto: pbx/kupfer
 def application_to_front(self, app_id):
     application_windows = self.get_application_windows(app_id)
     if not application_windows:
         return False
     etime = uievents.current_event_time()
     # if True, focus app's all windows on the same workspace
     # if False, focus only one window (in cyclical manner)
     focus_all = True
     if focus_all:
         return self._to_front_application_style(application_windows, etime)
     else:
         return self._to_front_single(application_windows, etime)
Exemplo n.º 3
0
 def application_to_front(self, app_id):
     application_windows = self.get_application_windows(app_id)
     if not application_windows:
         return False
     etime = uievents.current_event_time()
     # if True, focus app's all windows on the same workspace
     # if False, focus only one window (in cyclical manner)
     focus_all = True
     if focus_all:
         return self._to_front_application_style(application_windows, etime)
     else:
         return self._to_front_single(application_windows, etime)
Exemplo n.º 4
0
Arquivo: launch.py Projeto: pbx/kupfer
def launch_application(app_info, files=(), uris=(), paths=(), track=True,
                       activate=True, desktop_file=None, screen=None):
    """
    Launch @app_rec correctly, using a startup notification

    you may pass in either a list of gio.Files in @files, or 
    a list of @uris or @paths

    if @track, it is a user-level application
    if @activate, activate rather than start a new version

    @app_rec is either an GAppInfo or (GAppInfo, desktop_file_path) tuple

    Raises SpawnError on failed program start.
    """
    assert app_info

    if paths:
        files = [gio.File(p) for p in paths]
    if uris:
        files = [gio.File(p) for p in uris]

    svc = GetApplicationsMatcherService()
    app_id = application_id(app_info, desktop_file)

    if activate and svc.application_is_running(app_id):
        svc.application_to_front(app_id)
        return True

 # An launch callback closure for the @app_id
    def application_launch_callback(argv, pid, notify_id, files, timestamp):
        is_terminal = terminal.is_known_terminal_executable(argv[0])
        if not is_terminal:
            svc.launched_application(app_id, pid)

    if track:
        launch_callback = application_launch_callback
    else:
        launch_callback = None

    try:
        desktop_launch.launch_app_info(app_info, files,
               timestamp=uievents.current_event_time(),
               desktop_file=desktop_file,
               launch_cb=launch_callback,
               screen=screen)
    except SpawnError:
        raise
    return True
Exemplo n.º 5
0
def show_text_result(text, title=None, ctx=None):
	"""
	Show @text in a result window.

	Use @title to set a window title
	"""
	class ResultWindowBehavior (object):
		def on_text_result_window_key_press_event(self, widget, event, names):
			return _window_destroy_on_escape(widget, event)

		def on_close_button_clicked(self, widget, names):
			names.text_result_window.window.destroy()
			return True
		def on_copy_button_clicked(self, widget, names):
			clip = gtk.clipboard_get(gtk.gdk.SELECTION_CLIPBOARD)
			textview = names.result_textview
			buf = textview.get_buffer()
			buf.select_range(*buf.get_bounds())
			buf.copy_clipboard(clip)

	window, textview = builder_get_objects_from_file("result.ui",
			("text_result_window", "result_textview"),
			autoconnect_to=ResultWindowBehavior())


	# Set up text buffer
	buf = gtk.TextBuffer()
	buf.set_text(text)
	monospace = gtk.TextTag("fixed")
	monospace.set_property("family", "Monospace")
	monospace.set_property("scale", pango.SCALE_LARGE)
	beg, end = buf.get_bounds()
	tag_table = buf.get_tag_table()
	tag_table.add(monospace)
	buf.apply_tag(monospace, beg, end)

	textview.set_buffer(buf)
	textview.set_wrap_mode(gtk.WRAP_NONE)

	if title:
		window.set_title(title)

	if ctx:
		ctx.environment.present_window(window)

	window.show_all()

	# Fix Sizing:
	# We want to size the window so that the
	# TextView is displayed without scrollbars
	# initially, if it fits on screen.
	oldwid, oldhei = textview.window.get_size()
	winwid, winhei = window.get_size()

	max_hsize, max_vsize = window.get_default_size()
	wid, hei = textview.size_request()
	textview.set_wrap_mode(gtk.WRAP_WORD)

	vsize = int(min(hei + (winhei - oldhei) + 5, max_vsize))
	hsize = int(min(wid + (winwid - oldwid) + 5, max_hsize))

	window.resize(hsize, vsize)
	if ctx:
		ctx.environment.present_window(window)
	else:
		window.present_with_time(uievents.current_event_time())
Exemplo n.º 6
0
def show_large_type(text, ctx=None):
	"""
	Show @text, large, in a result window.
	"""
	import math

	text = text.strip()
	window = gtk.Window()
	label = gtk.Label()
	label.set_text(text)

	def set_font_size(label, fontsize=48.0):
		siz_attr = pango.AttrFontDesc(
				pango.FontDescription (str(fontsize)), 0, -1)
		attrs = pango.AttrList()
		attrs.insert(siz_attr)
		label.set_attributes(attrs)
	label.show()

	size = 72.0
	set_font_size(label, size)

	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
	# hard-wrap the text
	if ((wid > maxwid or hei > maxhei) and
			any(len(L) > 100 for L in text.splitlines())):
		label.set_text(_wrap_paragraphs(text))

	wid, hei = label.size_request()

	if wid > maxwid or hei > maxhei:
		# Round size down to fit inside
		wscale = maxwid * 1.0/wid
		hscale = maxhei * 1.0/hei
		set_font_size(label, math.floor(min(wscale, hscale)*size) or 1.0)

	window.add(label)
	window.set_position(gtk.WIN_POS_CENTER)
	window.set_resizable(False)
	window.set_decorated(False)
	window.set_property("border-width", 10)
	window.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("black"))
	label.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse("white"))

	def _window_destroy(widget, event):
		widget.destroy()
		return True
	window.connect("key-press-event", _window_destroy)
	window.show_all()
	if ctx:
		ctx.environment.present_window(window)
	else:
		window.present_with_time(uievents.current_event_time())
Exemplo n.º 7
0
 def application_close_all(self, app_id):
     application_windows = self.get_application_windows(app_id)
     evttime = uievents.current_event_time()
     for w in application_windows:
         if not w.is_skip_tasklist():
             w.close(evttime)
Exemplo n.º 8
0
def show_text_result(text, title=None, ctx=None):
    """
    Show @text in a result window.

    Use @title to set a window title
    """
    class ResultWindowBehavior(object):
        def __init__(self):
            self.names = None

        def on_text_result_window_key_press_event(self, widget, event):
            return _window_close_on_escape(widget, event)

        def on_close_button_clicked(self, widget):
            self.names.text_result_window.close()
            return True

        def on_copy_button_clicked(self, widget):
            clip = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
            textview = self.names.result_textview
            buf = textview.get_buffer()
            buf.select_range(*buf.get_bounds())
            buf.copy_clipboard(clip)

    window, textview = builder_get_objects_from_file(
        "result.ui", ("text_result_window", "result_textview"),
        autoconnect_to=ResultWindowBehavior())

    # Set up text buffer
    buf = Gtk.TextBuffer()
    buf.set_text(text)
    textview.set_buffer(buf)
    textview.set_wrap_mode(Gtk.WrapMode.NONE)
    textview.set_editable(True)

    if title:
        window.set_title(title)

    if ctx:
        ctx.environment.present_window(window)

    window.show_all()

    # Find the size of one (monospace) letter
    playout = textview.create_pango_layout("X")
    ink_r, logical_r = playout.get_pixel_extents()

    # Fix Sizing:
    # We want to size the window so that the
    # TextView is displayed without scrollbars
    # initially, if it fits on screen.
    tw_sr = textview.get_size_request()
    oldwid, oldhei = tw_sr.width, tw_sr.height
    winwid, winhei = window.get_size()

    #max_hsize, max_vsize = window.get_default_size()
    tw_sr = textview.size_request()
    wid, hei = tw_sr.width, tw_sr.height
    textview.set_wrap_mode(Gtk.WrapMode.WORD)

    # Set max window size to 100 colums x 60 lines
    max_hsize = ink_r.height * 60
    max_vsize = ink_r.width * 100

    vsize = int(min(hei + (winhei - oldhei) + 5, max_vsize))
    hsize = int(min(wid + (winwid - oldwid) + 5, max_hsize))

    window.resize(hsize, vsize)
    if ctx:
        ctx.environment.present_window(window)
    else:
        window.present_with_time(uievents.current_event_time())
Exemplo n.º 9
0
def show_large_type(text, ctx=None):
    """
    Show @text, large, in a result window.
    """
    import math

    text = text.strip()
    window = Gtk.Window()
    label = Gtk.Label()
    label.set_text(text)

    def set_font_size(label, fontsize=48.0):
        siz_attr = Pango.AttrFontDesc(
            Pango.FontDescription.from_string(str(fontsize)), 0, -1)
        attrs = Pango.AttrList()
        attrs.insert(siz_attr)
        label.set_attributes(attrs)

    label.show()

    size = 72.0
    #set_font_size(label, size)

    if ctx:
        screen = ctx.environment.get_screen()
        window.set_screen(screen)
    else:
        screen = 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
    # hard-wrap the text
    if ((wid > maxwid or hei > maxhei)
            and any(len(L) > 100 for L in text.splitlines())):
        label.set_text(_wrap_paragraphs(text))

    wid, hei = label.size_request()

    if wid > maxwid or hei > maxhei:
        # Round size down to fit inside
        wscale = maxwid * 1.0 / wid
        hscale = maxhei * 1.0 / hei
        set_font_size(label, math.floor(min(wscale, hscale) * size) or 1.0)

    window.add(label)
    window.set_position(Gtk.WindowPosition.CENTER)
    window.set_resizable(False)
    window.set_decorated(False)
    window.set_property("border-width", 10)
    window.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("black"))
    label.modify_fg(Gtk.StateType.NORMAL, Gdk.color_parse("white"))

    def _window_destroy(widget, event):
        widget.destroy()
        return True

    window.connect("key-press-event", _window_destroy)
    window.show_all()
    if ctx:
        ctx.environment.present_window(window)
    else:
        window.present_with_time(uievents.current_event_time())
Exemplo n.º 10
0
Arquivo: launch.py Projeto: pbx/kupfer
 def application_close_all(self, app_id):
     application_windows = self.get_application_windows(app_id)
     evttime = uievents.current_event_time()
     for w in application_windows:
         if not w.is_skip_tasklist():
             w.close(evttime)
Exemplo n.º 11
0
def show_text_result(text, title=None, ctx=None):
    """
	Show @text in a result window.

	Use @title to set a window title
	"""
    class ResultWindowBehavior(object):
        def on_text_result_window_key_press_event(self, widget, event, names):
            return _window_destroy_on_escape(widget, event)

        def on_close_button_clicked(self, widget, names):
            names.text_result_window.window.destroy()
            return True

        def on_copy_button_clicked(self, widget, names):
            clip = gtk.clipboard_get(gtk.gdk.SELECTION_CLIPBOARD)
            textview = names.result_textview
            buf = textview.get_buffer()
            buf.select_range(*buf.get_bounds())
            buf.copy_clipboard(clip)

    window, textview = builder_get_objects_from_file(
        "result.ui", ("text_result_window", "result_textview"),
        autoconnect_to=ResultWindowBehavior())

    # Set up text buffer
    buf = gtk.TextBuffer()
    buf.set_text(text)
    monospace = gtk.TextTag("fixed")
    monospace.set_property("family", "Monospace")
    monospace.set_property("scale", pango.SCALE_LARGE)
    beg, end = buf.get_bounds()
    tag_table = buf.get_tag_table()
    tag_table.add(monospace)
    buf.apply_tag(monospace, beg, end)

    textview.set_buffer(buf)
    textview.set_wrap_mode(gtk.WRAP_NONE)

    if title:
        window.set_title(title)

    if ctx:
        ctx.environment.present_window(window)

    window.show_all()

    # Fix Sizing:
    # We want to size the window so that the
    # TextView is displayed without scrollbars
    # initially, if it fits on screen.
    oldwid, oldhei = textview.window.get_size()
    winwid, winhei = window.get_size()

    max_hsize, max_vsize = window.get_default_size()
    wid, hei = textview.size_request()
    textview.set_wrap_mode(gtk.WRAP_WORD)

    vsize = int(min(hei + (winhei - oldhei) + 5, max_vsize))
    hsize = int(min(wid + (winwid - oldwid) + 5, max_hsize))

    window.resize(hsize, vsize)
    if ctx:
        ctx.environment.present_window(window)
    else:
        window.present_with_time(uievents.current_event_time())