/usr/share/pyshared/sqlkit/layout/misc.py is in python-sqlkit 0.9.5-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | import os
import sys
import gtk
from sqlkit import _
### utility: stock icons
SK_ICONS = (
('cal15.png', 'sk-calendar'),
('keys.png', 'sk-pkeys'),
('table-load.png', 'sk-table-load'),
)
def add_stock_icons(*icon_list):
factory = gtk.IconFactory()
for icon_file, stock_id in icon_list:
if os.path.exists(icon_file):
filename = icon_file
else:
filename = os.path.join(os.path.dirname(__file__), icon_file)
if not os.path.exists(filename):
filename = os.path.join(os.path.dirname(sys.executable), icon_file)
pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
iconset = gtk.IconSet(pixbuf)
factory.add(stock_id, iconset)
factory.add_default()
add_stock_icons(*SK_ICONS)
class StockMenuItem(gtk.ImageMenuItem):
def __init__(self, label, stock, size=gtk.ICON_SIZE_MENU):
gtk.ImageMenuItem.__init__(self, label)
image = gtk.Image()
image.set_from_stock(stock, size)
self.set_image(image)
self.show_all()
class EasyTreeView(object):
def __init__(self, cols, tv=None, model=None, sort=True,
resize=True, show=True, but='', title='EasyTreeView'):
if tv:
self.tv = tv
else:
self.l = self._get_layout(but, title=title)
self.l.prop('Window', 'visible', show)
self.w = self.l.show()
self.tv = self.w['TV=a']
self.l.connect(
('tb=gtk-quit', 'clicked', lambda l: self.w['Window'].destroy()),
)
self.columns = []
self.column_names = []
for col in cols:
if isinstance(col, str):
self.column_names += [col]
self.columns += [str]
if isinstance(col, tuple):
# the second position is for type
self.column_names += [col[0]]
self.columns += [col[1]]
if not model:
self.model = gtk.TreeStore(*self.columns)
else:
self.model = model
self.tv.set_enable_search(True)
self.tv.set_model(self.model)
self.tvc = {}
for i, col in enumerate(self.column_names):
cell = gtk.CellRendererText
if self.columns[i] == bool:
cell = gtk.CellRendererToggle
self.tvc[col] = gtk.TreeViewColumn(_(col), cell(), active=i)
else:
self.tvc[col] = gtk.TreeViewColumn(_(col), cell(), text=i)
if sort == True:
self.tvc[col].set_sort_column_id(i)
self.tvc[col].set_resizable(resize)
self.tv.append_column(self.tvc[col])
def show(self):
self.w['Window'].show_all()
def hide(self):
self.w['Window'].hide()
def _get_layout(self, but, title=None):
from sqlkit import layout
lay = """
{O tb=gtk-quit tb=gtk-clear %s}
TVS=a
""" % (but)
#dbg.write()
return layout.Layout(lay, opts="s", title=title)
class InputStream(object):
""" Simple Wrapper for File-like objects. [c]StringIO doesn't provide
a readline function for use with generate_tokens.
Using a iterator-like interface doesn't succeed, because the readline
function isn't used in such a context. (see <python-lib>/tokenize.py)
"""
def __init__(self, data):
self.__data = [ '%s\n' % x for x in data.splitlines() ]
self.__lcount = 0
def readline(self):
try:
line = self.__data[self.__lcount]
self.__lcount += 1
except IndexError:
line = ''
self.__lcount = 0
return line
|