aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorGravatar Mason Larobina <mason.larobina@gmail.com>2009-09-07 20:01:42 +0800
committerGravatar Mason Larobina <mason.larobina@gmail.com>2009-09-07 20:01:42 +0800
commita2e0e583fdd524a8865847555816d15175333e0c (patch)
tree697fc89190fd75f8345277f1eb2b8e2cd402f87c /examples
parent16a17e589de1698929707abce828a9e8354b2b08 (diff)
Fixed wonky patch & added in gtk_refresh option.
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/data/uzbl/scripts/uzbl_tabbed.py87
1 files changed, 53 insertions, 34 deletions
diff --git a/examples/data/uzbl/scripts/uzbl_tabbed.py b/examples/data/uzbl/scripts/uzbl_tabbed.py
index 40e03e5..f04b677 100755
--- a/examples/data/uzbl/scripts/uzbl_tabbed.py
+++ b/examples/data/uzbl/scripts/uzbl_tabbed.py
@@ -67,6 +67,7 @@
# show_gtk_tabs = 0
# tablist_top = 1
# gtk_tab_pos = (top|left|bottom|right)
+# gtk_refresh = 1000
# switch_to_new_tabs = 1
# capture_new_windows = 1
# multiline_tabs = 1
@@ -169,6 +170,7 @@ import socket
import random
import hashlib
import atexit
+import types
from gobject import io_add_watch, source_remove, timeout_add, IO_IN, IO_HUP
from signal import signal, SIGTERM, SIGINT
@@ -212,14 +214,15 @@ if not os.path.exists(UZBL_CONFIG):
# All of these settings can be inherited from your uzbl config file.
config = {
- 'multiline_tabs': True, # tabs wrap to the window
# Tab options
'show_tablist': True, # Show text uzbl like statusbar tab-list
'show_gtk_tabs': False, # Show gtk notebook tabs
'tablist_top': True, # Display tab-list at top of window
'gtk_tab_pos': 'top', # Gtk tab position (top|left|bottom|right)
+ 'gtk_refresh': 1000, # Tablist refresh millisecond interval
'switch_to_new_tabs': True, # Upon opening a new tab switch to it
'capture_new_windows': True, # Use uzbl_tabbed to catch new windows
+ 'multiline_tabs': True, # Tabs overflow onto new tablist lines.
# Tab title options
'tab_titles': True, # Display tab titles (else only tab-nums)
@@ -609,15 +612,17 @@ class UzblTabbed:
if not len(self.tabs):
self.new_tab()
+ gtk_refresh = int(config['gtk_refresh'])
+ if gtk_refresh < 100:
+ gtk_refresh = 100
+
# Update tablist timer
- #timer = "update-tablist"
- #timerid = timeout_add(500, self.update_tablist,timer)
- #self._timers[timer] = timerid
+ timerid = timeout_add(gtk_refresh, self.update_tablist)
+ self._timers["update-tablist"] = timerid
# Probe clients every second for window titles and location
- timer = "probe-clients"
- timerid = timeout_add(1000, self.probe_clients, timer)
- self._timers[timer] = timerid
+ timerid = timeout_add(gtk_refresh, self.probe_clients)
+ self._timers["probe-clients"] = timerid
# Make SIGTERM act orderly.
signal(SIGTERM, lambda signum, stack_frame: self.terminate(SIGTERM))
@@ -761,7 +766,7 @@ class UzblTabbed:
return True
- def probe_clients(self, timer_call):
+ def probe_clients(self):
'''Probe all uzbl clients for up-to-date window titles and uri's.'''
save_session = config['save_session']
@@ -1153,7 +1158,6 @@ class UzblTabbed:
return True
- pangols = []
def update_tablist(self, curpage=None):
'''Upate tablist status bar.'''
@@ -1161,6 +1165,11 @@ class UzblTabbed:
show_gtk_tabs = config['show_gtk_tabs']
tab_titles = config['tab_titles']
show_ellipsis = config['show_ellipsis']
+ multiline_tabs = config['multiline_tabs']
+
+ if multiline_tabs:
+ multiline = []
+
if not show_tablist and not show_gtk_tabs:
return True
@@ -1175,12 +1184,10 @@ class UzblTabbed:
pango = ""
normal = (config['tab_colours'], config['tab_text_colours'])
selected = (config['selected_tab'], config['selected_tab_text'])
- if tab_titles:
- # ok this kinda shits itself when it truncates multibyte utf8
- # characters so heres a cheap fix:
- tabtitle = unicode(tabtitle,"utf-8", "ignore").encode('utf-8')
+ if tab_titles:
tab_format = "<span %s> [ %d <span %s> %s</span> ] </span>"
+
else:
tab_format = "<span %s> [ <span %s>%d</span> ] </span>"
@@ -1194,14 +1201,22 @@ class UzblTabbed:
if index == curpage:
self.window.set_title(title_format % uzbl.title)
- tabtitle = uzbl.title[:max_title_len]
+ # Unicode heavy strings do not like being truncated/sliced so by
+ # re-encoding the string sliced of limbs are removed.
+ tabtitle = uzbl.title[:max_title_len + int(show_ellipsis)]
+ if type(tabtitle) != types.UnicodeType:
+ tabtitle = unicode(tabtitle, 'utf-8', 'ignore')
+
+ tabtitle = tabtitle.encode('utf-8', 'ignore').strip()
+
if show_ellipsis and len(tabtitle) != len(uzbl.title):
- tabtitle = "%s\xe2\x80\xa6" % tabtitle[:-1] # Show Ellipsis
+ tabtitle += "\xe2\x80\xa6"
if show_gtk_tabs:
if tab_titles:
- self.notebook.set_tab_label_text(tab,\
+ self.notebook.set_tab_label_text(tab,
gtk_tab_format % (index, tabtitle))
+
else:
self.notebook.set_tab_label_text(tab, str(index))
@@ -1209,33 +1224,37 @@ class UzblTabbed:
style = colour_selector(index, curpage, uzbl)
(tabc, textc) = style
- if config['multiline_tabs']:
+ if multiline_tabs:
opango = pango
if tab_titles:
- pango += tab_format % (tabc, index, textc,\
- escape(tabtitle))
+ pango += tab_format % (tabc, index, textc,
+ escape(tabtitle))
+
else:
pango += tab_format % (tabc, textc, index)
+
self.tablist.set_markup(pango)
- w = self.tablist.get_layout().get_pixel_size()[0]
- ww = self.window.get_size()[0]
- if w > ww-20: # 20 seems to be a good number
- pangols.append(opango)
- pango = tab_format % (tabc, index, textc,\
- escape(tabtitle))
- else:
- if tab_titles:
- pango += tab_format % (tabc, index, textc,\
- escape(tabtitle))
- else:
- pango += tab_format % (tabc, textc, index)
+ listwidth = self.tablist.get_layout().get_pixel_size()[0]
+ winwidth = self.window.get_size()[0]
+
+ if listwidth > (winwidth - 20):
+ multiline.append(opango)
+ pango = tab_format % (tabc, index, textc,
+ escape(tabtitle))
+ elif tab_titles:
+ pango += tab_format % (tabc, index, textc,
+ escape(tabtitle))
+
+ else:
+ pango += tab_format % (tabc, textc, index)
if show_tablist:
- if config['multiline_tabs']:
- pangols.append(pango)
- self.tablist.set_markup('&#10;'.join(pangols))
+ if multiline_tabs:
+ multiline.append(pango)
+ self.tablist.set_markup('&#10;'.join(multiline))
+
else:
self.tablist.set_markup(pango)