forked from Dogo6647/r2chat
yes me let dogo use my wlang even tough i implementeded it
This commit is contained in:
parent
958f1c83d4
commit
8f54378afd
2 changed files with 155 additions and 0 deletions
100
r2chat_LEGACY.py
Normal file
100
r2chat_LEGACY.py
Normal file
|
|
@ -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("<Key>", 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("<Return>", 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()
|
||||
55
wlang.py
Normal file
55
wlang.py
Normal file
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue