open external urls in browser
This commit is contained in:
parent
a400afc923
commit
13e360ac97
2 changed files with 14 additions and 0 deletions
|
@ -2,6 +2,7 @@
|
||||||
import os
|
import os
|
||||||
from os.path import dirname, abspath
|
from os.path import dirname, abspath
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import webbrowser
|
||||||
|
|
||||||
import gi
|
import gi
|
||||||
gi.require_version('WebKit2', '4.0')
|
gi.require_version('WebKit2', '4.0')
|
||||||
|
@ -21,6 +22,14 @@ def on_key_press_event(widget, event):
|
||||||
if event.state & Gdk.ModifierType.CONTROL_MASK and event.keyval == 113:
|
if event.state & Gdk.ModifierType.CONTROL_MASK and event.keyval == 113:
|
||||||
Gtk.main_quit()
|
Gtk.main_quit()
|
||||||
|
|
||||||
|
def on_decide_policy(view, decision, dtype):
|
||||||
|
uri = decision.get_request().get_uri()
|
||||||
|
if uri.startswith("http") and not '127.0.0.1' in uri:
|
||||||
|
decision.ignore()
|
||||||
|
webbrowser.open_new(uri)
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
wnd = Gtk.Window()
|
wnd = Gtk.Window()
|
||||||
|
|
||||||
wnd.set_icon_from_file(icon)
|
wnd.set_icon_from_file(icon)
|
||||||
|
@ -35,6 +44,8 @@ wnd.connect('key_press_event', on_key_press_event)
|
||||||
wnd.add(web)
|
wnd.add(web)
|
||||||
wnd.show_all()
|
wnd.show_all()
|
||||||
|
|
||||||
|
web.connect("decide-policy", on_decide_policy)
|
||||||
|
|
||||||
url = 'file://' + base + '/openmedialibrary/static/html/load.html'
|
url = 'file://' + base + '/openmedialibrary/static/html/load.html'
|
||||||
web.load_uri(url)
|
web.load_uri(url)
|
||||||
|
|
||||||
|
|
|
@ -531,6 +531,9 @@ class File(db.Model):
|
||||||
j = self.item.json()
|
j = self.item.json()
|
||||||
|
|
||||||
current_path = self.fullpath()
|
current_path = self.fullpath()
|
||||||
|
if not os.path.exists(current_path):
|
||||||
|
logger.debug('file is missing. %s', current_path)
|
||||||
|
return
|
||||||
author = '; '.join([ox.canonical_name(a) for a in j.get('author', [])])
|
author = '; '.join([ox.canonical_name(a) for a in j.get('author', [])])
|
||||||
if not author:
|
if not author:
|
||||||
author = 'Unknown Author'
|
author = 'Unknown Author'
|
||||||
|
|
Loading…
Reference in a new issue