tool.py

Go to the documentation of this file.
00001 # vim: ts:4 expandtab
00002 # Copyright (c) 2007 Cristian L. Vlasceanu
00003 #
00004 # Permission is hereby granted, free of charge, to any person
00005 # obtaining a copy of this software and associated documentation
00006 # files (the "Software"), to deal in the Software without
00007 # restriction, including without limitation the rights to use,
00008 # copy, modify, merge, publish, distribute, sublicense, and/or
00009 # sell copies of the Software, and to permit persons to whom
00010 # the Software is furnished to do so, subject to the following
00011 # conditions:
00012 # 
00013 # The above copyright notice and this permission notice shall be
00014 # included in all copies or substantial portions of the Software.
00015 # 
00016 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
00017 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
00018 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
00019 # AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
00020 # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
00021 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00022 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
00023 # OR OTHER DEALINGS IN THE SOFTWARE.
00024 # 
00025 # NOTE: The above applies solely to Python source code provided 
00026 # herein, and it DOES NOT COVER the Zero Debugger Engine and plug-ins.
00027 
00028 import gtk
00029 
00030 
00031 class Bar(object):
00032     def __init__(self, toolbar):
00033         self.__toolbar = toolbar
00034 
00035 
00036     def add_space(self):
00037         try:
00038             self.__toolbar.insert(gtk.SeparatorToolItem(), -1)
00039         except:
00040             self.__toolbar.append_space()
00041 
00042 
00043     def add_widget(self, widget, tip_text, private_text):
00044         try:
00045             toolitem = gtk.ToolItem()
00046             toolitem.add(widget)
00047             toolitem.set_expand(False)
00048             toolitem.set_homogeneous(False)
00049             toolitem.set_tooltip(gtk.Tooltips(), tip_text, private_text)
00050             self.__toolbar.insert(toolitem, -1)
00051         except:
00052             self.__toolbar.append_element(
00053                 gtk.TOOLBAR_CHILD_WIDGET,            
00054                 widget,
00055                 tip_text,
00056                 private_text,
00057                 None,
00058                 None,
00059                 None,
00060                 None)
00061 
00062 
00063     def add_stock(self, name, stock_id, label, tip_text, important, cb):
00064         try:
00065             toolitem = gtk.ToolButton(stock_id)
00066             toolitem.connect('clicked', cb)
00067             toolitem.set_tooltip(gtk.Tooltips(), tip_text, tip_text)
00068             toolitem.set_name('tool_' + name)
00069             toolitem.set_label(label)
00070             toolitem.set_is_important(important)
00071             self.__toolbar.insert(toolitem,-1)
00072         except:
00073             icon = gtk.Image()
00074             icon.set_from_stock(stock_id, gtk.ICON_SIZE_SMALL_TOOLBAR)
00075             w = self.__toolbar.insert_item(
00076                 label,
00077                 tip_text,
00078                 tip_text,
00079                 icon,
00080                 cb,
00081                 None,
00082                 -1)
00083             w.set_name('tool_' + name)
00084