Skip to content

Commit d6514de

Browse files
committed
Private Groups Now Live And a little bit Refactor
1 parent b8e6a6b commit d6514de

35 files changed

+165
-242
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1.47 KB
Binary file not shown.

main.py renamed to ChatBox/main.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
# ======================================================================================================================
55
import pymongo
66
import os
7-
import subprocess
8-
import threading
7+
98
os.system('cls' if os.name == 'nt' else 'clear')
109
myclient = pymongo.MongoClient(
1110
"mongodb+srv://CodingBlood:[email protected]/myFirstDatabase?retryWrites=true&w=majority")
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from tkinter import *
2-
from KThread import *
2+
from ChatBox.KThread import *
33
import pymongo
44
myclient = pymongo.MongoClient("mongodb+srv://CodingBlood:[email protected]/myFirstDatabase?retryWrites=true&w=majority")
55
mydb = myclient["Chatbox"]
@@ -31,7 +31,7 @@ def task2():
3131
root1.geometry("1300x700")
3232
color = {"nero": "#252726", "orange": "#FF8700", "darkorange": "#FE6101"}
3333
root1.title("Chat Box")
34-
photo1 = PhotoImage(file=r"heytest.png")
34+
photo1 = PhotoImage(file=r"./ChatBoxGUI/heytest.png")
3535
hi = 0
3636
h = Scrollbar(root1, orient='horizontal')
3737
h.pack(side=BOTTOM, fill=X)

ChatBoxGUI/KThread.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import sys
2+
import trace
3+
import threading
4+
5+
class KThread(threading.Thread):
6+
"""A subclass of threading.Thread, with a kill()
7+
method."""
8+
def __init__(self, *args, **keywords):
9+
threading.Thread.__init__(self, *args, **keywords)
10+
self.killed = False
11+
12+
def start(self):
13+
"""Start the thread."""
14+
self.__run_backup = self.run
15+
self.run = self.__run # Force the Thread to install our trace.
16+
threading.Thread.start(self)
17+
18+
def __run(self):
19+
"""Hacked run function, which installs the
20+
trace."""
21+
sys.settrace(self.globaltrace)
22+
self.__run_backup()
23+
self.run = self.__run_backup
24+
25+
def globaltrace(self, frame, why, arg):
26+
if why == 'call':
27+
return self.localtrace
28+
else:
29+
return None
30+
31+
def localtrace(self, frame, why, arg):
32+
if self.killed:
33+
if why == 'line':
34+
raise SystemExit()
35+
return self.localtrace
36+
37+
def kill(self):
38+
self.killed = True
Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from tkinter import *
22
import pymongo
3-
import time
3+
44
myclient = pymongo.MongoClient(
55
"mongodb+srv://CodingBlood:[email protected]/myFirstDatabase?retryWrites=true&w=majority")
66
mydb = myclient["Chatbox"]
@@ -29,7 +29,7 @@ def PuGrp():
2929
sl3.destroy()
3030
sl4.destroy()
3131
def PuGrpChat(Grpname):
32-
import PublicChatGUI
32+
from ChatBoxGUI import PublicChatGUI
3333
PublicChatGUI.main(Grpname, name)
3434
#===========================================================================================================================
3535
#===========================================================================================================================
@@ -66,8 +66,49 @@ def PuGrpChat(Grpname):
6666

6767

6868
def PrGrp():
69-
import GlobalChatGUI
70-
GlobalChatGUI.main(str(name))
69+
sb1.destroy()
70+
sl1.destroy()
71+
sl2.destroy()
72+
sl3.destroy()
73+
sl4.destroy()
74+
75+
def PrGrpChat(Grpname):
76+
from ChatBoxGUI import PrivateChatGUI
77+
PrivateChatGUI.main(Grpname, name)
78+
79+
# ===========================================================================================================================
80+
# ===========================================================================================================================
81+
# ===========================================================================================================================
82+
# ================NOT WORKING================================================================================================
83+
# def JoinGrp():
84+
#
85+
join = Button(root1, text='+', bg=color["nero"], fg=color["orange"],
86+
font=('Malgun Gothic Semilight', 15), width=2, bd=5, height=1, command=PrGrpChat)
87+
canvas1.create_window(65, 190, anchor="nw", window=join)
88+
# ===========================================================================================================================
89+
# ===========================================================================================================================
90+
# ===========================================================================================================================
91+
# ===========================================================================================================================
92+
pug_details = mydb["PrivateChatGroups"]
93+
b = 245
94+
turn = 0
95+
for iterate in pug_details.find():
96+
for member in iterate["Members"]['username']:
97+
if member['username'] == name:
98+
Gname = iterate["GName"]
99+
pgrp = Button(root1, text=iterate["GName"], bg=color["nero"], fg=color["orange"],
100+
font=('Malgun Gothic Semilight', 25, "bold"), width=500, height=100, bd=5,
101+
image=login,
102+
compound=LEFT,
103+
anchor="nw", command=lambda Grpname=Gname: PrGrpChat(Grpname))
104+
if turn >= 3:
105+
m = 700
106+
else:
107+
m = 100
108+
canvas1.create_window(m, b, anchor="nw", window=pgrp)
109+
b += 120
110+
turn += 1
111+
71112
def NPuGrp():
72113
import GlobalChatGUI
73114
GlobalChatGUI.main(str(name))
@@ -139,13 +180,10 @@ def switch():
139180
global btnState
140181
btnState = False
141182
# loading Navbar icon image:
142-
navIcon = PhotoImage(file="ham.png")
143-
closeIcon = PhotoImage(file="goback.png")
144-
login = PhotoImage(file=r"login.png", height=100, width=100)
145-
signup = PhotoImage(file=r"signup.png", height=100, width=105)
146-
find = PhotoImage(file=r"find.png", height=100, width=105)
147-
delete = PhotoImage(file=r"delete.png", height=100, width=100)
148-
photo1 = PhotoImage(file=r"heytest.png")
183+
navIcon = PhotoImage(file=r"./ChatBoxGUI/ham.png")
184+
closeIcon = PhotoImage(file=r"./ChatBoxGUI/goback.png")
185+
login = PhotoImage(file=r"./ChatBoxGUI/login.png", height=100, width=100)
186+
photo1 = PhotoImage(file=r"./ChatBoxGUI/heytest.png")
149187
canvas1 = Canvas(root1, width=400, height=400)
150188
canvas1.pack(fill="both", expand=True)
151189
canvas1.create_image(0, 0, image=photo1, anchor="nw")

0 commit comments

Comments
 (0)