Add ScrollBar to lobby
What a rework ><
This commit is contained in:
94
lobby.py
94
lobby.py
@@ -5,9 +5,19 @@ import importlib
|
||||
from socket import socket, AF_INET, SOCK_STREAM
|
||||
from datetime import datetime
|
||||
|
||||
# Server
|
||||
SERVER_ADDRESS = 'eveldee.ddns.net'
|
||||
SERVER_PORT = 1409
|
||||
|
||||
# Tags
|
||||
TEXT_TIME = 'Time'
|
||||
TEXT_PSEUDO = 'Pseudo'
|
||||
TEXT_SEPARATION = 'Separation'
|
||||
TEXT_MESSAGE = 'Message'
|
||||
TEXT_RANK = 'Rank'
|
||||
TEXT_SHIFT_SEPARATOR = 'Shift_Separation'
|
||||
TEXT_SCORE = 'Score'
|
||||
|
||||
class Lobby:
|
||||
def __init__(self):
|
||||
# Win
|
||||
@@ -63,22 +73,32 @@ class Lobby:
|
||||
|
||||
# Configure layout
|
||||
mainFrame = self.frame
|
||||
mainFrame.columnconfigure(0, weight = 1)
|
||||
mainFrame.columnconfigure(1, weight = 4)
|
||||
mainFrame.columnconfigure(0, weight = 4)
|
||||
mainFrame.columnconfigure(1, weight = 1)
|
||||
mainFrame.rowconfigure(0, weight = 1)
|
||||
|
||||
# Score
|
||||
scoreFrame = tk.LabelFrame(mainFrame, text = 'Score', bg = color.LEVEL_1, fg = color.PURPLE, font = (None, 12))
|
||||
scoreFrame.grid(column = 0, row = 0, sticky = 'NSEW', padx = 5)
|
||||
self.scoreFrame = scoreFrame
|
||||
scoreFrameDisplay = tk.Text(scoreFrame, bg = color.LEVEL_1, bd = 0, wrap = tk.WORD, font = (None, 11), spacing1 = 7)
|
||||
scoreFrameDisplay.tag_config(TEXT_RANK, foreground = color.PURPLE)
|
||||
scoreFrameDisplay.tag_config(TEXT_SHIFT_SEPARATOR, foreground = color.BLUE)
|
||||
scoreFrameDisplay.tag_config(TEXT_PSEUDO, foreground = color.GREEN)
|
||||
scoreFrameDisplay.tag_config(TEXT_SEPARATION, foreground = color.YELLOW)
|
||||
scoreFrameDisplay.tag_config(TEXT_SCORE, foreground = color.PINK)
|
||||
scoreFrameScroll = tk.Scrollbar(scoreFrame, command = scoreFrameDisplay.yview)
|
||||
scoreFrameDisplay.config(yscrollcommand = scoreFrameScroll.set)
|
||||
scoreFrameScroll.pack(side = tk.RIGHT, fill = tk.Y)
|
||||
scoreFrameDisplay.pack(side = tk.LEFT, fill = tk.BOTH)
|
||||
self.scoreFrameDisplay = scoreFrameDisplay
|
||||
|
||||
# Chat
|
||||
# Chat Frame
|
||||
chatFrame = tk.LabelFrame(mainFrame, text = 'Chat', bg = color.LEVEL_1, fg = color.PURPLE, font = (None, 12))
|
||||
chatFrame.grid(column = 1, row = 0, sticky = 'NSEW', padx = 5)
|
||||
self.chatFrame = chatFrame
|
||||
|
||||
# Chat input
|
||||
bottomFrame = tk.Frame(chatFrame, bg = color.LEVEL_5, name = 'bottomFrame')
|
||||
bottomFrame.pack(side = tk.BOTTOM, fill = tk.X)
|
||||
bottomFrame.pack(side = tk.BOTTOM, fill = tk.X, expand = True)
|
||||
entry = tk.Entry(bottomFrame, textvariable = self.message, bg = color.LEVEL_1, fg = color.GHOST, font = (None, 11))
|
||||
entry.bind('<Return>', lambda e: self.sendMessage())
|
||||
entry.pack(side = tk.LEFT, fill = tk.BOTH, expand = True, padx = 5, pady = 5)
|
||||
@@ -89,6 +109,22 @@ class Lobby:
|
||||
command = lambda: self.sendMessage()
|
||||
).pack(side = tk.LEFT, padx = 5, pady = 5)
|
||||
|
||||
# Chat display
|
||||
chatTextFrame = tk.Frame(chatFrame, bg = color.LEVEL_1)
|
||||
chatTextFrame.pack(side = tk.TOP, fill = tk.BOTH, pady = 2)
|
||||
chatTextDisplay = tk.Text(chatTextFrame, bg = color.LEVEL_1, bd = 0, state = tk.DISABLED, wrap = tk.WORD, font = (None, 11), spacing1 = 7)
|
||||
chatTextDisplayScroll = tk.Scrollbar(chatTextFrame, command = chatTextDisplay.yview)
|
||||
chatTextDisplay.config(yscrollcommand = chatTextDisplayScroll.set)
|
||||
|
||||
chatTextDisplayScroll.pack(side = tk.RIGHT, fill = tk.Y)
|
||||
chatTextDisplay.pack(side = tk.LEFT, fill = tk.BOTH, padx = 3)
|
||||
self.chatTextDisplay = chatTextDisplay
|
||||
|
||||
chatTextDisplay.tag_config(TEXT_TIME, foreground = color.PURPLE)
|
||||
chatTextDisplay.tag_config(TEXT_PSEUDO, foreground = color.GREEN)
|
||||
chatTextDisplay.tag_config(TEXT_SEPARATION, foreground = color.YELLOW)
|
||||
chatTextDisplay.tag_config(TEXT_MESSAGE, foreground = color.PINK)
|
||||
|
||||
# Play
|
||||
tk.Button(
|
||||
mainFrame, text = 'Jouer', bg = color.PURPLE, fg = color.LEVEL_1,
|
||||
@@ -104,30 +140,24 @@ class Lobby:
|
||||
|
||||
# Score
|
||||
if len(scores) > self.scoreLen:
|
||||
for child in self.scoreFrame.children.values():
|
||||
child.pack_forget()
|
||||
|
||||
self.scoreLen = len(scores)
|
||||
|
||||
rank = 1
|
||||
for score in self.networkManager.requestScores():
|
||||
for score in scores:
|
||||
pseudo, score = score.split(';')
|
||||
self.addScoreEntry(rank, pseudo, score)
|
||||
rank += 1
|
||||
|
||||
# Chat
|
||||
if len(messages) > self.chatLen:
|
||||
for child in self.chatFrame.children.values():
|
||||
if child._name != 'bottomFrame':
|
||||
child.pack_forget()
|
||||
|
||||
self.chatLen = len(messages)
|
||||
|
||||
for messsage in self.networkManager.requestMessages():
|
||||
for messsage in messages[self.chatLen:]:
|
||||
split = messsage.split(';')
|
||||
time, pseudo, content = split[0], split[1], ';'.join(split[2:])
|
||||
self.addChatEntry(time, pseudo, content)
|
||||
|
||||
self.chatLen = len(messages)
|
||||
|
||||
self.win.after(1000, lambda: self.update())
|
||||
|
||||
def nameConfirm(self):
|
||||
@@ -185,23 +215,25 @@ class Lobby:
|
||||
self.sendScore(score)
|
||||
|
||||
def addScoreEntry(self, rank, pseudo, score):
|
||||
frame = tk.Frame(self.scoreFrame)
|
||||
frame.pack(anchor = tk.W)
|
||||
font = (None, 11)
|
||||
tk.Label(frame, text = f'{rank}', bg = color.LEVEL_1, fg = color.PURPLE, font = font).pack(side = tk.LEFT)
|
||||
tk.Label(frame, text = f'>', bg = color.LEVEL_1, fg = color.BLUE, font = font).pack(side = tk.LEFT)
|
||||
tk.Label(frame, text = f'{pseudo}', bg = color.LEVEL_1, fg = color.GREEN, font = font).pack(side = tk.LEFT)
|
||||
tk.Label(frame, text = f':', bg = color.LEVEL_1, fg = color.YELLOW, font = font).pack(side = tk.LEFT)
|
||||
tk.Label(frame, text = f'{score}', bg = color.LEVEL_1, fg = color.PINK, font = font).pack(side = tk.LEFT)
|
||||
self.scoreFrameDisplay['state'] = tk.NORMAL
|
||||
|
||||
self.scoreFrameDisplay.insert(tk.END, f'{rank}', TEXT_RANK)
|
||||
self.scoreFrameDisplay.insert(tk.END, f'> ', TEXT_SHIFT_SEPARATOR)
|
||||
self.scoreFrameDisplay.insert(tk.END, f'{pseudo}', TEXT_PSEUDO)
|
||||
self.scoreFrameDisplay.insert(tk.END, f': ', TEXT_SEPARATION)
|
||||
self.scoreFrameDisplay.insert(tk.END, f'{score}\n', TEXT_SCORE)
|
||||
|
||||
self.scoreFrameDisplay['state'] = tk.DISABLED
|
||||
|
||||
def addChatEntry(self, time, pseudo, message):
|
||||
frame = tk.Frame(self.chatFrame, bg = color.LEVEL_1)
|
||||
frame.pack(anchor = tk.W)
|
||||
font = (None, 10)
|
||||
tk.Label(frame, text = f'[{time}]', bg = color.LEVEL_1, fg = color.PURPLE, font = font).pack(side = tk.LEFT, anchor = tk.N)
|
||||
tk.Label(frame, text = f'({pseudo})', bg = color.LEVEL_1, fg = color.GREEN, font = font).pack(side = tk.LEFT, anchor = tk.N)
|
||||
tk.Label(frame, text = f':', bg = color.LEVEL_1, fg = color.YELLOW, font = font, bd = 0).pack(side = tk.LEFT, anchor = tk.N)
|
||||
tk.Label(frame, text = f'{message}', bg = color.LEVEL_1, fg = color.PINK, font = font, wraplength = 450, justify = tk.LEFT).pack(side = tk.LEFT, anchor = tk.N)
|
||||
self.chatTextDisplay['state'] = tk.NORMAL
|
||||
|
||||
self.chatTextDisplay.insert(tk.END, f'[{time}] ', TEXT_TIME)
|
||||
self.chatTextDisplay.insert(tk.END, f'({pseudo})', TEXT_PSEUDO)
|
||||
self.chatTextDisplay.insert(tk.END, ': ', TEXT_SEPARATION)
|
||||
self.chatTextDisplay.insert(tk.END, f'{message}\n', TEXT_MESSAGE)
|
||||
|
||||
self.chatTextDisplay['state'] = tk.DISABLED
|
||||
|
||||
def show(self):
|
||||
self.win.mainloop()
|
||||
|
||||
Reference in New Issue
Block a user