Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 from python_qt_binding.QtCore import Qt
00036 from python_qt_binding.QtGui import QWidgetItem
00037 import roslib
00038 import rospy
00039
00040
00041 class LayoutUtil(object):
00042
00043 @staticmethod
00044 def alternate_color(list_widgets, colors_alter=[Qt.white, Qt.gray]):
00045 """
00046 Alternate the background color of the widgets that are ordered
00047 linearly, by the given list of colors.
00048
00049 Originally intended for the elements of QHBoxLayout & QVBoxLayout.
00050
00051 @type list_widgets: QtGui.QWidget[]
00052 @type colors_alter: QtCore.Qt.GlobalColor[]
00053 @param colors_alter: 1st element is used as initial/default color.
00054 @rtype: void
00055
00056 @author: Isaac Saito
00057 """
00058
00059 colors_num = len(colors_alter)
00060 i_widget = 0
00061 for w in list_widgets:
00062 w.setAutoFillBackground(True)
00063 p = w.palette()
00064
00065 divisor = (i_widget + colors_num) % colors_num
00066 i_widget += 1
00067
00068 rospy.logdebug('LayoutUtil divisor={} i_widget={} colors_num={}'.format(
00069 divisor,
00070 i_widget,
00071 colors_num))
00072
00073 p.setColor(w.backgroundRole(), colors_alter[divisor])
00074 w.setPalette(p)
00075
00076 @staticmethod
00077 def clear_layout(layout):
00078 """
00079 Clear all items in the given layout. Currently, only the instances of
00080 QWidgetItem get cleared (ie. QSpaceItem is ignored).
00081
00082 Originally taken from http://stackoverflow.com/a/9375273/577001
00083
00084 :type layout: QLayout
00085 """
00086 for i in reversed(range(layout.count())):
00087 item = layout.itemAt(i)
00088
00089 if isinstance(item, QWidgetItem):
00090
00091 item.widget().close()
00092
00093
00094 elif isinstance(item, QSpacerItem):
00095
00096 continue
00097
00098 else:
00099
00100 LayoutUtil.clear_layout(item.layout())
00101
00102
00103 layout.removeItem(item)