primitivus: added a FOCUS_EXTRA key (default: "ctrl f") which can be used to focus a main part:
- ctrl f + 1 (or m) to focus menu
- ctrl f + 2 (or b) to focus body
- ctrl f + 3 (or n) to focus notifications bar
- ctrl f + 4 (or e) to focus edit bar
This commit is contained in:
parent
171f1677d2
commit
befbf322ea
2 changed files with 43 additions and 2 deletions
|
|
@ -55,6 +55,9 @@ action_key_map.update(
|
||||||
|
|
||||||
#card game
|
#card game
|
||||||
("card_game", "CARD_SELECT"): ' ',
|
("card_game", "CARD_SELECT"): ' ',
|
||||||
|
|
||||||
|
#focus
|
||||||
|
("focus", "FOCUS_EXTRA"): "ctrl f",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -189,6 +189,7 @@ class PrimitivusTopWidget(sat_widgets.FocusPile):
|
||||||
self._notif_bar = notif_bar
|
self._notif_bar = notif_bar
|
||||||
self._edit_bar = edit_bar
|
self._edit_bar = edit_bar
|
||||||
self._hidden = {'notif_bar'}
|
self._hidden = {'notif_bar'}
|
||||||
|
self._focus_extra = False
|
||||||
super(PrimitivusTopWidget, self).__init__([('pack', self._menu), self._body, ('pack', self._edit_bar)])
|
super(PrimitivusTopWidget, self).__init__([('pack', self._menu), self._body, ('pack', self._edit_bar)])
|
||||||
for position in self.positions:
|
for position in self.positions:
|
||||||
setattr(self,
|
setattr(self,
|
||||||
|
|
@ -198,6 +199,44 @@ class PrimitivusTopWidget(sat_widgets.FocusPile):
|
||||||
)
|
)
|
||||||
self.focus_position = len(self.contents)-1
|
self.focus_position = len(self.contents)-1
|
||||||
|
|
||||||
|
def getVisiblePositions(self, keep=None):
|
||||||
|
"""Return positions that are not hidden in the right order
|
||||||
|
|
||||||
|
@param keep: if not None, this position will be keep in the right order, even if it's hidden
|
||||||
|
(can be useful to find its index)
|
||||||
|
@return (list): list of visible positions
|
||||||
|
"""
|
||||||
|
return [pos for pos in self.positions if (keep and pos == keep) or pos not in self._hidden]
|
||||||
|
|
||||||
|
def keypress(self, size, key):
|
||||||
|
"""Manage FOCUS keys that focus directly a main part (one of self.positions)
|
||||||
|
|
||||||
|
To avoid key conflicts, a combinaison must be made with FOCUS_EXTRA then an other key
|
||||||
|
"""
|
||||||
|
if key == a_key['FOCUS_EXTRA']:
|
||||||
|
self._focus_extra = True
|
||||||
|
return
|
||||||
|
if self._focus_extra:
|
||||||
|
self._focus_extra = False
|
||||||
|
if key in ('m', '1'):
|
||||||
|
focus = 'menu'
|
||||||
|
elif key in ('b', '2'):
|
||||||
|
focus = 'body'
|
||||||
|
elif key in ('n', '3'):
|
||||||
|
focus = 'notif_bar'
|
||||||
|
elif key in ('e', '4'):
|
||||||
|
focus = 'edit_bar'
|
||||||
|
else:
|
||||||
|
return super(PrimitivusTopWidget, self).keypress(size, key)
|
||||||
|
|
||||||
|
if focus in self._hidden:
|
||||||
|
return
|
||||||
|
|
||||||
|
self.focus_position = self.getVisiblePositions().index(focus)
|
||||||
|
return
|
||||||
|
|
||||||
|
return super(PrimitivusTopWidget, self).keypress(size, key)
|
||||||
|
|
||||||
def widgetGet(self, position):
|
def widgetGet(self, position):
|
||||||
if not position in self.positions:
|
if not position in self.positions:
|
||||||
raise ValueError("Unknown position {}".format(position))
|
raise ValueError("Unknown position {}".format(position))
|
||||||
|
|
@ -212,9 +251,8 @@ class PrimitivusTopWidget(sat_widgets.FocusPile):
|
||||||
if not position in self.can_hide:
|
if not position in self.can_hide:
|
||||||
raise ValueError("Can't switch position {}".format(position))
|
raise ValueError("Can't switch position {}".format(position))
|
||||||
hide = not position in self._hidden
|
hide = not position in self._hidden
|
||||||
visible_positions = [pos for pos in self.positions if pos == position or pos not in self._hidden] # we need to keep position to find its index
|
|
||||||
widget = self.widgetGet(position)
|
widget = self.widgetGet(position)
|
||||||
idx = visible_positions.index(position)
|
idx = self.getVisiblePositions(position).index(position)
|
||||||
if hide:
|
if hide:
|
||||||
del self.contents[idx]
|
del self.contents[idx]
|
||||||
self._hidden.add(position)
|
self._hidden.add(position)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue