Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4ca58f5

Browse files
committed
feat(widget): enhance button navigation with row wrapping support
Improves the button navigation logic to allow vertical movement across rows, ensuring a smoother user experience when navigating through buttons in the power menu. Adjustments include handling edge cases for row transitions and maintaining focus within valid button indices.
1 parent1d9f9c9 commit4ca58f5

File tree

1 file changed

+40
-12
lines changed

1 file changed

+40
-12
lines changed

‎src/core/widgets/yasb/power_menu.py

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,16 @@ def eventFilter(self, source, event):
274274
source.setProperty("class",f"button{source.property('class').split()[1]} hover")
275275
source.style().unpolish(source)
276276
source.style().polish(source)
277+
forchildinsource.findChildren(QLabel):
278+
child.style().unpolish(child)
279+
child.style().polish(child)
277280
elifevent.type()==QtCore.QEvent.Type.Leaveandisinstance(source,QPushButton):
278281
source.setProperty("class",f"button{source.property('class').split()[1]}")
279282
source.style().unpolish(source)
280283
source.style().polish(source)
284+
forchildinsource.findChildren(QLabel):
285+
child.style().unpolish(child)
286+
child.style().polish(child)
281287
returnsuper(MainWindow,self).eventFilter(source,event)
282288

283289
defkeyPressEvent(self,event):
@@ -291,10 +297,10 @@ def keyPressEvent(self, event):
291297
self.navigate_focus(-1)
292298
event.accept()# Mark event as handled
293299
elifevent.key()==Qt.Key.Key_Down:
294-
self.navigate_focus(self.button_row)
300+
self.navigate_focus(self.button_row)# Move down by one row
295301
event.accept()# Mark event as handled
296302
elifevent.key()==Qt.Key.Key_Up:
297-
self.navigate_focus(-self.button_row)
303+
self.navigate_focus(-self.button_row)# Move up by one row
298304
event.accept()# Mark event as handled
299305
elifevent.key()in (Qt.Key.Key_Return,Qt.Key.Key_Enter,Qt.Key.Key_Space):
300306
# Trigger click on the focused button
@@ -303,7 +309,7 @@ def keyPressEvent(self, event):
303309
event.accept()# Mark event as handled
304310
else:
305311
super(MainWindow,self).keyPressEvent(event)
306-
312+
307313
defnavigate_focus(self,step):
308314
"""Navigate button focus by step."""
309315
ifnotself.buttons_list:
@@ -314,30 +320,52 @@ def navigate_focus(self, step):
314320
# If no button is currently focused, start with the appropriate first button
315321
ifself.current_focus_index<0orself.current_focus_index>=total_buttons:
316322
ifstep>0:
317-
# When pressing right arrow with no selection, select the first button
323+
# When pressing rightor downarrow with no selection, select the first button
318324
new_index=0
319325
elifstep<0:
320-
# When pressing left arrow with no selection, select the last button
326+
# When pressing leftor uparrow with no selection, select the last button
321327
new_index=total_buttons-1
322328
else:
323-
#For other keys with no selection, default to first button
329+
#Default to first button
324330
new_index=0
325331
else:
326332
# Normal navigation with existing selection
327333
current=self.current_focus_index
328334

329-
# Simple navigation with wrapping
330335
ifstep==1:# Right
331336
new_index= (current+1)%total_buttons
332337
elifstep==-1:# Left
333338
new_index= (current-1)%total_buttons
334-
elifstep==self.button_row:# Down
335-
new_index= (current+self.button_row)%total_buttons
336-
elifstep==-self.button_row:# Up
337-
new_index= (current-self.button_row)%total_buttons
339+
elifstep==self.button_roworstep==-self.button_row:# Up/Down - vertical movement
340+
# Calculate the current row and column
341+
current_row=current//self.button_row
342+
current_col=current%self.button_row
343+
344+
# Determine total rows
345+
total_rows= (total_buttons+self.button_row-1)//self.button_row
346+
347+
ifstep==self.button_row:# Down
348+
# Move to next row, same column
349+
new_row= (current_row+1)%total_rows
350+
else:# Up
351+
# Move to previous row, same column
352+
new_row= (current_row-1)%total_rows
353+
354+
# Calculate new index
355+
new_index=new_row*self.button_row+current_col
356+
357+
# If we've moved to a partial row and the column is beyond its bounds
358+
ifnew_index>=total_buttons:
359+
ifstep==self.button_row:
360+
# When moving down to an out-of-bounds position, wrap to first row
361+
new_index=current_col
362+
else:
363+
# When moving up to an out-of-bounds position, use last valid button
364+
new_index=total_buttons-1
338365
else:
339366
new_index=current# No change
340-
367+
368+
new_index=max(0,min(new_index,total_buttons-1))
341369
self.set_focused_button(new_index)
342370

343371
defset_focused_button(self,index):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp