proiect finalizat
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
"""
|
||||
The 'views' package contains all the UI implementation of the app. The app contains the following views:
|
||||
- InitialView
|
||||
- LoginView
|
||||
- SingUpView
|
||||
- MainPageView
|
||||
- ChatView
|
||||
"""
|
||||
@@ -5,6 +5,10 @@ from app.views.message import MessageView
|
||||
|
||||
|
||||
class ChatWindow(tk.Toplevel):
|
||||
"""
|
||||
This view is opened in a separate window and takes care of the communication between the two users. It receives
|
||||
both the users' information and retrieves the conversation_url.
|
||||
"""
|
||||
def __init__(self, master=None, user_data=None, current_logged_user=None):
|
||||
super().__init__(master)
|
||||
|
||||
@@ -48,6 +52,7 @@ class ChatWindow(tk.Toplevel):
|
||||
}
|
||||
|
||||
def create_widgets(self, conversation):
|
||||
"""Creates the UI of this view"""
|
||||
# Create a frame for displaying messages
|
||||
self.messages_frame = tk.Frame(self)
|
||||
self.messages_frame.pack()
|
||||
@@ -70,6 +75,10 @@ class ChatWindow(tk.Toplevel):
|
||||
self.send_button.pack(side=tk.RIGHT)
|
||||
|
||||
def update_chat(self):
|
||||
"""
|
||||
This function is scheduled each second to make a request to the API to retrieve the latest chat between the
|
||||
users
|
||||
"""
|
||||
self.messages_frame.destroy()
|
||||
self.messages_frame = tk.Frame(self)
|
||||
self.messages_frame.pack()
|
||||
@@ -85,7 +94,9 @@ class ChatWindow(tk.Toplevel):
|
||||
pass
|
||||
|
||||
def send_message(self):
|
||||
"""At the submit button, the text is sent to the database"""
|
||||
message = self.entry_widget.get()
|
||||
|
||||
self.define_send_message_params(message, "text")
|
||||
if not message:
|
||||
return
|
||||
@@ -101,6 +112,7 @@ class ChatWindow(tk.Toplevel):
|
||||
self.update_chat()
|
||||
|
||||
def get_conversation_url(self):
|
||||
"""Fetches the conversation_url"""
|
||||
request_builder.set_url(self.url)
|
||||
request_builder.set_body(self.body)
|
||||
request_builder.set_headers(self.headers)
|
||||
@@ -113,6 +125,7 @@ class ChatWindow(tk.Toplevel):
|
||||
return data['conversation_url']
|
||||
|
||||
def get_conversation(self):
|
||||
"""Fetches the conversation between the users"""
|
||||
request_builder.set_url(self.url)
|
||||
request_builder.set_body(self.body)
|
||||
request_builder.set_headers(self.headers)
|
||||
|
||||
@@ -2,6 +2,9 @@ import tkinter as tk
|
||||
|
||||
|
||||
class InitialView(tk.Frame):
|
||||
"""
|
||||
This class is the first rendered view of the application. This offers the options to Login or sign Up
|
||||
"""
|
||||
def __init__(self, master=None):
|
||||
super().__init__(master)
|
||||
self.create_widgets()
|
||||
|
||||
@@ -14,6 +14,10 @@ def hash_password(password):
|
||||
|
||||
|
||||
class LoginView(tk.Frame):
|
||||
"""
|
||||
This view takes care of the validation of the user in the system. This class receives the login information and
|
||||
validates them. The response is shown to the user.
|
||||
"""
|
||||
def __init__(self, master=None):
|
||||
super().__init__(master)
|
||||
self.form_frame = None
|
||||
@@ -27,6 +31,9 @@ class LoginView(tk.Frame):
|
||||
self.params = None
|
||||
|
||||
def create_widgets(self):
|
||||
"""
|
||||
Creates the layout of the view
|
||||
"""
|
||||
# Create a frame to hold the entry fields and labels
|
||||
self.form_frame = tk.Frame(self)
|
||||
|
||||
@@ -71,6 +78,10 @@ class LoginView(tk.Frame):
|
||||
self.master.change_to_initial_view()
|
||||
|
||||
def on_login(self):
|
||||
"""
|
||||
After login button pressed, the validation of the provided information starts and will redirect the
|
||||
user to next view if everything is accepted
|
||||
"""
|
||||
# Retrieve values from entry fields
|
||||
email = self.email_entry.get()
|
||||
password = self.password_entry.get()
|
||||
|
||||
@@ -6,6 +6,10 @@ from app.views.user_frame import UserFrame
|
||||
|
||||
|
||||
class MainPageView(tk.Frame):
|
||||
"""
|
||||
This is the view from which the user will open a chat with anyone which is registered in the system. Each chat is
|
||||
shown as a box with a photo, the username and the email.
|
||||
"""
|
||||
def __init__(self, master=None):
|
||||
super().__init__(master)
|
||||
self.form_frame = None
|
||||
@@ -20,6 +24,7 @@ class MainPageView(tk.Frame):
|
||||
self.body = None
|
||||
|
||||
def create_widgets(self):
|
||||
"""Takes care of the creation of the UI"""
|
||||
# Create a main frame to center the user frame and button frame
|
||||
main_frame = tk.Frame(self.master)
|
||||
main_frame.pack(expand=True)
|
||||
@@ -57,6 +62,7 @@ class MainPageView(tk.Frame):
|
||||
self.master.change_to_initial_view()
|
||||
|
||||
def open_chat(self, user_data):
|
||||
"""Opens a chat in a different window"""
|
||||
# Pass both the clicked user data and the current logged user info to ChatWindow
|
||||
chat_window = ChatWindow(self, user_data, self.master.current_logged_user)
|
||||
chat_window.mainloop() # Main loop for the new window
|
||||
|
||||
@@ -7,6 +7,9 @@ import base64
|
||||
|
||||
|
||||
class MessageView(tk.Frame):
|
||||
"""
|
||||
This view is the message that appears in main windows of the chat. This is configured to hold text and images.
|
||||
"""
|
||||
def __init__(self, master, message, current_logged_user, user_data, *args, **kwargs):
|
||||
super().__init__(master, *args, **kwargs)
|
||||
self.current_logged_user = current_logged_user
|
||||
|
||||
@@ -14,6 +14,10 @@ def hash_password(password):
|
||||
|
||||
|
||||
class SignupView(tk.Frame):
|
||||
"""
|
||||
This view takes care of the registration of the user in the system. This class receives the sing up
|
||||
information and validates them. The response is shown to the user.
|
||||
"""
|
||||
def __init__(self, master=None):
|
||||
super().__init__(master)
|
||||
self.form_frame = None
|
||||
@@ -27,6 +31,7 @@ class SignupView(tk.Frame):
|
||||
self.params = None
|
||||
|
||||
def create_widgets(self):
|
||||
"""Creates the layout of the view"""
|
||||
# Create a frame to hold the entry fields and labels
|
||||
self.form_frame = tk.Frame(self)
|
||||
|
||||
@@ -78,6 +83,10 @@ class SignupView(tk.Frame):
|
||||
self.master.change_to_initial_view()
|
||||
|
||||
def on_signup(self):
|
||||
"""
|
||||
After sign up button pressed, the validation of the provided information starts and will redirect the
|
||||
user to next view if everything is accepted
|
||||
"""
|
||||
# Retrieve values from entry fields
|
||||
username = self.username_entry.get()
|
||||
email = self.email_entry.get()
|
||||
|
||||
@@ -3,11 +3,13 @@ from PIL import Image, ImageTk
|
||||
|
||||
|
||||
class UserFrame(tk.Frame):
|
||||
"""
|
||||
This class takes care of the aspect of the user blocks from the MainPageView.
|
||||
"""
|
||||
def __init__(self, master, user_data, current_logged_user, click_callback, *args, **kwargs):
|
||||
super().__init__(master, *args, **kwargs)
|
||||
|
||||
self.current_logged_user = current_logged_user
|
||||
print(user_data)
|
||||
|
||||
self.user_data = {
|
||||
'id': user_data[0],
|
||||
@@ -45,7 +47,6 @@ class UserFrame(tk.Frame):
|
||||
# Bind the click event to the user frame
|
||||
user_frame.bind("<Button-1>", lambda event, user_data=self.user_data, current_logged_user=self.current_logged_user: self.on_user_click(user_data, current_logged_user))
|
||||
|
||||
|
||||
# Pack the user frame
|
||||
user_frame.pack(side=tk.LEFT, padx=10, pady=10)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user