def fill_property(self, property, value):
"""Set a value for a particular property.
'property' should be one of the keys in my propertyLabels.
"""
row, name = self.propertyLabels.get(property)
if type(value) is not types.InstanceType:
widget = gtk.Label(str(value))
widget.set_alignment(0, 0)
else:
widget = value.newAttributeWidget(self)
widget.set_name("PropertyValue")
self.subtable['properties'].attach(widget, 1, 2, row, row+1)
python类Label()的实例源码
def fill_attributeGroup(self, group, attributes):
"""Provide members of an attribute group.
'group' should be one of the keys in my groupLabels, and
'attributes' a list of (name, value) pairs, with each value as
either an Explorer or string.
"""
# XXX: How to indicate detail level of members?
table = self.subtable[group]
if not attributes:
table.hide()
return
table.resize(len(attributes)+1, 2)
# XXX: Do I need to destroy previously attached children?
row = 1 # 0 is title
for name, value in attributes.items():
label = gtk.Label(name)
label.set_name("AttributeName")
label.set_alignment(0, 0)
if type(value) is types.StringType:
widget = gtk.Label(value)
widget.set_alignment(0, 0)
else:
widget = value.newAttributeWidget(self)
table.attach(label, 0, 1, row, row + 1)
table.attach(widget, 1, 2, row, row + 1)
row = row + 1
table.show_all()
def getTextForLabel(self):
"""Returns text for my label.
The default implementation of AttributeWidget is a gtk.Label
widget. You may override this method to change the text which
appears in the label. However, if you don't want to be a
label, override _makeWidgetObject instead.
"""
return self.identifier
def _makeWidgetObject(self):
"""Make the GTK widget object that is me.
Called by __init__ to construct the GtkObject I wrap-- the ._o
member of a pygtk GtkObject. Isn't subclassing GtkObjects in
Python fun?
"""
ebox = gtk.EventBox()
label = gtk.Label(self.getTextForLabel())
label.set_alignment(0,0)
ebox.add(label)
return ebox._o
def __init__(self, title=None):
self.__title_text = None
gtk.widget_push_composite_child()
self.__title = gobject.new(gtk.Label, visible=True, xalign=0, yalign=0.5)
self.__indent = gobject.new(gtk.Label, visible=True, label=' ')
gtk.widget_pop_composite_child()
gtk.Bin.__init__(self)
self.__title.set_parent(self)
self.__indent.set_parent(self)
if title is not None:
self.props.title = title
def __init__(self):
assert Visualizer.INSTANCE is None
Visualizer.INSTANCE = self
super(Visualizer, self).__init__()
self.nodes = {} # node index -> Node
self.channels = {} # id(ns3.Channel) -> Channel
self.window = None # toplevel window
self.canvas = None # goocanvas.Canvas
self.time_label = None # gtk.Label
self.play_button = None # gtk.ToggleButton
self.zoom = None # gtk.Adjustment
self._scrolled_window = None # gtk.ScrolledWindow
self.links_group = goocanvas.Group()
self.channels_group = goocanvas.Group()
self.nodes_group = goocanvas.Group()
self._update_timeout_id = None
self.simulation = SimulationThread(self)
self.selected_node = None # node currently selected
self.speed = 1.0
self.information_windows = []
self._transmission_arrows = []
self._last_transmissions = []
self._drop_arrows = []
self._last_drops = []
self._show_transmissions_mode = None
self.set_show_transmissions_mode(ShowTransmissionsMode.ALL)
self._panning_state = None
self.node_size_adjustment = None
self.transmissions_smoothing_adjustment = None
self.sample_period = SAMPLE_PERIOD
self.node_drag_state = None
self.follow_node = None
self.shell_window = None
self.create_gui()
for plugin in plugins:
plugin(self)
def create_collector_bbox(self, collector):
frame = gtk.Frame(collector.name)
if collector.is_enabled():
layout = gtk.BUTTONBOX_SPREAD
spacing = 10
bbox = gtk.HButtonBox()
bbox.set_border_width(1)
bbox.set_layout(layout)
bbox.set_spacing(spacing)
frame.add(bbox)
startCollectorButton = gtk.Button('Start Collector')
startCollectorButton.connect("clicked", self.startIndividualCollector, collector)
startCollectorButton.set_sensitive(not isinstance(collector, engine.collector.ManualCollector))
bbox.add(startCollectorButton)
stopCollectorButton = gtk.Button('Stop Collector')
stopCollectorButton.connect("clicked", self.stopIndividualCollector, collector)
stopCollectorButton.set_sensitive(not isinstance(collector, engine.collector.ManualCollector))
bbox.add(stopCollectorButton)
parseButton = gtk.Button('Parse Data')
parseButton.connect("clicked", self.parser, collector)
bbox.add(parseButton)
else:
label = gtk.Label("Collector Disabled")
frame.add(label)
return frame
def create_error_vbox(self, error_msg):
vbox_error = gtk.VBox()
traceback.print_exc()
err_label = gtk.Label(error_msg)
err_label.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse("red"))
vbox_error.pack_start(err_label)
return vbox_error
def create_options_hbox(self, label, value, trace, sensitivity_group, constraints=None):
hbox_main = gtk.HBox()
label_text = gtk.Label(label.title())
label_text.set_alignment(0, 0.5)
label_text.set_padding(8,8)
checkbuttons = []
selected_options = value
if constraints is None:
options = []
else:
options = constraints
for option in options:
new_button = gtk.CheckButton(option)
if option in selected_options:
new_button.set_active(True)
checkbuttons.append(new_button)
hbox_main.pack_start(label_text)
for checkbutton in checkbuttons:
hbox_main.pack_start(checkbutton)
self.plugin_config_widgets.append(checkbuttons)
self.plugin_config_traces.append(trace)
sensitivity_group.append(label_text)
sensitivity_group.append(checkbuttons)
return hbox_main
def create_time_hbox(self, label, value, trace, sensitivity_group, constraints=None):
hbox_main = gtk.HBox()
label_text = gtk.Label(label.title())
label_text.set_alignment(0, 0.5)
label_text.set_padding(8,8)
adjustment = gtk.Adjustment(value, 0, sys.maxint, 1)
spinbutton_value = gtk.SpinButton(adjustment)
combobox_units = gtk.combo_box_new_text()
t_value, units = self.get_time_value_and_units(value)
spinbutton_value.set_value(t_value)
options = ["seconds", "minutes", "hours", "days", "weeks"]
for option in options:
combobox_units.append_text(option)
selected_index = options.index(units)
combobox_units.set_active(selected_index)
hbox_main.pack_start(label_text)
hbox_main.pack_start(spinbutton_value)
hbox_main.pack_start(combobox_units)
self.plugin_config_widgets.append([spinbutton_value, combobox_units])
self.plugin_config_traces.append(trace)
sensitivity_group.append(label_text)
sensitivity_group.append(spinbutton_value)
return hbox_main
#TODO: Refactor these
def __call__(self, icon):
try:
return self.cache[icon]
except KeyError: # element not in cache
result = gtk.Label().render_icon(icon, self.size)
self.cache[icon] = result
return result
def __call__(self, icon):
try:
return self.cache[icon]
except KeyError: # element not in cache
result = gtk.Label().render_icon(icon, self.size)
self.cache[icon] = result
return result
def exitfc_button_cb(self, button):
label = gtk.Label("Are you sure you want the FC to exit?")
dialog = gtk.Dialog("Confirm Exit",
None,
gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
dialog.vbox.pack_start(label)
label.show()
response = dialog.run()
dialog.destroy()
if response == gtk.RESPONSE_ACCEPT:
msg = ZarjExitCommand()
self.zarj_comm.push_message(msg)
def __init__(self, label="", ellipsize=pango.ELLIPSIZE_END):
gtk.Label.__init__(self)
self.set_use_markup(True)
self.set_justify(gtk.JUSTIFY_LEFT)
self.set_alignment(xalign=0.0, yalign=0.5)
self.set_markup(label)
if ellipsize:
self.set_ellipsize(ellipsize)
# __init__()
# Label
def __init__(self, label=""):
Label.__init__(self, label)
self.set_line_wrap(True)
self.set_single_line_mode(False)
self.set_justify(gtk.JUSTIFY_FILL)
# __init__()
# MultiLineLabel
def new_label_for(label, field, align_right=True):
"""Creates a new gtk.Label and associates it to field"""
wid = gtk.Label(label)
wid.set_mnemonic_widget(field)
if align_right:
wid.set_justify(gtk.JUSTIFY_RIGHT)
wid.set_alignment(xalign=1.0, yalign=0.5)
return wid
# new_label_for()
def new_table(wids):
"""Creates a gtk.Table with two rows, use it for forms"""
p = gtk.Table(rows=len(wids) or 1, columns=2, homogeneous=False)
p.set_col_spacings(5)
p.set_row_spacings(5)
if len(wids) < 1:
wid = gtk.Label("Empty")
p.attach(wid, 0, 2, 0, 1)
p.show_all()
return p
for i, row in enumerate(wids):
if isinstance(row, basestring):
wid = Label("<b>%s</b>" % row)
p.attach(wid, 0, 2, i, i+1)
wid.show()
if i > 0:
p.set_row_spacing(i-1, 10)
elif isinstance(row, (tuple, list)):
label, field = row
wid = new_label_for(label, field)
p.attach(wid, 0, 1, i, i+1, xoptions=gtk.FILL)
p.attach(field, 1, 2, i, i+1)
wid.show()
field.show()
sw = gtk.ScrolledWindow()
sw.set_shadow_type(gtk.SHADOW_NONE)
sw.set_policy(hscrollbar_policy=gtk.POLICY_NEVER,
vscrollbar_policy=gtk.POLICY_AUTOMATIC)
sw.add_with_viewport(p)
p.show()
sw.show()
return sw
# new_table()
def setup_gui_button_contents(self):
self.gui_button_contents = gtk.Label(self.__class__.__name__)
self.gui_button_contents.show()
# setup_gui_button_contents()
def _setup_ui_advanced(self):
self.width = hildon.NumberEditor(100, 400)
self.height = hildon.NumberEditor(100, 240)
wids = ("Media",
("Width:", self.width),
("Height:", self.height),
)
self.tab.append_page(catota.ui.new_table(wids), gtk.Label("Advanced"))
# _setup_ui_advanced()