terminator/terminatorlib/util.py

50 lines
1.6 KiB
Python
Raw Normal View History

2009-08-07 09:21:37 +00:00
#!/usr/bin/python
2009-08-09 23:10:08 +00:00
# Terminator.util - misc utility functions
2009-08-07 09:21:37 +00:00
# Copyright (C) 2006-2008 cmsj@tenshu.net
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 2 only.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2009-08-09 23:10:08 +00:00
"""Terminator.util - misc utility functions"""
2009-08-07 09:21:37 +00:00
import sys
import gtk
2009-08-07 09:21:37 +00:00
# set this to true to enable debugging output
DEBUG = True
2009-08-07 09:21:37 +00:00
def dbg(log = ""):
2009-08-09 23:10:08 +00:00
"""Print a message if debugging is enabled"""
if DEBUG:
print >> sys.stderr, log
2009-08-07 09:21:37 +00:00
def err(log = ""):
2009-08-09 23:10:08 +00:00
"""Print an error message"""
print >> sys.stderr, log
def gerr(message = None):
"""Display a graphical error. This should only be used for serious
errors as it will halt execution"""
dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL,
gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, message)
dialog.run()
def has_ancestor(widget, type):
"""Walk up the family tree of widget to see if any ancestors are of type"""
while widget:
widget = widget.get_parent()
if isinstance(widget, type):
return(True)
return(False)