From 8f54378afdfa25eed3217b2a36159006b7a52e63 Mon Sep 17 00:00:00 2001 From: win7he Date: Sat, 18 Apr 2026 01:49:03 -0500 Subject: [PATCH] yes me let dogo use my wlang even tough i implementeded it --- r2chat_LEGACY.py | 100 +++++++++++++++++++++++++++++++++++++++++++++++ wlang.py | 55 ++++++++++++++++++++++++++ 2 files changed, 155 insertions(+) create mode 100644 r2chat_LEGACY.py create mode 100644 wlang.py diff --git a/r2chat_LEGACY.py b/r2chat_LEGACY.py new file mode 100644 index 0000000..8acbd1e --- /dev/null +++ b/r2chat_LEGACY.py @@ -0,0 +1,100 @@ +import tkinter as tk +from tkinter import scrolledtext +import os +import time +import getpass +from json import loads + +CHAT_FILE = "C:/Users/Public/r2chat/chat.txt" +REFRESH_INTERVAL = 1000 + +BORDER_WIDTH = 3 +THEMES = [['white','white','white','black','Basic'],['#000707','#002727','#001717','white','Aqua']] + +username = getpass.getuser() +CONFIG_FILE = f'C:/r2chat/legacy_config/{username}.r2cc' + +if not os.path.exists(CONFIG_FILE): + CFILE_C=open(CONFIG_FILE, "a") + CFILE_C.write('0\n is now online.\n is now offline.') + CFILE_C.close() + +def conf_line(n): + return((open(CONFIG_FILE).read()).split('\n')[n]) + +THEME = int(conf_line(0)) +JOIN_MESSAGE = conf_line(1) +LEAVE_MESSAGE = conf_line(2) + +class r2chat: + def __init__(self, root): + self.root = root + self.root.title(f"r2chat Legacy :: {username}") + + self.last_size = 0 + + self.chat_area = scrolledtext.ScrolledText(root, wrap='word', font=("Lucida Console", 11), bg=THEMES[THEME][1], fg=THEMES[THEME][3], relief='groove', borderwidth=BORDER_WIDTH) + self.chat_area.pack(padx=10, pady=10, fill=tk.BOTH, expand=True) + self.chat_area.bind("", lambda e: "break") + + self.entry = tk.Entry(root, font=("Lucida Console", 11), bg=THEMES[THEME][2], fg=THEMES[THEME][3], relief='groove', borderwidth=BORDER_WIDTH) + self.entry.pack(padx=10, pady=(0, 10), fill=tk.X) + self.entry.bind("", self.send_message) + + if not os.path.exists(CHAT_FILE): + open(CHAT_FILE, "a").close() + + self.update_chat() + self.write_system_message(f"{username}{JOIN_MESSAGE}") + + def on_close(self): + self.write_system_message(f"{username}{LEAVE_MESSAGE}") + self.root.destroy() + + def write_system_message(self, msg): + line = f"---- {msg} ----\n" + with open(CHAT_FILE, "a", encoding="utf-8") as f: + f.write(line) + + def send_message(self, event=None): + msg = self.entry.get().strip() + if msg: + timestamp = time.strftime("%y/%m/%d %H:%M") + line = f"[{timestamp}] {username} (legacy): {msg}\n" + try: + with open(CHAT_FILE, "a", encoding="utf-8") as f: + f.write(line) + except Exception as e: + print("oh noes! ", e) + + self.entry.delete(0, tk.END) + + def update_chat(self): + try: + current_size = os.path.getsize(CHAT_FILE) + + if current_size > self.last_size: + with open(CHAT_FILE, "r", encoding="utf-8") as f: + f.seek(self.last_size) + new_data = f.read() + self.last_size = current_size + self.chat_area.config(state='normal') + self.chat_area.insert(tk.END, new_data) + self.chat_area.config(state='disabled') + self.chat_area.yview(tk.END) + + except Exception as e: + print("oh noes! ", e) + + self.root.after(REFRESH_INTERVAL, self.update_chat) + + +if __name__ == "__main__": + root = tk.Tk() + app = r2chat(root) + root.geometry("500x520") + root.minsize(360, 520) + root.attributes('-topmost', True) + root.protocol("WM_DELETE_WINDOW", app.on_close) + root.configure(bg=THEMES[THEME][0]) + root.mainloop() diff --git a/wlang.py b/wlang.py new file mode 100644 index 0000000..6928cc0 --- /dev/null +++ b/wlang.py @@ -0,0 +1,55 @@ +import locale +import json + +# default language file +langfile='lang.json' + +# error and shit +try: + langfilecon=open(langfile).read() +except: + print('wlang error:Language file not found, continuing execution. Make sure to set the language file!') + +# default language +lang='en' +deflangfull=locale.getdefaultlocale()[0] +deflang=deflangfull[3:len(deflangfull)].lower() + +# functions +def setlangfile(lfile): + global langfile + global langfilecon + langfile=lfile + langfilecon=open(langfile).read() + +def setlang(l): + global lang + lang=l + +# get the d, n and v values +def getlangname(): + return json.loads(langfilecon)["n"] + +def getlangver(): + return json.loads(langfilecon)["v"] + +def getinlangdef(): + return json.loads(langfilecon)["d"] + +# the big one +def getobj(obj): + # sssdfg + obj=str(obj) + # get the thing + try: + return json.loads(langfilecon)["l"][lang][obj] + except: + # else use replaced + try: + return json.loads(langfilecon)["l"][json.loads(langfilecon)["r"][lang]][obj] + except: + # else use default + try: + return json.loads(langfilecon)["l"][json.loads(langfilecon)["d"]][obj] + except: + return '{'+obj+'}' # give up \ No newline at end of file