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

Class Listbox

recipes/Python/580785_Metro_Listbox/recipe-580785.py:15–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13 basestring = str
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:
61 if self._actived_item is not None:
62 self._command(self._actived_item.value)
63
64 def _activate_colors(self, label_item):
65 label_item.configure(background=self._activebackground, foreground=self._activeforeground)
66
67 def _deactivate_colors(self, label_item):
68 label_item.configure(background=self._background, foreground=self._foreground)
69
70 def _on_enter_label_item(self, event):
71 label_item = event.widget
72 self._activate_colors(label_item)

Callers 13

recipe-580714.pyFile · 0.85
changedMethod · 0.85
recipe-580785.pyFile · 0.85
__init__Method · 0.85
create_widgetsMethod · 0.85
__init__Method · 0.85
__init__Method · 0.85
makeWidgetsMethod · 0.85
__init__Method · 0.85
_build_listboxMethod · 0.85
__init__Method · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected