forked from dalanicolai/gnome-tracker-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappchooser.py
executable file
·52 lines (33 loc) · 1.17 KB
/
appchooser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
# This script takes one filename as argument and opens a openwith gtk window
import sys
import os
import subprocess
import mimetypes
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk
#home = os.getenv("HOME")
class myWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Open with")
self.set_icon_from_file('/usr/share/icons/hicolor/scalable/apps/ulauncher.svg')
self.connect("key-press-event", self.on_key_press)
def on_key_press(self, window, event):
print(event.keyval)
if event.keyval == Gdk.KEY_Escape:
Gtk.main_quit()
def application_activated(appchooserwidget, desktopappinfo):
app_info = appchooserwidget.get_app_info()
exe = app_info.get_executable()
subprocess.Popen([exe,filename])
Gtk.main_quit()
filename = sys.argv[1]
mime = mimetypes.guess_type(filename)[0]
window = myWindow()
window.connect("destroy", Gtk.main_quit)
appchooserwidget = Gtk.AppChooserWidget(content_type=mime)
appchooserwidget.connect("application-activated", application_activated)
window.add(appchooserwidget)
window.show_all()
Gtk.main()