tidy up the imports, move the graphical error to a generic gerr() function in util.py and add a function for injecting URL regexps
This commit is contained in:
parent
28a5b963f0
commit
1e12ece0ea
|
@ -10,31 +10,85 @@ import gobject
|
||||||
import gtk
|
import gtk
|
||||||
import pango
|
import pango
|
||||||
|
|
||||||
|
from cwd import get_pid_cwd, get_default_cwd
|
||||||
|
from util import dbg, err, gerr
|
||||||
|
from config import Config
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import vte
|
import vte
|
||||||
except ImportError:
|
except ImportError:
|
||||||
ERROR = gtk.MessageDialog(None,
|
gerr('You need to install python bindings for libvte')
|
||||||
gtk.DIALOG_MODAL,
|
|
||||||
gtk.MESSAGE_ERROR,
|
|
||||||
gtk.BUTTONS_OK,
|
|
||||||
'You need to install python bindings for libvte')
|
|
||||||
ERROR.run()
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
from cwd import get_pid_cwd, get_default_cwd
|
|
||||||
|
|
||||||
class Terminal(gtk.VBox):
|
class Terminal(gtk.VBox):
|
||||||
"""Class implementing the VTE widget and its wrappings"""
|
"""Class implementing the VTE widget and its wrappings"""
|
||||||
|
|
||||||
vte = None
|
vte = None
|
||||||
|
matches = None
|
||||||
|
config = None
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""Class initialiser"""
|
"""Class initialiser"""
|
||||||
gtk.VBox.__init__(self)
|
gtk.VBox.__init__(self)
|
||||||
|
self.matches = {}
|
||||||
|
|
||||||
|
self.config = Config()
|
||||||
|
|
||||||
self.vte = vte.Terminal()
|
self.vte = vte.Terminal()
|
||||||
self.vte.set_size(80, 24)
|
self.vte.set_size(80, 24)
|
||||||
self.vte._expose_data = None
|
self.vte._expose_data = None
|
||||||
self.vte.show()
|
self.vte.show()
|
||||||
|
|
||||||
|
self.update_url_matches(self.config['try_posix_regexp'])
|
||||||
|
|
||||||
|
def update_url_matches(self, posix = True):
|
||||||
|
"""Update the regexps used to match URLs"""
|
||||||
|
userchars = "-A-Za-z0-9"
|
||||||
|
passchars = "-A-Za-z0-9,?;.:/!%$^*&~\"#'"
|
||||||
|
hostchars = "-A-Za-z0-9"
|
||||||
|
pathchars = "-A-Za-z0-9_$.+!*(),;:@&=?/~#%'\""
|
||||||
|
schemes = "(news:|telnet:|nntp:|file:/|https?:|ftps?:|webcal:)"
|
||||||
|
user = "[" + userchars + "]+(:[" + passchars + "]+)?"
|
||||||
|
urlpath = "/[" + pathchars + "]*[^]'.}>) \t\r\n,\\\"]"
|
||||||
|
|
||||||
|
if posix:
|
||||||
|
dbg ('update_url_matches: Trying POSIX URL regexps. Set \
|
||||||
|
try_posix_regexp = False in config to only try GNU \
|
||||||
|
if you get (harmless) VTE warnings.')
|
||||||
|
lboundry = "[[:<:]]"
|
||||||
|
rboundry = "[[:>:]]"
|
||||||
|
else: # GNU
|
||||||
|
dbg ('update_url_matches: Trying GNU URL regexps. Set \
|
||||||
|
try_posix_regexp = True in config if URLs are not \
|
||||||
|
detected.')
|
||||||
|
lboundry = "\\<"
|
||||||
|
rboundry = "\\>"
|
||||||
|
|
||||||
|
self.matches['full_uri'] = self._vte.match_add(lboundry + schemes +
|
||||||
|
"//(" + user + "@)?[" + hostchars +".]+(:[0-9]+)?(" +
|
||||||
|
urlpath + ")?" + rboundry + "/?")
|
||||||
|
|
||||||
|
if self.matches['full_uri'] == -1:
|
||||||
|
if posix:
|
||||||
|
err ('update_url_matches: POSIX match failed, trying GNU')
|
||||||
|
self.update_url_matches(posix = False)
|
||||||
|
else:
|
||||||
|
err ('update_url_matches: Failed adding URL match patterns')
|
||||||
|
else:
|
||||||
|
self.matches['voip'] = self._vte.match_add(lboundry +
|
||||||
|
'(callto:|h323:|sip:)' + "[" + userchars + "+][" +
|
||||||
|
userchars + ".]*(:[0-9]+)?@?[" + pathchars + "]+" +
|
||||||
|
rboundry)
|
||||||
|
self.matches['addr_only'] = self._vte.match_add (lboundry +
|
||||||
|
"(www|ftp)[" + hostchars + "]*\.[" + hostchars +
|
||||||
|
".]+(:[0-9]+)?(" + urlpath + ")?" + rboundry + "/?")
|
||||||
|
self.matches['email'] = self._vte.match_add (lboundry +
|
||||||
|
"(mailto:)?[a-zA-Z0-9][a-zA-Z0-9.+-]*@[a-zA-Z0-9][a-zA-Z0-9-]*\.[a-zA-Z0-9][a-zA-Z0-9-]+[.a-zA-Z0-9-]*" + rboundry)
|
||||||
|
self.matches['nntp'] = self._vte.match_add (lboundry +
|
||||||
|
'''news:[-A-Z\^_a-z{|}~!"#$%&'()*+,./0-9;:=?`]+@[-A-Za-z0-9.]+(:[0-9]+)?''' + rboundry)
|
||||||
|
# if the url looks like a Launchpad changelog closure entry
|
||||||
|
# LP: #92953 - make it a url to http://bugs.launchpad.net
|
||||||
|
self.matches['launchpad'] = self._vte.match_add (
|
||||||
|
'\\bLP:? #?[0-9]+\\b')
|
||||||
|
|
||||||
# vim: set expandtab ts=4 sw=4:
|
# vim: set expandtab ts=4 sw=4:
|
||||||
|
|
Loading…
Reference in New Issue