Skip to content

Commit

Permalink
bs4 dependency removed
Browse files Browse the repository at this point in the history
Optimized "Open file" function and disabled prettify for previously edited files in order to not add unnecessary indents.
  • Loading branch information
GrimStride committed Feb 26, 2021
1 parent 43e9850 commit 02f8a7a
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions uchnotepad.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import tkinter as tk
#from tkinter.filedialog import askopenfilename, asksaveasfilename
from tkinter import ttk, font, messagebox
import lzma, xml.dom.minidom, pathlib, PIL, bs4, os, win32clipboard, hashlib, json, sys, urllib, webbrowser
import lzma, xml.dom.minidom, pathlib, PIL, os, win32clipboard, hashlib, json, sys, urllib, webbrowser
from pathlib import Path
from bs4 import BeautifulSoup
#from bs4 import BeautifulSoup
from PIL import ImageTk, Image, ImageGrab
from io import BytesIO
from urllib import request, error
Expand All @@ -20,7 +20,7 @@
#global fnd
fnd = 0
rpl = 0
lastcol= "a"
lastcol= None
lastpatt= ""
pyfont.add_file("lib/SearchIcons.ttf")
def loadJson():
Expand Down Expand Up @@ -276,12 +276,12 @@ def savechges(self):
data["shwlc"] = False
txpos["text"] = ""
else: data["shwlc"] = True
if self.sortx.get() == "0":
'''if self.sortx.get() == "0":
data["sort"] = False
frmat = UnsortedAttributes()
else:
data["sort"] = True
frmat= None
frmat= None'''
if self.sythl.get() == "0":
data["syntax"] = False
try:
Expand Down Expand Up @@ -333,10 +333,10 @@ def ufont_changed(self, font):
self.nsuf = font
self.uxf["font"]= font
self.uxf["text"]= font.translate(str.maketrans({'{': '', '}': ''}))
class UnsortedAttributes(bs4.formatter.XMLFormatter):
'''class UnsortedAttributes(bs4.formatter.XMLFormatter):
def attributes(self, tag):
for k, v in tag.attrs.items():
yield k, v
yield k, v'''

def open_file(mode):
if mode != "2":
Expand All @@ -357,23 +357,23 @@ def open_file(mode):
if extension == ".snapshot" or extension == ".ruleset":
with lzma.open(filepath1, "r") as input_file:
text = input_file.read()
text1 = xml.dom.minidom.parseString(text)
text2 = text1.toprettyxml(indent=" ")
text3 = text2.replace("<?xml version=\"1.0\" ?>" + "\n", "")
txt_edit.insert(tk.END, text3)
txt_edit.edit_modified(0)
txt_edit.edit_reset()
checksyntax(None)
else:
with open(filepath1, "r") as input_file:
text = input_file.read()
text1 = xml.dom.minidom.parseString(text)
text2 = text1.toprettyxml(indent=" ")
text3 = text2.replace("<?xml version=\"1.0\" ?>" + "\n", "")
txt_edit.insert(tk.END, text3)
txt_edit.edit_modified(0)
txt_edit.edit_reset()
checksyntax(None)
print(type(text))
if text.decode("utf-8").find(" ") != -1:
text3 = text
else:
text1 = xml.dom.minidom.parseString(text)
text2 = text1.toprettyxml(indent=" ")
text3 = text2.replace("<?xml version=\"1.0\" ?>" + "\n", "")
'''text1 = xml.dom.minidom.parseString(text)
text2 = text1.toprettyxml(indent=indt)
text3 = text2.replace("<?xml version=\"1.0\" ?>" + "\n", "")'''
txt_edit.insert(tk.END, text3)
txt_edit.edit_modified(0)
txt_edit.edit_reset()
checksyntax(None)
global filepath
global lastcol
filepath = filepath1
Expand All @@ -382,7 +382,7 @@ def open_file(mode):
global chash
chash = hashlib.md5(bhash.encode('utf-8')).hexdigest()
txt_edit.mark_set("insert", "1.0")
lastcol = "a"
lastcol = None
root.title(f"{filepath} - UCH Notepad ")

def syntax(pattern, tag, color, start, end,regexp=False):
Expand Down Expand Up @@ -927,8 +927,8 @@ def winquit():

data = loadJson()
updateJson()
if data["sort"] == False: frmat = UnsortedAttributes()
else: frmat = None
#if data["sort"] == False: frmat = None
#else: frmat = None
root = tk.Tk()
root.title("UCH Notepad 1.3")
root.geometry(data["wm"])
Expand Down

0 comments on commit 02f8a7a

Please sign in to comment.