MCPcopy Create free account
hub / github.com/ActiveState/code / __init__

Method __init__

recipes/Python/580785_Metro_Listbox/recipe-580785.py:16–57  ·  view source on GitHub ↗
(self, master, options, width=20, bordercolor="#cccccc", foreground="black", background="white", activebackground="#2780E3", activeforeground="white",padx=15, pady=7, command=None)

Source from the content-addressed store, hash-verified

14
15class Listbox(Frame):
16 def __init__(self, master, options, width=20, bordercolor="#cccccc", foreground="black", background="white", activebackground="#2780E3", activeforeground="white",padx=15, pady=7, command=None):
17 Frame.__init__(self, master, background=background, highlightbackground=bordercolor, highlightcolor=bordercolor, highlightthickness=1, bd= 0)
18
19 self._foreground = foreground
20 self._background = background
21 self._activebackground = activebackground
22 self._activeforeground = activeforeground
23
24 self._items = []
25
26 index = 0
27 for option in options:
28
29 if option is None:
30 Separator(self, orient=HORIZONTAL).pack(fill=X)
31 continue
32
33 if isinstance(option, basestring):
34 test = option
35 value = option
36 else:
37 text, value = option
38
39 label_item = Label(self, width=width, text=text, background=background, foreground="black", anchor=W, padx=padx, pady=pady)
40 label_item.pack(fill=X)
41
42 label_item.index = index
43 label_item.value = value
44
45 label_item.bind("<Enter>", self._on_enter_label_item)
46 label_item.bind("<Leave>", self._on_leave_label_item)
47 label_item.bind("<1>", lambda event, index=index:self._on_click_item(event.widget, index))
48 self._items.append(label_item)
49
50 index += 1
51
52 self._actived_item = None
53 self._command = command
54
55 self.bind("<Up>", self._on_up)
56 self.bind("<Down>", self._on_down)
57 self.bind("<Return>", self._on_return)
58
59 def _on_return(self, event):
60 if self._command is not None:

Callers

nothing calls this directly

Calls 5

_on_click_itemMethod · 0.95
LabelClass · 0.85
packMethod · 0.45
bindMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected