pymud 0.21.1__py3-none-any.whl → 0.21.2a1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pymud/__init__.py +16 -16
- pymud/__main__.py +3 -3
- pymud/decorators.py +234 -234
- pymud/dialogs.py +166 -166
- pymud/extras.py +930 -918
- pymud/i18n.py +62 -62
- pymud/lang/i18n_chs.py +226 -226
- pymud/lang/i18n_eng.py +850 -850
- pymud/logger.py +167 -167
- pymud/main.py +220 -220
- pymud/modules.py +285 -285
- pymud/objects.py +1032 -1032
- pymud/pkuxkx.py +280 -280
- pymud/protocol.py +1010 -1010
- pymud/pymud.py +1280 -1286
- pymud/session.py +3584 -3578
- pymud/settings.py +196 -196
- {pymud-0.21.1.dist-info → pymud-0.21.2a1.dist-info}/METADATA +477 -476
- pymud-0.21.2a1.dist-info/RECORD +23 -0
- {pymud-0.21.1.dist-info → pymud-0.21.2a1.dist-info}/WHEEL +1 -1
- {pymud-0.21.1.dist-info → pymud-0.21.2a1.dist-info}/licenses/LICENSE.txt +674 -674
- pymud-0.21.1.dist-info/RECORD +0 -23
- {pymud-0.21.1.dist-info → pymud-0.21.2a1.dist-info}/entry_points.txt +0 -0
- {pymud-0.21.1.dist-info → pymud-0.21.2a1.dist-info}/top_level.txt +0 -0
pymud/dialogs.py
CHANGED
@@ -1,167 +1,167 @@
|
|
1
|
-
import asyncio, webbrowser
|
2
|
-
from typing import Any, Callable, Iterable, List, Tuple, Union
|
3
|
-
from prompt_toolkit.layout import AnyContainer, ConditionalContainer, Float, VSplit, HSplit, Window, WindowAlign, ScrollablePane, ScrollOffsets
|
4
|
-
from prompt_toolkit.widgets import Button, Dialog, Label, MenuContainer, MenuItem, TextArea, SystemToolbar, Frame, RadioList
|
5
|
-
from prompt_toolkit.layout.dimension import Dimension, D
|
6
|
-
from prompt_toolkit import ANSI, HTML
|
7
|
-
from prompt_toolkit.mouse_events import MouseEvent, MouseEventType
|
8
|
-
from prompt_toolkit.formatted_text import FormattedText, AnyFormattedText
|
9
|
-
from prompt_toolkit.application.current import get_app
|
10
|
-
from .extras import EasternButton
|
11
|
-
|
12
|
-
from .settings import Settings
|
13
|
-
|
14
|
-
class BasicDialog:
|
15
|
-
def __init__(self, title: AnyFormattedText = "", modal = True):
|
16
|
-
self.future = asyncio.Future()
|
17
|
-
self.dialog = Dialog(
|
18
|
-
body = self.create_body(),
|
19
|
-
title = title,
|
20
|
-
buttons = self.create_buttons(),
|
21
|
-
modal = modal,
|
22
|
-
width = D(preferred=80),
|
23
|
-
)
|
24
|
-
|
25
|
-
def set_done(self, result: Any = True):
|
26
|
-
self.future.set_result(result)
|
27
|
-
|
28
|
-
def create_body(self) -> AnyContainer:
|
29
|
-
return HSplit([Label(text=Settings.gettext("basic_dialog"))])
|
30
|
-
|
31
|
-
def create_buttons(self):
|
32
|
-
ok_button = EasternButton(text=Settings.gettext("ok"), handler=(lambda: self.set_done()))
|
33
|
-
return [ok_button]
|
34
|
-
|
35
|
-
def set_exception(self, exc):
|
36
|
-
self.future.set_exception(exc)
|
37
|
-
|
38
|
-
def __pt_container__(self):
|
39
|
-
return self.dialog
|
40
|
-
|
41
|
-
class MessageDialog(BasicDialog):
|
42
|
-
def __init__(self, title="", message = "", modal=True):
|
43
|
-
self.message = message
|
44
|
-
super().__init__(title, modal)
|
45
|
-
|
46
|
-
def create_body(self) -> AnyContainer:
|
47
|
-
return HSplit([Label(text=self.message)])
|
48
|
-
|
49
|
-
class QueryDialog(BasicDialog):
|
50
|
-
def __init__(self, title: AnyFormattedText = "", message: AnyFormattedText = "", modal = True):
|
51
|
-
self.message = message
|
52
|
-
super().__init__(title, modal)
|
53
|
-
|
54
|
-
def create_body(self) -> AnyContainer:
|
55
|
-
return HSplit([Label(text=self.message)])
|
56
|
-
|
57
|
-
def create_buttons(self):
|
58
|
-
ok_button = EasternButton(text=Settings.gettext("ok"), handler=(lambda: self.set_done(True)))
|
59
|
-
cancel_button = EasternButton(text=Settings.gettext("cancel"), handler=(lambda: self.set_done(False)))
|
60
|
-
return [ok_button, cancel_button]
|
61
|
-
|
62
|
-
class WelcomeDialog(BasicDialog):
|
63
|
-
def __init__(self, modal=True):
|
64
|
-
self.website = FormattedText(
|
65
|
-
[('', f'{Settings.gettext("visit")} '),
|
66
|
-
#('class:b', 'GitHub:'),
|
67
|
-
('', Settings.__website__, self.open_url),
|
68
|
-
('', f' {Settings.gettext("displayhelp")}')]
|
69
|
-
)
|
70
|
-
super().__init__("PYMUD", modal)
|
71
|
-
|
72
|
-
def open_url(self, event: MouseEvent):
|
73
|
-
if event.event_type == MouseEventType.MOUSE_UP:
|
74
|
-
webbrowser.open(Settings.__website__)
|
75
|
-
|
76
|
-
def create_body(self) -> AnyContainer:
|
77
|
-
import platform, sys
|
78
|
-
body = HSplit([
|
79
|
-
Window(height=1),
|
80
|
-
Label(HTML(Settings.gettext("appinfo", Settings.__version__, Settings.__release__)), align=WindowAlign.CENTER),
|
81
|
-
Label(HTML(Settings.gettext("author", Settings.__author__, Settings.__email__)), align=WindowAlign.CENTER),
|
82
|
-
Label(self.website, align=WindowAlign.CENTER),
|
83
|
-
Label(Settings.gettext("sysversion", platform.system(), platform.version(), platform.python_version()), align = WindowAlign.CENTER),
|
84
|
-
|
85
|
-
Window(height=1),
|
86
|
-
])
|
87
|
-
|
88
|
-
return body
|
89
|
-
|
90
|
-
class NewSessionDialog(BasicDialog):
|
91
|
-
def __init__(self):
|
92
|
-
super().__init__(Settings.gettext("new_session"), True)
|
93
|
-
|
94
|
-
def create_body(self) -> AnyContainer:
|
95
|
-
body = HSplit([
|
96
|
-
VSplit([
|
97
|
-
HSplit([
|
98
|
-
Label(f" {Settings.gettext('sessionname')}:"),
|
99
|
-
Frame(body=TextArea(name = "session", text="session", multiline=False, wrap_lines=False, height = 1, dont_extend_height=True, width = D(preferred=10), focus_on_click=True, read_only=False),)
|
100
|
-
]),
|
101
|
-
HSplit([
|
102
|
-
Label(f" {Settings.gettext('host')}:"),
|
103
|
-
Frame(body=TextArea(name = "host", text="mud.pkuxkx.net", multiline=False, wrap_lines=False, height = 1, dont_extend_height=True, width = D(preferred=20), focus_on_click=True, read_only=False),)
|
104
|
-
]),
|
105
|
-
HSplit([
|
106
|
-
Label(f" {Settings.gettext('port')}:"),
|
107
|
-
Frame(body=TextArea(name = "port", text="8081", multiline=False, wrap_lines=False, height = 1, dont_extend_height=True, width = D(max=8), focus_on_click=True, read_only=False),)
|
108
|
-
]),
|
109
|
-
HSplit([
|
110
|
-
Label(f" {Settings.gettext('encoding')}:"),
|
111
|
-
Frame(body=TextArea(name = "encoding", text="utf8", multiline=False, wrap_lines=False, height = 1, dont_extend_height=True, width = D(max=8), focus_on_click=True, read_only=False),)
|
112
|
-
]),
|
113
|
-
])
|
114
|
-
])
|
115
|
-
|
116
|
-
return body
|
117
|
-
|
118
|
-
def create_buttons(self):
|
119
|
-
ok_button = EasternButton(text=Settings.gettext("ok"), handler=self.btn_ok_clicked)
|
120
|
-
cancel_button = EasternButton(text=Settings.gettext("cancel"), handler=(lambda: self.set_done(False)))
|
121
|
-
return [ok_button, cancel_button]
|
122
|
-
|
123
|
-
def btn_ok_clicked(self):
|
124
|
-
def get_text_safely(buffer_name):
|
125
|
-
buffer = get_app().layout.get_buffer_by_name(buffer_name)
|
126
|
-
return buffer.text if buffer else ""
|
127
|
-
name = get_text_safely("session")
|
128
|
-
host = get_text_safely("host")
|
129
|
-
port = get_text_safely("port")
|
130
|
-
encoding = get_text_safely("encoding")
|
131
|
-
result = (name, host, port, encoding)
|
132
|
-
self.set_done(result)
|
133
|
-
|
134
|
-
|
135
|
-
class LogSelectionDialog(BasicDialog):
|
136
|
-
def __init__(self, text, values, modal=True):
|
137
|
-
self._header_text = text
|
138
|
-
self._selection_values = values
|
139
|
-
self._itemsCount = len(values)
|
140
|
-
if len(values) > 0:
|
141
|
-
self._radio_list = RadioList(values = self._selection_values)
|
142
|
-
else:
|
143
|
-
self._radio_list = Label(Settings.gettext("nolog").center(13))
|
144
|
-
super().__init__(Settings.gettext("chooselog"), modal)
|
145
|
-
|
146
|
-
def create_body(self) -> AnyContainer:
|
147
|
-
body=HSplit([
|
148
|
-
Label(text = self._header_text, dont_extend_height=True),
|
149
|
-
self._radio_list
|
150
|
-
])
|
151
|
-
return body
|
152
|
-
|
153
|
-
def create_buttons(self):
|
154
|
-
ok_button = EasternButton(text=Settings.gettext("ok"), handler=self.btn_ok_clicked)
|
155
|
-
cancel_button = EasternButton(text=Settings.gettext("cancel"), handler=(lambda: self.set_done(False)))
|
156
|
-
return [ok_button, cancel_button]
|
157
|
-
|
158
|
-
def btn_ok_clicked(self):
|
159
|
-
if self._itemsCount:
|
160
|
-
if isinstance(self._radio_list, RadioList):
|
161
|
-
result = self._radio_list.current_value
|
162
|
-
else:
|
163
|
-
result = None
|
164
|
-
self.set_done(result)
|
165
|
-
else:
|
166
|
-
self.set_done(False)
|
1
|
+
import asyncio, webbrowser
|
2
|
+
from typing import Any, Callable, Iterable, List, Tuple, Union
|
3
|
+
from prompt_toolkit.layout import AnyContainer, ConditionalContainer, Float, VSplit, HSplit, Window, WindowAlign, ScrollablePane, ScrollOffsets
|
4
|
+
from prompt_toolkit.widgets import Button, Dialog, Label, MenuContainer, MenuItem, TextArea, SystemToolbar, Frame, RadioList
|
5
|
+
from prompt_toolkit.layout.dimension import Dimension, D
|
6
|
+
from prompt_toolkit import ANSI, HTML
|
7
|
+
from prompt_toolkit.mouse_events import MouseEvent, MouseEventType
|
8
|
+
from prompt_toolkit.formatted_text import FormattedText, AnyFormattedText
|
9
|
+
from prompt_toolkit.application.current import get_app
|
10
|
+
from .extras import EasternButton
|
11
|
+
|
12
|
+
from .settings import Settings
|
13
|
+
|
14
|
+
class BasicDialog:
|
15
|
+
def __init__(self, title: AnyFormattedText = "", modal = True):
|
16
|
+
self.future = asyncio.Future()
|
17
|
+
self.dialog = Dialog(
|
18
|
+
body = self.create_body(),
|
19
|
+
title = title,
|
20
|
+
buttons = self.create_buttons(),
|
21
|
+
modal = modal,
|
22
|
+
width = D(preferred=80),
|
23
|
+
)
|
24
|
+
|
25
|
+
def set_done(self, result: Any = True):
|
26
|
+
self.future.set_result(result)
|
27
|
+
|
28
|
+
def create_body(self) -> AnyContainer:
|
29
|
+
return HSplit([Label(text=Settings.gettext("basic_dialog"))])
|
30
|
+
|
31
|
+
def create_buttons(self):
|
32
|
+
ok_button = EasternButton(text=Settings.gettext("ok"), handler=(lambda: self.set_done()))
|
33
|
+
return [ok_button]
|
34
|
+
|
35
|
+
def set_exception(self, exc):
|
36
|
+
self.future.set_exception(exc)
|
37
|
+
|
38
|
+
def __pt_container__(self):
|
39
|
+
return self.dialog
|
40
|
+
|
41
|
+
class MessageDialog(BasicDialog):
|
42
|
+
def __init__(self, title="", message = "", modal=True):
|
43
|
+
self.message = message
|
44
|
+
super().__init__(title, modal)
|
45
|
+
|
46
|
+
def create_body(self) -> AnyContainer:
|
47
|
+
return HSplit([Label(text=self.message)])
|
48
|
+
|
49
|
+
class QueryDialog(BasicDialog):
|
50
|
+
def __init__(self, title: AnyFormattedText = "", message: AnyFormattedText = "", modal = True):
|
51
|
+
self.message = message
|
52
|
+
super().__init__(title, modal)
|
53
|
+
|
54
|
+
def create_body(self) -> AnyContainer:
|
55
|
+
return HSplit([Label(text=self.message)])
|
56
|
+
|
57
|
+
def create_buttons(self):
|
58
|
+
ok_button = EasternButton(text=Settings.gettext("ok"), handler=(lambda: self.set_done(True)))
|
59
|
+
cancel_button = EasternButton(text=Settings.gettext("cancel"), handler=(lambda: self.set_done(False)))
|
60
|
+
return [ok_button, cancel_button]
|
61
|
+
|
62
|
+
class WelcomeDialog(BasicDialog):
|
63
|
+
def __init__(self, modal=True):
|
64
|
+
self.website = FormattedText(
|
65
|
+
[('', f'{Settings.gettext("visit")} '),
|
66
|
+
#('class:b', 'GitHub:'),
|
67
|
+
('', Settings.__website__, self.open_url),
|
68
|
+
('', f' {Settings.gettext("displayhelp")}')]
|
69
|
+
)
|
70
|
+
super().__init__("PYMUD", modal)
|
71
|
+
|
72
|
+
def open_url(self, event: MouseEvent):
|
73
|
+
if event.event_type == MouseEventType.MOUSE_UP:
|
74
|
+
webbrowser.open(Settings.__website__)
|
75
|
+
|
76
|
+
def create_body(self) -> AnyContainer:
|
77
|
+
import platform, sys
|
78
|
+
body = HSplit([
|
79
|
+
Window(height=1),
|
80
|
+
Label(HTML(Settings.gettext("appinfo", Settings.__version__, Settings.__release__)), align=WindowAlign.CENTER),
|
81
|
+
Label(HTML(Settings.gettext("author", Settings.__author__, Settings.__email__)), align=WindowAlign.CENTER),
|
82
|
+
Label(self.website, align=WindowAlign.CENTER),
|
83
|
+
Label(Settings.gettext("sysversion", platform.system(), platform.version(), platform.python_version()), align = WindowAlign.CENTER),
|
84
|
+
|
85
|
+
Window(height=1),
|
86
|
+
])
|
87
|
+
|
88
|
+
return body
|
89
|
+
|
90
|
+
class NewSessionDialog(BasicDialog):
|
91
|
+
def __init__(self):
|
92
|
+
super().__init__(Settings.gettext("new_session"), True)
|
93
|
+
|
94
|
+
def create_body(self) -> AnyContainer:
|
95
|
+
body = HSplit([
|
96
|
+
VSplit([
|
97
|
+
HSplit([
|
98
|
+
Label(f" {Settings.gettext('sessionname')}:"),
|
99
|
+
Frame(body=TextArea(name = "session", text="session", multiline=False, wrap_lines=False, height = 1, dont_extend_height=True, width = D(preferred=10), focus_on_click=True, read_only=False),)
|
100
|
+
]),
|
101
|
+
HSplit([
|
102
|
+
Label(f" {Settings.gettext('host')}:"),
|
103
|
+
Frame(body=TextArea(name = "host", text="mud.pkuxkx.net", multiline=False, wrap_lines=False, height = 1, dont_extend_height=True, width = D(preferred=20), focus_on_click=True, read_only=False),)
|
104
|
+
]),
|
105
|
+
HSplit([
|
106
|
+
Label(f" {Settings.gettext('port')}:"),
|
107
|
+
Frame(body=TextArea(name = "port", text="8081", multiline=False, wrap_lines=False, height = 1, dont_extend_height=True, width = D(max=8), focus_on_click=True, read_only=False),)
|
108
|
+
]),
|
109
|
+
HSplit([
|
110
|
+
Label(f" {Settings.gettext('encoding')}:"),
|
111
|
+
Frame(body=TextArea(name = "encoding", text="utf8", multiline=False, wrap_lines=False, height = 1, dont_extend_height=True, width = D(max=8), focus_on_click=True, read_only=False),)
|
112
|
+
]),
|
113
|
+
])
|
114
|
+
])
|
115
|
+
|
116
|
+
return body
|
117
|
+
|
118
|
+
def create_buttons(self):
|
119
|
+
ok_button = EasternButton(text=Settings.gettext("ok"), handler=self.btn_ok_clicked)
|
120
|
+
cancel_button = EasternButton(text=Settings.gettext("cancel"), handler=(lambda: self.set_done(False)))
|
121
|
+
return [ok_button, cancel_button]
|
122
|
+
|
123
|
+
def btn_ok_clicked(self):
|
124
|
+
def get_text_safely(buffer_name):
|
125
|
+
buffer = get_app().layout.get_buffer_by_name(buffer_name)
|
126
|
+
return buffer.text if buffer else ""
|
127
|
+
name = get_text_safely("session")
|
128
|
+
host = get_text_safely("host")
|
129
|
+
port = get_text_safely("port")
|
130
|
+
encoding = get_text_safely("encoding")
|
131
|
+
result = (name, host, port, encoding)
|
132
|
+
self.set_done(result)
|
133
|
+
|
134
|
+
|
135
|
+
class LogSelectionDialog(BasicDialog):
|
136
|
+
def __init__(self, text, values, modal=True):
|
137
|
+
self._header_text = text
|
138
|
+
self._selection_values = values
|
139
|
+
self._itemsCount = len(values)
|
140
|
+
if len(values) > 0:
|
141
|
+
self._radio_list = RadioList(values = self._selection_values)
|
142
|
+
else:
|
143
|
+
self._radio_list = Label(Settings.gettext("nolog").center(13))
|
144
|
+
super().__init__(Settings.gettext("chooselog"), modal)
|
145
|
+
|
146
|
+
def create_body(self) -> AnyContainer:
|
147
|
+
body=HSplit([
|
148
|
+
Label(text = self._header_text, dont_extend_height=True),
|
149
|
+
self._radio_list
|
150
|
+
])
|
151
|
+
return body
|
152
|
+
|
153
|
+
def create_buttons(self):
|
154
|
+
ok_button = EasternButton(text=Settings.gettext("ok"), handler=self.btn_ok_clicked)
|
155
|
+
cancel_button = EasternButton(text=Settings.gettext("cancel"), handler=(lambda: self.set_done(False)))
|
156
|
+
return [ok_button, cancel_button]
|
157
|
+
|
158
|
+
def btn_ok_clicked(self):
|
159
|
+
if self._itemsCount:
|
160
|
+
if isinstance(self._radio_list, RadioList):
|
161
|
+
result = self._radio_list.current_value
|
162
|
+
else:
|
163
|
+
result = None
|
164
|
+
self.set_done(result)
|
165
|
+
else:
|
166
|
+
self.set_done(False)
|
167
167
|
|