mirror of
https://github.com/paul-nameless/tg
synced 2024-11-22 03:43:19 +00:00
Implement simple resizing
This commit is contained in:
parent
4986d39987
commit
473f96902f
2 changed files with 60 additions and 14 deletions
|
@ -19,18 +19,15 @@ class Controller:
|
|||
self.lock = threading.Lock()
|
||||
|
||||
def init(self):
|
||||
self.view.draw_chats(
|
||||
self.model.current_chat,
|
||||
self.model.get_chats()
|
||||
)
|
||||
msgs = self.model.get_current_msgs()
|
||||
self.view.draw_msgs(self.model.get_current_msg(), msgs)
|
||||
pass
|
||||
# self.refresh_chats()
|
||||
# self.refresh_msgs()
|
||||
|
||||
def run(self):
|
||||
try:
|
||||
self.handle()
|
||||
except Exception as e:
|
||||
logger.exception('Error happened on run')
|
||||
logger.exception('Error happened in main loop')
|
||||
|
||||
# def send_msg(self):
|
||||
# import curses
|
||||
|
@ -68,6 +65,12 @@ class Controller:
|
|||
# self.view.draw_msgs(msgs)
|
||||
|
||||
def handle_msgs(self):
|
||||
# set width to 0.25, move window to left
|
||||
# refresh everything
|
||||
self.view.chats.resize(0.25)
|
||||
self.view.msgs.resize(0.25)
|
||||
self.refresh_chats()
|
||||
|
||||
while True:
|
||||
|
||||
key = self.view.get_key(self.view.chats.h, self.view.chats.w)
|
||||
|
@ -86,6 +89,12 @@ class Controller:
|
|||
elif key == 'k':
|
||||
if self.model.prev_msg():
|
||||
self.refresh_msgs()
|
||||
elif key == 'G':
|
||||
# move to the bottom
|
||||
pass
|
||||
elif key == 'gg':
|
||||
# move to the top
|
||||
pass
|
||||
elif key == 'e':
|
||||
# edit msg
|
||||
pass
|
||||
|
@ -107,14 +116,18 @@ class Controller:
|
|||
self.model.current_chat,
|
||||
self.model.get_chats()
|
||||
)
|
||||
msgs = self.model.get_current_msgs()
|
||||
self.view.draw_msgs(self.model.get_current_msg(), msgs)
|
||||
self.refresh_msgs()
|
||||
|
||||
def refresh_msgs(self):
|
||||
msgs = self.model.get_current_msgs()
|
||||
self.view.draw_msgs(self.model.get_current_msg(), msgs)
|
||||
|
||||
def handle_chats(self):
|
||||
# set width to 0.5, move window to center?
|
||||
# refresh everything
|
||||
self.view.chats.resize(0.5)
|
||||
self.view.msgs.resize(0.5)
|
||||
self.refresh_chats()
|
||||
while True:
|
||||
|
||||
key = self.view.get_key(self.view.chats.h, self.view.chats.w)
|
||||
|
@ -125,6 +138,9 @@ class Controller:
|
|||
rc = self.handle_msgs()
|
||||
if rc == 'QUIT':
|
||||
return
|
||||
self.view.chats.resize(0.5)
|
||||
self.view.msgs.resize(0.5)
|
||||
self.refresh_chats()
|
||||
|
||||
elif key == 'j':
|
||||
is_changed = self.model.next_chat()
|
||||
|
@ -145,7 +161,7 @@ class Controller:
|
|||
chat_id = update['message']['chat_id']
|
||||
self.model.msgs.msgs[chat_id].append(update['message'])
|
||||
msgs = self.model.get_current_msgs()
|
||||
self.view.draw_msgs(msgs)
|
||||
self.refresh_msgs()
|
||||
try:
|
||||
notify(update['message']['content']['text']['text'])
|
||||
except Exception:
|
||||
|
|
38
view.py
38
view.py
|
@ -46,6 +46,20 @@ class View:
|
|||
# return _input
|
||||
|
||||
|
||||
class StatusView:
|
||||
|
||||
def __init__(self, stdscr):
|
||||
# self.stdscr = stdscr
|
||||
pass
|
||||
|
||||
def resize(self):
|
||||
pass
|
||||
|
||||
def draw(self, msg):
|
||||
# draw msg on the last line
|
||||
pass
|
||||
|
||||
|
||||
emoji_pattern = re.compile(
|
||||
"["
|
||||
"\U0001F600-\U0001F64F" # emoticons
|
||||
|
@ -58,11 +72,16 @@ emoji_pattern = re.compile(
|
|||
|
||||
|
||||
class ChatView:
|
||||
def __init__(self, stdscr):
|
||||
def __init__(self, stdscr, p=0.5):
|
||||
self.h = curses.LINES - 1
|
||||
self.w = int((curses.COLS - 1) * 0.25)
|
||||
self.w = int((curses.COLS - 1) * p)
|
||||
self.win = stdscr.subwin(self.h, self.w, 0, 0)
|
||||
|
||||
def resize(self, p=0.25):
|
||||
self.h = curses.LINES - 1
|
||||
self.w = int((curses.COLS - 1) * p)
|
||||
self.win.resize(self.h, self.w)
|
||||
|
||||
def draw(self, current, chats):
|
||||
self.win.clear()
|
||||
# self.win.vline(0, self.w-1, curses.ACS_VLINE, self.h)
|
||||
|
@ -80,13 +99,24 @@ class ChatView:
|
|||
|
||||
|
||||
class MsgView:
|
||||
def __init__(self, stdscr):
|
||||
def __init__(self, stdscr, p=0.5):
|
||||
self.stdscr = stdscr
|
||||
self.h = curses.LINES - 1
|
||||
self.w = curses.COLS - int((curses.COLS - 1) * 0.25)
|
||||
self.w = curses.COLS - int((curses.COLS - 1) * p)
|
||||
self.s = curses.COLS - self.w
|
||||
self.win = stdscr.subwin(self.h, self.w, 0, self.s)
|
||||
self.lines = 0
|
||||
|
||||
def resize(self, p=0.25):
|
||||
self.h = curses.LINES - 1
|
||||
self.w = curses.COLS - int((curses.COLS - 1) * p)
|
||||
logger.info('msgs view width: %s', self.w)
|
||||
self.s = curses.COLS - self.w
|
||||
|
||||
self.win = self.stdscr.subwin(self.h, self.w, 0, self.s)
|
||||
self.win.mvwin(0, self.s)
|
||||
self.win.resize(self.h, self.w)
|
||||
|
||||
def draw(self, current, msgs):
|
||||
logger.info('Dwaring msgs')
|
||||
self.win.clear()
|
||||
|
|
Loading…
Reference in a new issue