Use new config system
This commit is contained in:
parent
bc203aaff1
commit
6c4bfe2752
3 changed files with 34 additions and 19 deletions
|
|
@ -91,6 +91,10 @@ class Config:
|
||||||
def view(self) -> "ConfigView":
|
def view(self) -> "ConfigView":
|
||||||
return ConfigView(self.tree)
|
return ConfigView(self.tree)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def v(self) -> "ConfigView":
|
||||||
|
return self.view
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def tree(self) -> Any:
|
def tree(self) -> Any:
|
||||||
both = dict(self.default_fields)
|
both = dict(self.default_fields)
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
from typing import Any, List
|
from typing import Any, List, Optional
|
||||||
|
|
||||||
import urwid
|
import urwid
|
||||||
|
|
||||||
import yaboli
|
import yaboli
|
||||||
|
|
||||||
from .palette import Style
|
from ..config import Config
|
||||||
from ..markup import AT
|
from ..markup import AT
|
||||||
from ..widgets import ATWidget
|
from ..widgets import ATWidget
|
||||||
|
|
||||||
|
|
@ -30,7 +29,8 @@ class RoomWidget(urwid.WidgetWrap):
|
||||||
event
|
event
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, roomname: str) -> None:
|
def __init__(self, config: Config, roomname: str) -> None:
|
||||||
|
self.c = config
|
||||||
self._room = yaboli.Room(roomname)
|
self._room = yaboli.Room(roomname)
|
||||||
|
|
||||||
super().__init__(self._connecting_widget())
|
super().__init__(self._connecting_widget())
|
||||||
|
|
@ -38,19 +38,19 @@ class RoomWidget(urwid.WidgetWrap):
|
||||||
|
|
||||||
def _connecting_widget(self) -> Any:
|
def _connecting_widget(self) -> Any:
|
||||||
lines = [AT("Connecting to ")
|
lines = [AT("Connecting to ")
|
||||||
+ AT("&" + self.room.name, style=Style.ROOM)
|
+ AT("&" + self.room.name, style=self.c.v.element.room)
|
||||||
+ AT("...")]
|
+ AT("...")]
|
||||||
return CenteredTextWidget(lines)
|
return CenteredTextWidget(lines)
|
||||||
|
|
||||||
def _connected_widget(self) -> Any:
|
def _connected_widget(self) -> Any:
|
||||||
lines = [AT("Connected to ")
|
lines = [AT("Connected to ")
|
||||||
+ AT("&" + self.room.name, style=Style.ROOM)
|
+ AT("&" + self.room.name, style=self.c.v.element.room)
|
||||||
+ AT(".")]
|
+ AT(".")]
|
||||||
return CenteredTextWidget(lines)
|
return CenteredTextWidget(lines)
|
||||||
|
|
||||||
def _connection_failed_widget(self) -> Any:
|
def _connection_failed_widget(self) -> Any:
|
||||||
lines = [AT("Could not connect to ")
|
lines = [AT("Could not connect to ")
|
||||||
+ AT("&" + self.room.name, style=Style.ROOM)
|
+ AT("&" + self.room.name, style=self.c.v.element.room)
|
||||||
+ AT(".")]
|
+ AT(".")]
|
||||||
return CenteredTextWidget(lines)
|
return CenteredTextWidget(lines)
|
||||||
|
|
||||||
|
|
@ -73,7 +73,10 @@ class RoomWidget(urwid.WidgetWrap):
|
||||||
|
|
||||||
# Handle input
|
# Handle input
|
||||||
|
|
||||||
def selectable(self) -> bool:
|
#def selectable(self) -> bool:
|
||||||
return True
|
# return True
|
||||||
|
|
||||||
|
#def keypress(self, size: Any, key: str) -> Optional[str]:
|
||||||
|
# pass
|
||||||
|
|
||||||
urwid.register_signal(RoomWidget, ["close"])
|
urwid.register_signal(RoomWidget, ["close"])
|
||||||
|
|
|
||||||
|
|
@ -2,19 +2,21 @@ from typing import Any, Optional
|
||||||
|
|
||||||
import urwid
|
import urwid
|
||||||
|
|
||||||
from .palette import Style
|
from ..config import Config
|
||||||
from .room_widget import RoomWidget
|
from .room_widget import RoomWidget
|
||||||
|
|
||||||
__all__ = ["SingleRoomApplication"]
|
__all__ = ["SingleRoomApplication"]
|
||||||
|
|
||||||
class ChooseRoomWidget(urwid.WidgetWrap):
|
class ChooseRoomWidget(urwid.WidgetWrap):
|
||||||
def __init__(self) -> None:
|
def __init__(self, config: Config) -> None:
|
||||||
|
self.c = config
|
||||||
|
|
||||||
self.error = None
|
self.error = None
|
||||||
self.text = urwid.Text("Choose a room:", align=urwid.CENTER)
|
self.text = urwid.Text("Choose a room:", align=urwid.CENTER)
|
||||||
self.edit = urwid.Edit("&", align=urwid.CENTER)
|
self.edit = urwid.Edit("&", align=urwid.CENTER)
|
||||||
self.pile = urwid.Pile([
|
self.pile = urwid.Pile([
|
||||||
self.text,
|
self.text,
|
||||||
urwid.AttrMap(self.edit, Style.ROOM),
|
urwid.AttrMap(self.edit, self.c.v.element.room),
|
||||||
])
|
])
|
||||||
self.filler = urwid.Filler(self.pile)
|
self.filler = urwid.Filler(self.pile)
|
||||||
super().__init__(self.filler)
|
super().__init__(self.filler)
|
||||||
|
|
@ -32,7 +34,7 @@ class ChooseRoomWidget(urwid.WidgetWrap):
|
||||||
self.pile = urwid.Pile([
|
self.pile = urwid.Pile([
|
||||||
self.error,
|
self.error,
|
||||||
self.text,
|
self.text,
|
||||||
urwid.AttrMap(self.edit, Style.ROOM),
|
urwid.AttrMap(self.edit, self.c.v.element.room),
|
||||||
])
|
])
|
||||||
self.filler = urwid.Filler(self.pile)
|
self.filler = urwid.Filler(self.pile)
|
||||||
self._w = self.filler
|
self._w = self.filler
|
||||||
|
|
@ -41,7 +43,7 @@ class ChooseRoomWidget(urwid.WidgetWrap):
|
||||||
self.error = None
|
self.error = None
|
||||||
self.pile = urwid.Pile([
|
self.pile = urwid.Pile([
|
||||||
self.text,
|
self.text,
|
||||||
urwid.AttrMap(self.edit, Style.ROOM),
|
urwid.AttrMap(self.edit, self.c.v.element.room),
|
||||||
])
|
])
|
||||||
self.filler = urwid.Filler(self.pile)
|
self.filler = urwid.Filler(self.pile)
|
||||||
self._w = self.filler
|
self._w = self.filler
|
||||||
|
|
@ -49,7 +51,7 @@ class ChooseRoomWidget(urwid.WidgetWrap):
|
||||||
def could_not_connect(self, roomname: str) -> None:
|
def could_not_connect(self, roomname: str) -> None:
|
||||||
text = [
|
text = [
|
||||||
"Could not connect to ",
|
"Could not connect to ",
|
||||||
(Style.ROOM, "&" + roomname),
|
(self.c.v.element.room, "&" + roomname),
|
||||||
".\n",
|
".\n",
|
||||||
]
|
]
|
||||||
self.set_error(text)
|
self.set_error(text)
|
||||||
|
|
@ -71,8 +73,10 @@ class SingleRoomApplication(urwid.WidgetWrap):
|
||||||
"home", "end",
|
"home", "end",
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self, config: Config) -> None:
|
||||||
self.choose_room = ChooseRoomWidget()
|
self.c = config
|
||||||
|
|
||||||
|
self.choose_room = ChooseRoomWidget(self.c)
|
||||||
super().__init__(self.choose_room)
|
super().__init__(self.choose_room)
|
||||||
|
|
||||||
def selectable(self) -> bool:
|
def selectable(self) -> bool:
|
||||||
|
|
@ -93,13 +97,15 @@ class SingleRoomApplication(urwid.WidgetWrap):
|
||||||
roomname = self.choose_room.edit.edit_text
|
roomname = self.choose_room.edit.edit_text
|
||||||
|
|
||||||
if roomname:
|
if roomname:
|
||||||
room = RoomWidget(roomname)
|
room = RoomWidget(self.c, roomname)
|
||||||
urwid.connect_signal(room, "close", self.switch_to_choose)
|
urwid.connect_signal(room, "close", self.switch_to_choose)
|
||||||
room.connect()
|
room.connect()
|
||||||
self._w = room
|
self._w = room
|
||||||
else:
|
else:
|
||||||
self.choose_room.invalid_room_name("too short")
|
self.choose_room.invalid_room_name("too short")
|
||||||
|
|
||||||
|
elif not super().selectable():
|
||||||
|
return key
|
||||||
# Make sure we only enter valid room names
|
# Make sure we only enter valid room names
|
||||||
elif key.lower() in self.ALPHABET:
|
elif key.lower() in self.ALPHABET:
|
||||||
return super().keypress(size, key.lower())
|
return super().keypress(size, key.lower())
|
||||||
|
|
@ -108,5 +114,7 @@ class SingleRoomApplication(urwid.WidgetWrap):
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
else:
|
elif super().selectable():
|
||||||
return super().keypress(size, key)
|
return super().keypress(size, key)
|
||||||
|
|
||||||
|
return key
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue