本文整理汇总了Python中label.Label.connect方法的典型用法代码示例。如果您正苦于以下问题:Python Label.connect方法的具体用法?Python Label.connect怎么用?Python Label.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类label.Label
的用法示例。
在下文中一共展示了Label.connect方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TimeSpinBox
# 需要导入模块: from label import Label [as 别名]
# 或者: from label.Label import connect [as 别名]
class TimeSpinBox(gtk.VBox):
'''
TimeSpinBox class.
@undocumented: value_changed
@undocumented: size_change_cb
@undocumented: press_increase_button
@undocumented: press_decrease_button
@undocumented: handle_key_release
@undocumented: expose_time_spin
@undocumented: create_simple_button
'''
SET_NONE = 0
SET_HOUR = 1
SET_MIN = 2
SET_SEC = 3
__gsignals__ = {
"value-changed" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_INT, gobject.TYPE_INT, gobject.TYPE_INT)),
"key-release" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_INT, gobject.TYPE_INT, gobject.TYPE_INT)),
}
def __init__(self,
width=95,
height=22,
padding_x=5,
is_24hour=True,
):
'''
Initialize TimeSpinBox class.
@param width: The width of TimeSpinBox, default is 95 pixels.
@param height: The height of TimeSpinBox, default is 22 pixels.
@param padding_x: The padding x of TimeSpinBox, default is 5 pixels.
@param is_24hour: Whether use 24 hours format, default is True.
'''
gtk.VBox.__init__(self)
self.set_time = self.SET_NONE
self.set_time_bg_color = "#DCDCDC"
self.time_width = 0
self.time_comma_width = 0
self.__24hour = is_24hour
self.__pressed_button = False
self.hour_value = time.localtime().tm_hour
self.min_value = time.localtime().tm_min
self.sec_value = time.localtime().tm_sec
# Init.
self.width = width
self.height = height
self.padding_x = padding_x
self.arrow_button_width = 19
self.background_color = ui_theme.get_alpha_color("text_entry_background")
self.acme_color = ui_theme.get_alpha_color("text_entry_acme")
self.point_color = ui_theme.get_alpha_color("text_entry_point")
self.frame_point_color = ui_theme.get_alpha_color("text_entry_frame_point")
self.frame_color = ui_theme.get_alpha_color("text_entry_frame")
# Widget.
arrow_up_button = self.create_simple_button("up", self.press_increase_button)
arrow_down_button = self.create_simple_button("down", self.press_decrease_button)
button_box = gtk.VBox()
button_box.pack_start(arrow_up_button, False, False)
button_box.pack_start(arrow_down_button, False, False)
self.time_label = Label()
self.main_align = gtk.Alignment()
self.main_align.set(0.5, 0.5, 0, 0)
hbox = gtk.HBox()
hbox.pack_start(self.time_label, False, False)
hbox.pack_end(button_box, False, False)
hbox_align = gtk.Alignment()
hbox_align.set(0.5, 0.5, 1.0, 1.0)
hbox_align.set_padding(0, 1, 0, 0)
hbox_align.add(hbox)
self.main_align.add(hbox_align)
self.pack_start(self.main_align, False, False)
# Signals.
self.connect("size-allocate", self.size_change_cb)
self.time_label.connect("button-press-event", self.__time_label_press)
self.main_align.connect("expose-event", self.expose_time_spin)
SecondThread(self).start()
def get_24hour(self):
'''
Get whether use 24 hour format.
@return: Return True if is use 24 hour format.
'''
return self.__24hour
def set_24hour(self, value):
'''
Set whether use 24 hour format.
@param value: Set as True to use 24 hour format.
#.........这里部分代码省略.........
示例2: ComboBox
# 需要导入模块: from label import Label [as 别名]
# 或者: from label.Label import connect [as 别名]
class ComboBox(gtk.VBox):
'''
ComboBox class.
@undocumented: set_size_request
@undocumented: auto_set_size
@undocumented: on_drop_button_press
@undocumented: on_combo_single_click
@undocumented: on_focus_in_combo
@undocumented: on_focus_out_combo
@undocumented: items
@undocumented: on_expose_combo_frame
'''
__gsignals__ = {
"item-selected" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (str, gobject.TYPE_PYOBJECT, int,)),
"key-release" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (str, gobject.TYPE_PYOBJECT, int,)),
}
def __init__(self,
items=[],
droplist_height=None,
select_index=0,
max_width=None,
fixed_width=None,
min_width = 120,
min_height = 100,
editable=False,
):
'''
Initialize ComboBox class.
@param items: Init item list, default is empty list.
@param droplist_height: The height of droplist, default is None that droplist's height will calculate with items' height automatically.
@param select_index: Init index of selected item, default is 0.
@param max_width: Maximum width of combobox, default is None.
@param fixed_width: Fixed width of combobox, after you set this value combobox won't care the width of droplist and items, default is None.
@param min_width: Minimum width of combobox, default is 120 pixels.
@param min_height: Minimum height of combobox, default is 100 pixels.
@param editable: Set True to make combobox can edit, default is False.
'''
gtk.VBox.__init__(self)
self.set_can_focus(True)
# Init variables.
self.focus_flag = False
self.select_index = select_index
self.editable = editable
if self.editable:
self.padding_x = 0
else:
self.padding_x = 5
self.combo_list = ComboList(min_width=min_width,
max_width=max_width,
fixed_width=fixed_width,
min_height=min_height,
max_height=droplist_height)
self.drop_button = DisableButton(
(ui_theme.get_pixbuf("combo/dropbutton_normal.png"),
ui_theme.get_pixbuf("combo/dropbutton_hover.png"),
ui_theme.get_pixbuf("combo/dropbutton_press.png"),
ui_theme.get_pixbuf("combo/dropbutton_disable.png")),
)
self.drop_button_width = ui_theme.get_pixbuf("combo/dropbutton_normal.png").get_pixbuf().get_width()
self.panel_align = gtk.Alignment()
self.panel_align.set(0.5, 0.5, 0.0, 0.0)
if self.editable:
self.label = Entry()
else:
self.label = Label("", enable_select=False, enable_double_click=False)
self.label.connect("button-press-event", self.on_drop_button_press)
self.panel_align.set_padding(0, 0, self.padding_x, 0)
self.panel_align.add(self.label)
# Init items.
self.add_items(items)
# set selected index
if len(items) > 0:
self.set_select_index(select_index)
hbox = gtk.HBox()
hbox.pack_start(self.panel_align, True, False)
hbox.pack_start(self.drop_button, False, False)
box_align = gtk.Alignment()
box_align.set(0.5, 0.5, 0.0, 0.0)
box_align.add(hbox)
self.add(box_align)
# Connect signals.
box_align.connect("expose-event", self.on_expose_combo_frame)
self.drop_button.connect("button-press-event", self.on_drop_button_press)
self.connect("focus-in-event", self.on_focus_in_combo)
self.connect("focus-out-event", self.on_focus_out_combo)
self.combo_list.treeview.connect("button-press-item", self.on_combo_single_click)
#.........这里部分代码省略.........
示例3: ComboBox
# 需要导入模块: from label import Label [as 别名]
# 或者: from label.Label import connect [as 别名]
class ComboBox(gtk.VBox):
'''Combo box.'''
__gsignals__ = {
"item-selected" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (str, gobject.TYPE_PYOBJECT, int,)),
"key-release" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (str, gobject.TYPE_PYOBJECT, int,)),
}
def __init__(self, items, droplist_height=None, select_index=0, max_width=None):
'''Init combo box.'''
# Init.
gtk.VBox.__init__(self)
self.set_can_focus(True)
self.items = items
self.droplist_height = droplist_height
self.select_index = select_index
self.focus_flag = False
self.droplist = Droplist(self.items, max_width=max_width)
if self.droplist_height:
self.droplist.set_size_request(-1, self.droplist_height)
self.width = self.droplist.get_droplist_width()
self.height = 22
self.label_padding_left = 6
self.box = gtk.HBox()
self.dropbutton_width = ui_theme.get_pixbuf("combo/dropbutton_normal.png").get_pixbuf().get_width()
self.label = Label(self.items[select_index][0],
label_width=self.width - self.dropbutton_width - 1 - self.label_padding_left,
enable_select=False,
enable_double_click=False)
self.label.text_color = ui_theme.get_color("menu_font")
self.dropbutton = DisableButton(
(ui_theme.get_pixbuf("combo/dropbutton_normal.png"),
ui_theme.get_pixbuf("combo/dropbutton_hover.png"),
ui_theme.get_pixbuf("combo/dropbutton_press.png"),
ui_theme.get_pixbuf("combo/dropbutton_disable.png")),
)
self.align = gtk.Alignment()
self.align.set(0.5, 0.5, 0.0, 0.0)
self.align.set_padding(1, 1, 1 + self.label_padding_left, 1)
self.pack_start(self.align, False, False)
self.align.add(self.box)
self.box.pack_start(self.label, False, False)
self.box.pack_start(self.dropbutton, False, False)
self.align.connect("expose-event", self.expose_combobox_frame)
self.label.connect("button-press-event", self.click_drop_button)
self.dropbutton.connect("button-press-event", self.click_drop_button)
self.droplist.connect("item-selected", self.update_select_content)
self.droplist.connect("key-release", lambda dl, s, o, i: self.emit("key-release", s, o, i))
self.connect("key-press-event", self.key_press_combo)
self.connect("key-release-event", self.key_release_combo)
self.connect("focus-in-event", self.focus_in_combo)
self.connect("focus-out-event", self.focus_out_combo)
self.keymap = {
"Home" : self.select_first_item,
"End" : self.select_last_item,
"Up" : self.select_prev_item,
"Down" : self.select_next_item}
def focus_in_combo(self, widget, event):
'''Focus in combo.'''
self.focus_flag = True
self.label.text_color = ui_theme.get_color("menu_select_font")
self.queue_draw()
def focus_out_combo(self, widget, event):
'''Focus out combo.'''
self.focus_flag = False
self.label.text_color = ui_theme.get_color("menu_font")
self.queue_draw()
def click_drop_button(self, *args):
'''Click drop button.'''
if self.droplist.get_visible():
self.droplist.hide()
else:
(align_x, align_y) = get_widget_root_coordinate(self.align, WIDGET_POS_BOTTOM_LEFT)
self.droplist.show(
(align_x - 1, align_y - 1),
(0, -self.height + 1))
self.droplist.item_select_index = self.select_index
self.droplist.active_item()
self.droplist.scroll_page_to_select_item()
self.queue_draw()
def select_first_item(self):
'''Select first item.'''
if len(self.droplist.droplist_items) > 0:
first_index = self.droplist.get_first_index()
if first_index != None:
self.droplist.item_select_index = first_index
self.droplist.active_item()
#.........这里部分代码省略.........