Skip to content
This repository was archived by the owner on Mar 31, 2020. It is now read-only.

Commit ced7223

Browse files
committed
Updated CloppyWindow subclasses, .flake8
- Added more commentary to CloppyButtonWindow and CloppyTextInputWindow. - Fixed some issues with .flake8 file.
1 parent bc3065c commit ced7223

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

.flake8

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
[flake8]
12
max-line-length=100
2-
application_import_names=projectt
3+
application_import_names=project
34
ignore=P102,B311,W503,E226,S311,W504,F821
45
exclude=__pycache__, venv, .venv, tests
56
import-order-style=pycharm

project/windows/cloppy_window.py

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ def show(self):
132132

133133

134134
class CloppyButtonWindow(CloppyWindow):
135+
"""
136+
A sub-child of CloppyWindow that takes input from the user using a list of
137+
buttons.
138+
"""
135139
def __init__(self, master):
136140
super().__init__(master)
137141

@@ -159,8 +163,6 @@ def add_choice(self, choice):
159163
command=lambda: self.make_choice(choice)
160164
)
161165

162-
# choice_button.bind('<Up>', self.on_up_key)
163-
164166
row = len(self.choice_buttons)
165167

166168
choice_button.grid(
@@ -174,12 +176,20 @@ def add_choice(self, choice):
174176
def show(self):
175177
super().show()
176178

179+
# Set focus to the first button in the list.
177180
if len(self.choice_buttons):
178181
self.choice_buttons[0].focus_set()
179182

180183
def set_highlighted_choice(self, choice):
184+
"""
185+
Set focus to the button at a given index in the list of choices.
186+
187+
:param choice: The index of the choice to be focused on.
188+
"""
189+
181190
if choice < 0:
182191
choice = len(self.choice_buttons)-1
192+
183193
elif choice >= len(self.choice_buttons):
184194
choice = 0
185195

@@ -197,27 +207,45 @@ def on_enter_key(self, event: tk.Event):
197207

198208

199209
class CloppyTextInputWindow(CloppyWindow):
210+
"""
211+
A sub-child of CloppyWindow that takes input from the user using a text
212+
entry.
213+
"""
200214
def __init__(self, master, password=False, submit_button_text='Ok'):
215+
"""
216+
:param password: If set to True, then input in the box will be masked
217+
as if it's a password.
218+
219+
:param submit_button_text: The text shown in the button at the bottom.
220+
When clicked, this button will submit the
221+
user's input as a choice.
222+
"""
201223
super().__init__(master)
202224

225+
# Setting up the text entry box.
203226
if password:
204227
self.input_box = tk.Entry(self.input_frame, show='*')
205228
else:
206229
self.input_box = tk.Entry(self.input_frame)
207230

231+
self.input_box.grid(row=0, column=0, sticky=tk.NSEW)
232+
233+
self.input_box.bind(
234+
'<Return>',
235+
lambda e: self.make_choice(self.input_box.get())
236+
)
237+
238+
# Setting up the submit button.
208239
self.submit_button = tk.Button(
209240
self.input_frame,
210241
text=submit_button_text,
211242
command=lambda: self.make_choice(self.input_box.get())
212243
)
213244

214-
self.input_box.grid(row=0, column=0, sticky=tk.NSEW)
215245
self.submit_button.grid(row=1, column=0, sticky=tk.NSEW)
216-
self.input_box.bind(
217-
'<Return>',
218-
lambda e: self.make_choice(self.input_box.get())
219-
)
220246

221247
def show(self):
222248
super().show()
249+
250+
# Direct focus to the input box.
223251
self.input_box.focus_set()

0 commit comments

Comments
 (0)