mirror of
https://github.com/markqvist/NomadNet.git
synced 2025-05-05 07:35:02 -04:00
Focus handling
This commit is contained in:
parent
24d79c4b2b
commit
ba22f41cf8
4 changed files with 120 additions and 45 deletions
|
@ -2,19 +2,50 @@ import RNS
|
|||
import time
|
||||
import nomadnet
|
||||
|
||||
class ConversationsDisplayShortcuts():
|
||||
import urwid
|
||||
|
||||
class ListEntry(urwid.Text):
|
||||
_selectable = True
|
||||
|
||||
signals = ["click"]
|
||||
|
||||
def keypress(self, size, key):
|
||||
"""
|
||||
Send 'click' signal on 'activate' command.
|
||||
"""
|
||||
if self._command_map[key] != urwid.ACTIVATE:
|
||||
return key
|
||||
|
||||
self._emit('click')
|
||||
|
||||
def mouse_event(self, size, event, button, x, y, focus):
|
||||
"""
|
||||
Send 'click' signal on button 1 press.
|
||||
"""
|
||||
if button != 1 or not urwid.util.is_mouse_press(event):
|
||||
return False
|
||||
|
||||
self._emit('click')
|
||||
return True
|
||||
|
||||
|
||||
class ConversationListDisplayShortcuts():
|
||||
def __init__(self, app):
|
||||
import urwid
|
||||
self.app = app
|
||||
|
||||
self.widget = urwid.AttrMap(urwid.Text("Conversations Display Shortcuts"), "shortcutbar")
|
||||
self.widget = urwid.AttrMap(urwid.Text("Conversation List Display Shortcuts"), "shortcutbar")
|
||||
|
||||
class ConversationDisplayShortcuts():
|
||||
def __init__(self, app):
|
||||
self.app = app
|
||||
|
||||
self.widget = urwid.AttrMap(urwid.Text("[C-s] Send"), "shortcutbar")
|
||||
|
||||
class ConversationsDisplay():
|
||||
list_width = 0.33
|
||||
cached_conversation_widgets = {}
|
||||
|
||||
def __init__(self, app):
|
||||
import urwid
|
||||
from nomadnet.vendor.additional_urwid_widgets import IndicativeListBox
|
||||
|
||||
self.app = app
|
||||
|
@ -23,12 +54,21 @@ class ConversationsDisplay():
|
|||
for conversation in app.conversations():
|
||||
conversation_list_widgets.append(self.conversation_list_widget(conversation))
|
||||
|
||||
def disp_list_shortcuts(sender, arg1, arg2):
|
||||
self.shortcuts_display = self.list_shortcuts
|
||||
self.app.ui.main_display.update_active_shortcuts()
|
||||
RNS.log("Modified")
|
||||
|
||||
walker = urwid.SimpleFocusListWalker(conversation_list_widgets)
|
||||
listbox = urwid.LineBox(urwid.Filler(IndicativeListBox(conversation_list_widgets), height=("relative", 100)))
|
||||
ilb = IndicativeListBox(conversation_list_widgets)
|
||||
listbox = urwid.LineBox(urwid.Filler(ilb, height=("relative", 100)))
|
||||
|
||||
columns_widget = urwid.Columns([("weight", ConversationsDisplay.list_width, listbox), ("weight", 1-ConversationsDisplay.list_width, self.make_conversation_widget(None))], dividechars=0, focus_column=0, box_columns=[0])
|
||||
|
||||
self.shortcuts_display = ConversationsDisplayShortcuts(self.app)
|
||||
self.list_shortcuts = ConversationListDisplayShortcuts(self.app)
|
||||
self.editor_shortcuts = ConversationDisplayShortcuts(self.app)
|
||||
|
||||
self.shortcuts_display = self.list_shortcuts
|
||||
self.widget = columns_widget
|
||||
|
||||
def display_conversation(self, sender=None, source_hash=None):
|
||||
|
@ -38,7 +78,6 @@ class ConversationsDisplay():
|
|||
|
||||
def make_conversation_widget(self, source_hash):
|
||||
time_format = self.app.time_format
|
||||
import urwid
|
||||
class LXMessageWidget(urwid.WidgetWrap):
|
||||
def __init__(self, message):
|
||||
title_string = time.strftime(time_format)
|
||||
|
@ -76,44 +115,26 @@ class ConversationsDisplay():
|
|||
|
||||
from nomadnet.vendor.additional_urwid_widgets import IndicativeListBox
|
||||
messagelist = IndicativeListBox(message_widgets)
|
||||
msg_editor = urwid.Edit(caption="\u270E", edit_text="", multiline=True)
|
||||
|
||||
widget = urwid.LineBox(
|
||||
urwid.Frame(
|
||||
messagelist,
|
||||
footer=urwid.AttrMap(urwid.Edit(caption="\u270E", edit_text=""), "msg_editor")
|
||||
footer=urwid.AttrMap(msg_editor, "msg_editor")
|
||||
)
|
||||
)
|
||||
|
||||
def disp_editor_shortcuts(sender, arg1, arg2):
|
||||
self.shortcuts_display = self.editor_shortcuts
|
||||
self.app.ui.main_display.update_active_shortcuts()
|
||||
|
||||
urwid.connect_signal(msg_editor, "change", disp_editor_shortcuts, "modified event")
|
||||
|
||||
ConversationsDisplay.cached_conversation_widgets[source_hash] = widget
|
||||
return widget
|
||||
|
||||
|
||||
def conversation_list_widget(self, conversation):
|
||||
import urwid
|
||||
|
||||
class ListEntry(urwid.Text):
|
||||
_selectable = True
|
||||
|
||||
signals = ["click"]
|
||||
|
||||
def keypress(self, size, key):
|
||||
"""
|
||||
Send 'click' signal on 'activate' command.
|
||||
"""
|
||||
if self._command_map[key] != urwid.ACTIVATE:
|
||||
return key
|
||||
|
||||
self._emit('click')
|
||||
|
||||
def mouse_event(self, size, event, button, x, y, focus):
|
||||
"""
|
||||
Send 'click' signal on button 1 press.
|
||||
"""
|
||||
if button != 1 or not urwid.util.is_mouse_press(event):
|
||||
return False
|
||||
|
||||
self._emit('click')
|
||||
return True
|
||||
|
||||
#widget = urwid.SelectableIcon(str(conversation), cursor_position=-1)
|
||||
widget = ListEntry(str(conversation))
|
||||
urwid.connect_signal(widget, "click", self.display_conversation, conversation)
|
||||
|
@ -121,4 +142,10 @@ class ConversationsDisplay():
|
|||
|
||||
|
||||
def shortcuts(self):
|
||||
return self.shortcuts_display
|
||||
focus_path = self.widget.get_focus_path()
|
||||
if focus_path[0] == 0:
|
||||
return self.list_shortcuts
|
||||
elif focus_path[0] == 1:
|
||||
return self.editor_shortcuts
|
||||
else:
|
||||
return self.list_shortcuts
|
Loading…
Add table
Add a link
Reference in a new issue