pymud 0.20.2a5__py3-none-any.whl → 0.20.3__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 CHANGED
@@ -1,12 +1,12 @@
1
- from .settings import Settings
2
- from .pymud import PyMudApp
3
- from .modules import IConfig
4
- from .objects import CodeBlock, Alias, SimpleAlias, Trigger, SimpleTrigger, Command, SimpleCommand, Timer, SimpleTimer, GMCPTrigger
5
- from .extras import DotDict
6
- from .session import Session
7
- from .logger import Logger
8
- from .main import main
9
-
10
- __all__ = [
11
- "IConfig", "PyMudApp", "Settings", "CodeBlock", "Alias", "SimpleAlias", "Trigger", "SimpleTrigger", "Command", "SimpleCommand", "Timer", "SimpleTimer", "GMCPTrigger", "Session", "PyMudApp", "DotDict", "Logger", "main"
1
+ from .settings import Settings
2
+ from .pymud import PyMudApp
3
+ from .modules import IConfig
4
+ from .objects import CodeBlock, Alias, SimpleAlias, Trigger, SimpleTrigger, Command, SimpleCommand, Timer, SimpleTimer, GMCPTrigger
5
+ from .extras import DotDict
6
+ from .session import Session
7
+ from .logger import Logger
8
+ from .main import main
9
+
10
+ __all__ = [
11
+ "IConfig", "PyMudApp", "Settings", "CodeBlock", "Alias", "SimpleAlias", "Trigger", "SimpleTrigger", "Command", "SimpleCommand", "Timer", "SimpleTimer", "GMCPTrigger", "Session", "PyMudApp", "DotDict", "Logger", "main"
12
12
  ]
pymud/__main__.py CHANGED
@@ -1,4 +1,4 @@
1
- from .main import main
2
-
3
- if __name__ == "__main__":
1
+ from .main import main
2
+
3
+ if __name__ == "__main__":
4
4
  main()
pymud/dialogs.py CHANGED
@@ -1,161 +1,161 @@
1
- import asyncio, webbrowser
2
-
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
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 = "", 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 = True):
26
- self.future.set_result(result)
27
-
28
- def create_body(self) -> AnyContainer:
29
- return HSplit([Label(text="basic dialog")])
30
-
31
- def create_buttons(self):
32
- ok_button = EasternButton(text="确定", 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="", message = "", 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="确定", handler=(lambda: self.set_done(True)))
59
- cancel_button = EasternButton(text="取消", 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
- [('', '访问 '),
66
- #('class:b', 'GitHub:'),
67
- ('', 'https://pymud.readthedocs.org/', self.open_url),
68
- ('', ' 以查看最新帮助文档')]
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('<b fg="red">PYMUD {0}</b> - a MUD Client Written in Python'.format(Settings.__version__, Settings.__release__)), align=WindowAlign.CENTER),
81
- Label(HTML('作者: <b>{0}</b> <b>E-mail</b>: <u>{1}</u>'.format(Settings.__author__, Settings.__email__)), align=WindowAlign.CENTER),
82
- Label(self.website, align=WindowAlign.CENTER),
83
- Label('系统:{} {} Python版本:{}'.format(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__("创建新会话", True)
93
-
94
- def create_body(self) -> AnyContainer:
95
- body = HSplit([
96
- VSplit([
97
- HSplit([
98
- Label(" 会话名称:"),
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(" 服务器地址:"),
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(" 端口:"),
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(" 编码:"),
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="确定", handler=self.btn_ok_clicked)
120
- cancel_button = EasternButton(text="取消", handler=(lambda: self.set_done(False)))
121
- return [ok_button, cancel_button]
122
-
123
- def btn_ok_clicked(self):
124
- name = get_app().layout.get_buffer_by_name("session").text
125
- host = get_app().layout.get_buffer_by_name("host").text
126
- port = int(get_app().layout.get_buffer_by_name("port").text)
127
- encoding = get_app().layout.get_buffer_by_name("encoding").text
128
- result = (name, host, port, encoding)
129
- self.set_done(result)
130
-
131
-
132
- class LogSelectionDialog(BasicDialog):
133
- def __init__(self, text, values, modal=True):
134
- self._header_text = text
135
- self._selection_values = values
136
- self._itemsCount = len(values)
137
- if len(values) > 0:
138
- self._radio_list = RadioList(values = self._selection_values)
139
- else:
140
- self._radio_list = Label('无记录'.center(13))
141
- super().__init__('选择查看的记录', modal)
142
-
143
- def create_body(self) -> AnyContainer:
144
- body=HSplit([
145
- Label(text = self._header_text, dont_extend_height=True),
146
- self._radio_list
147
- ])
148
- return body
149
-
150
- def create_buttons(self):
151
- ok_button = EasternButton(text="确定", handler=self.btn_ok_clicked)
152
- cancel_button = EasternButton(text="取消", handler=(lambda: self.set_done(False)))
153
- return [ok_button, cancel_button]
154
-
155
- def btn_ok_clicked(self):
156
- if self._itemsCount:
157
- result = self._radio_list.current_value
158
- self.set_done(result)
159
- else:
160
- self.set_done(False)
1
+ import asyncio, webbrowser
2
+
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
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 = "", 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 = True):
26
+ self.future.set_result(result)
27
+
28
+ def create_body(self) -> AnyContainer:
29
+ return HSplit([Label(text="basic dialog")])
30
+
31
+ def create_buttons(self):
32
+ ok_button = EasternButton(text="确定", 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="", message = "", 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="确定", handler=(lambda: self.set_done(True)))
59
+ cancel_button = EasternButton(text="取消", 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
+ [('', '访问 '),
66
+ #('class:b', 'GitHub:'),
67
+ ('', 'https://pymud.readthedocs.org/', self.open_url),
68
+ ('', ' 以查看最新帮助文档')]
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('<b fg="red">PYMUD {0}</b> - a MUD Client Written in Python'.format(Settings.__version__, Settings.__release__)), align=WindowAlign.CENTER),
81
+ Label(HTML('作者: <b>{0}</b> <b>E-mail</b>: <u>{1}</u>'.format(Settings.__author__, Settings.__email__)), align=WindowAlign.CENTER),
82
+ Label(self.website, align=WindowAlign.CENTER),
83
+ Label('系统:{} {} Python版本:{}'.format(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__("创建新会话", True)
93
+
94
+ def create_body(self) -> AnyContainer:
95
+ body = HSplit([
96
+ VSplit([
97
+ HSplit([
98
+ Label(" 会话名称:"),
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(" 服务器地址:"),
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(" 端口:"),
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(" 编码:"),
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="确定", handler=self.btn_ok_clicked)
120
+ cancel_button = EasternButton(text="取消", handler=(lambda: self.set_done(False)))
121
+ return [ok_button, cancel_button]
122
+
123
+ def btn_ok_clicked(self):
124
+ name = get_app().layout.get_buffer_by_name("session").text
125
+ host = get_app().layout.get_buffer_by_name("host").text
126
+ port = int(get_app().layout.get_buffer_by_name("port").text)
127
+ encoding = get_app().layout.get_buffer_by_name("encoding").text
128
+ result = (name, host, port, encoding)
129
+ self.set_done(result)
130
+
131
+
132
+ class LogSelectionDialog(BasicDialog):
133
+ def __init__(self, text, values, modal=True):
134
+ self._header_text = text
135
+ self._selection_values = values
136
+ self._itemsCount = len(values)
137
+ if len(values) > 0:
138
+ self._radio_list = RadioList(values = self._selection_values)
139
+ else:
140
+ self._radio_list = Label('无记录'.center(13))
141
+ super().__init__('选择查看的记录', modal)
142
+
143
+ def create_body(self) -> AnyContainer:
144
+ body=HSplit([
145
+ Label(text = self._header_text, dont_extend_height=True),
146
+ self._radio_list
147
+ ])
148
+ return body
149
+
150
+ def create_buttons(self):
151
+ ok_button = EasternButton(text="确定", handler=self.btn_ok_clicked)
152
+ cancel_button = EasternButton(text="取消", handler=(lambda: self.set_done(False)))
153
+ return [ok_button, cancel_button]
154
+
155
+ def btn_ok_clicked(self):
156
+ if self._itemsCount:
157
+ result = self._radio_list.current_value
158
+ self.set_done(result)
159
+ else:
160
+ self.set_done(False)
161
161