def refreshTree(self):
folderIcon = gtk.Image().render_icon(gtk.STOCK_DIRECTORY, gtk.ICON_SIZE_MENU)
fileIcon = gtk.Image().render_icon(gtk.STOCK_FILE, gtk.ICON_SIZE_MENU)
def load(dic, parent=None):
for i, j in dic.items():
isFile = j[0]
if isFile:
self.treeStore.append(parent, [fileIcon, i, True])
else:
p = self.treeStore.append(parent, [folderIcon, i, False])
load(j[1], p)
self.treeStore.clear()
load(self.files)
python类STOCK_FILE的实例源码
def get_for_file(self, fname):
mime = gio.content_type_guess(fname)
if mime:
icon_name = gio.content_type_get_icon(mime)
icon = self.theme.choose_icon(icon_name.get_names(), 16, 0)
if icon:
return gtk.IconInfo.load_icon(icon)
else:
name = gtk.STOCK_FILE
else:
name = gtk.STOCK_FILE
return self.theme.load_icon(name, 16, 0)
# TODO expand for other devices
def _load_icons():
'''
Load icons for the plugin from 'ICONS_DIRECTORY' folder (files with png format).
Icons are stored as dict: {'name': 'icon'}, where icon is a name of the icon in the factory (or gtk).
For example an icon with name 'name' will have an icon file 'name.png'
in this folder or a 'NO_IMAGE' icon if it is not available.
'''
# Use IconFactory to get the same size for all icons.
factory = gtk.IconFactory()
factory.add_default()
icons = {
NO_IMAGE: gtk.STOCK_MISSING_IMAGE, # icon has no image
SEVERAL_ICONS: gtk.STOCK_DIALOG_QUESTION, # not clear what icon to use
# Icons below can be overwritten if there is a certain file in the 'ICONS_DIRECTORY'.
'apply': gtk.STOCK_APPLY, # additional GTK icon
#'info': gtk.STOCK_INFO, # additional GTK icon
FOLDER_ICON: gtk.STOCK_DIRECTORY, # for pages with children
FOLDER_TAGS_ICON: gtk.STOCK_DIRECTORY, # for pages with children and with tags
FILE_ICON: gtk.STOCK_FILE, # for ordinary pages
FILE_TAGS_ICON: gtk.STOCK_FILE # for ordinary pages with tags
}
# Icons from directory.
dir = data_dir(ICONS_DIRECTORY)
counter = 0 # to count number of loaded icons
if dir:
for file in dir.list('*.png'):
# not all installs have svg support, so only check png for now..
name = file[:-4].lower() # e.g. 'calendar.png' -> 'calendar'
icon_name = 'p_Icon_' + name # e.g. 'Calendar' -> 'p_Icon_calendar'
try:
pixbuf = gtk.gdk.pixbuf_new_from_file(str(dir+file))
icon = gtk.IconSet(pixbuf)
factory.add(icon_name, icon)
icons[name] = icon_name
counter += 1
except:
logger.error('IconTags: Error while loading icons.')
logger.debug('IconTags: {} icons loaded from: {}'.format(counter, dir.path))
else:
logger.debug('''IconTags: Folder with icons doesn't exist.''')
return icons
def _load_icons():
'''
Load icons for the plugin from 'ICONS_DIRECTORY' folder (files with png format).
Icons are stored as dict: {'name': 'icon'}, where icon is a name of the icon in the factory (or gtk).
For example an icon with name 'name' will have an icon file 'name.png'
in this folder or a 'NO_IMAGE' icon if it is not available.
'''
# Use IconFactory to get the same size for all icons.
factory = gtk.IconFactory()
factory.add_default()
icons = {
NO_IMAGE: gtk.STOCK_MISSING_IMAGE, # icon has no image
SEVERAL_ICONS: gtk.STOCK_DIALOG_QUESTION, # not clear what icon to use
# Icons below can be overwritten if there is a certain file in the 'ICONS_DIRECTORY'.
'apply': gtk.STOCK_APPLY, # additional GTK icon
#'info': gtk.STOCK_INFO, # additional GTK icon
FOLDER_ICON: gtk.STOCK_DIRECTORY, # for pages with children
FOLDER_TAGS_ICON: gtk.STOCK_DIRECTORY, # for pages with children and with tags
FILE_ICON: gtk.STOCK_FILE, # for ordinary pages
FILE_TAGS_ICON: gtk.STOCK_FILE # for ordinary pages with tags
}
# Icons from directory.
dir = data_dir(ICONS_DIRECTORY)
counter = 0 # to count number of loaded icons
if dir:
for file in dir.list('*.png'):
# not all installs have svg support, so only check png for now..
name = file[:-4].lower() # e.g. 'calendar.png' -> 'calendar'
icon_name = 'p_Icon_' + name # e.g. 'Calendar' -> 'p_Icon_calendar'
try:
pixbuf = gtk.gdk.pixbuf_new_from_file(str(dir+file))
icon = gtk.IconSet(pixbuf)
factory.add(icon_name, icon)
icons[name] = icon_name
counter += 1
except:
logger.error('IconTags: Error while loading icons.')
logger.debug('IconTags: {} icons loaded from: {}'.format(counter, dir.path))
else:
logger.debug('''IconTags: Folder with icons doesn't exist.''')
return icons
def do_search(self, query, event_flag):
def get_icon(n):
if n not in self.parser.members: # no check for undeclared class
icon = gtk.STOCK_DELETE
elif '(' in n:
icon = gtk.STOCK_EXECUTE
elif ':' in n:
icon = gtk.STOCK_SELECT_FONT
else:
icon = gtk.STOCK_FILE
return icon
def append_row(parent, names, depth, call_info):
name = names[0]
call_info_str = call_info.select_from_call_types(u'?????') \
.replace(u'??', u'?') \
.replace(u'??', u'?')
it = self.store.append(parent, (
name, # class/method/field name
get_icon(name), # icon
'b' if name in toplevel else '',
# bold (in root) or not
call_info_str
))
# Append children
d = depth + 1
if d >= self._max_tree_depth:
self.store.append(it, (' ...maximum depth (%d) reached' %
self._max_tree_depth, gtk.STOCK_INFO, 'i',
call_info_str))
return
for caller, info in self.parser.callers.get(name, {}).items():
if event_flag.is_set(): # stopped earlier
return
if caller not in names:
names.appendleft(caller)
append_row(it, names, d, info)
names.popleft()
else:
self.store.append(it, (' ...recursive ' + caller,
gtk.STOCK_INFO, 'i', call_info_str))
with self.search_lock:
gobject.idle_add(self.treeview.set_model, None)
toplevel = set()
self.store.clear()
for k in self.parser.callers:
if fnmatch.fnmatch(k, query):
toplevel.add(k)
for i in toplevel:
append_row(None, collections.deque((i,)), 0, CallInfo())
# Finalization
if not event_flag.is_set():
event_flag.set()
gobject.idle_add(self.treeview.set_model, self.store)
gobject.idle_add(self.on_search_stop)
def _create_legend(self):
icons = (
(gtk.STOCK_FILE, 'Class'),
(gtk.STOCK_EXECUTE, 'Method'),
(gtk.STOCK_SELECT_FONT, 'Field'),
(gtk.STOCK_DELETE, 'Declaration not found'),
(gtk.STOCK_INFO, 'Miscellaneous (info)'),
(u'?', 'Direct call – e.g. static, private, etc'),
(u'?', 'Virtual call (? + ?)'),
(u'?', 'Virtual call (indirect) which could be performed because '
'of polymorphism'),
(u'?', 'Virtual call (direct only) which does not actually '
'performed – e.g. interface method'),
(u'?', 'Super call (? + ?)'),
(u'?', 'Super call (indirect) because direct super does not '
'declare the method'),
(u'?', 'Super call (direct only) which does not actually '
'performed – e.g. not declared here'),
)
table = gtk.Table(7, 5)
table.set_border_width(8)
table.set_row_spacings(8)
table.set_col_spacings(8)
separator = gtk.VSeparator()
table.attach(separator, 2, 3, 0, 7, 0)
x, y = 0, 0
for icon, desc in icons:
if len(icon) == 1:
image = gtk.Label(icon)
else:
image = gtk.Image()
image.set_from_stock(icon, gtk.ICON_SIZE_MENU)
image.set_alignment(1, 0.5)
label = gtk.Label(desc)
label.set_alignment(0, 0.5)
table.attach(image, x + 0, x + 1, y, y + 1, gtk.FILL)
table.attach(label, x + 1, x + 2, y, y + 1, gtk.FILL)
y += 1
if y == 5 and x == 0:
x, y = 3, 0
frame = gtk.Frame('Legend')
frame.add(table)
return frame