Skip to content

Commit 11adc83

Browse files
committed
refactor: moved status button to core views
1 parent bd4c023 commit 11adc83

File tree

3 files changed

+43
-71
lines changed

3 files changed

+43
-71
lines changed

app/contracts/view.py

+4-32
Original file line numberDiff line numberDiff line change
@@ -174,34 +174,6 @@ def __init__(self, onStateChanged: Callable[[ContractStates], None]):
174174
self.state_to_filter_btns_map = {}
175175
self.on_state_changed_callback = onStateChanged
176176

177-
def filter_button(
178-
self,
179-
state: ContractStates,
180-
label: str,
181-
onClick: Callable[[ContractStates], None],
182-
tooltip: str,
183-
):
184-
"""Creates a filter button for the given state"""
185-
button = ElevatedButton(
186-
text=label,
187-
col={"xs": 6, "sm": 3, "lg": 2},
188-
on_click=lambda e: onClick(state),
189-
height=dimens.CLICKABLE_PILL_HEIGHT,
190-
color=colors.PRIMARY_COLOR
191-
if state == self.current_state
192-
else colors.GRAY_COLOR,
193-
tooltip=tooltip,
194-
style=ButtonStyle(
195-
elevation={
196-
utils.PRESSED: 3,
197-
utils.SELECTED: 3,
198-
utils.HOVERED: 4,
199-
utils.OTHER_CONTROL_STATES: 2,
200-
},
201-
),
202-
)
203-
return button
204-
205177
def on_filter_button_clicked(self, state: ContractStates):
206178
"""sets the new state and updates selected button"""
207179
self.state_to_filter_btns_map[self.current_state].color = colors.GRAY_COLOR
@@ -213,13 +185,13 @@ def on_filter_button_clicked(self, state: ContractStates):
213185
def set_filter_buttons(self):
214186
"""Sets all the filter buttons"""
215187
for state in ContractStates:
216-
button = self.filter_button(
188+
self.state_to_filter_btns_map[state] = views.TStatusFilterBtn(
217189
label=state.__str__(),
218-
state=state,
219-
onClick=self.on_filter_button_clicked,
190+
is_current_state=self.current_state.value == state.value,
191+
on_click_params=state,
192+
on_click=self.on_filter_button_clicked,
220193
tooltip=state.tooltip(),
221194
)
222-
self.state_to_filter_btns_map[state] = button
223195

224196
def build(self):
225197
"""Builds the filter buttons"""

app/core/views.py

+28
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
PopupMenuButton,
1919
PopupMenuItem,
2020
ProgressBar,
21+
ButtonStyle,
2122
margin,
2223
NavigationRail,
2324
Row,
@@ -908,3 +909,30 @@ def __init__(self, form_controls: list[UserControl]):
908909
),
909910
),
910911
)
912+
913+
914+
class TStatusFilterBtn(ElevatedButton):
915+
def __init__(
916+
self,
917+
label: str,
918+
is_current_state: bool,
919+
on_click: Callable,
920+
tooltip: str,
921+
on_click_params: any,
922+
):
923+
return super().__init__(
924+
text=label,
925+
col={"xs": 6, "sm": 3, "lg": 2},
926+
on_click=lambda e: on_click(on_click_params),
927+
height=dimens.CLICKABLE_PILL_HEIGHT,
928+
color=colors.PRIMARY_COLOR if is_current_state else colors.GRAY_COLOR,
929+
tooltip=tooltip,
930+
style=ButtonStyle(
931+
elevation={
932+
utils.PRESSED: 3,
933+
utils.SELECTED: 3,
934+
utils.HOVERED: 4,
935+
utils.OTHER_CONTROL_STATES: 2,
936+
},
937+
),
938+
)

app/projects/view.py

+11-39
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,11 @@ def __str__(self):
210210

211211
def tooltip(self):
212212
"""returns the tooltip for the filter button"""
213-
if self is ProjectStates.ACTIVE.value:
213+
if self is ProjectStates.ACTIVE:
214214
return "Not completed and not due."
215-
elif self is ProjectStates.UPCOMING.value:
215+
elif self is ProjectStates.UPCOMING:
216216
return "Scheduled for the future."
217-
elif self is ProjectStates.COMPLETED.value:
217+
elif self is ProjectStates.COMPLETED:
218218
return "Marked as completed."
219219
else:
220220
return "All projects."
@@ -225,56 +225,28 @@ class ProjectFiltersView(UserControl):
225225

226226
def __init__(self, onStateChanged: Callable[[ProjectStates], None]):
227227
super().__init__()
228-
self.currentState = ProjectStates.ALL
228+
self.current_state = ProjectStates.ALL
229229
self.stateTofilterButtonsMap = {}
230230
self.onStateChangedCallback = onStateChanged
231231

232-
def filter_button(
233-
self,
234-
state: ProjectStates,
235-
label: str,
236-
onClick: Callable[[ProjectStates], None],
237-
tooltip: str,
238-
):
239-
"""creates a filter button for project status"""
240-
button = ElevatedButton(
241-
text=label,
242-
col={"xs": 6, "sm": 3, "lg": 2},
243-
on_click=lambda e: onClick(state),
244-
height=dimens.CLICKABLE_PILL_HEIGHT,
245-
color=colors.PRIMARY_COLOR
246-
if state == self.currentState
247-
else colors.GRAY_COLOR,
248-
tooltip=tooltip,
249-
style=ButtonStyle(
250-
elevation={
251-
utils.PRESSED: 3,
252-
utils.SELECTED: 3,
253-
utils.HOVERED: 4,
254-
utils.OTHER_CONTROL_STATES: 2,
255-
},
256-
),
257-
)
258-
return button
259-
260232
def on_filter_button_clicked(self, state: ProjectStates):
261233
"""sets the new state and updates selected button"""
262-
self.stateTofilterButtonsMap[self.currentState].color = colors.GRAY_COLOR
263-
self.currentState = state
264-
self.stateTofilterButtonsMap[self.currentState].color = colors.PRIMARY_COLOR
234+
self.stateTofilterButtonsMap[self.current_state].color = colors.GRAY_COLOR
235+
self.current_state = state
236+
self.stateTofilterButtonsMap[self.current_state].color = colors.PRIMARY_COLOR
265237
self.update()
266238
self.onStateChangedCallback(state)
267239

268240
def set_filter_buttons(self):
269241
"""sets the filter buttons for each project state"""
270242
for state in ProjectStates:
271-
button = self.filter_button(
243+
self.stateTofilterButtonsMap[state] = views.TStatusFilterBtn(
272244
label=state.__str__(),
273-
state=state,
274-
onClick=self.on_filter_button_clicked,
245+
is_current_state=state.value == self.current_state.value,
246+
on_click=self.on_filter_button_clicked,
247+
on_click_params=state,
275248
tooltip=state.tooltip(),
276249
)
277-
self.stateTofilterButtonsMap[state] = button
278250

279251
def build(self):
280252
"""builds the filter buttons"""

0 commit comments

Comments
 (0)