Skip to content

Commit

Permalink
⚡️event loop fixed, performance improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
berkaygediz committed Nov 9, 2024
1 parent 26b75bd commit 3ae0079
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions RichSpan.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ def initUI(self):

self.status_bar = self.statusBar()
self.DocumentArea = QTextEdit()
self.DocumentArea.setTextInteractionFlags(Qt.TextEditorInteraction)
self.initArea()
layout.addWidget(self.DocumentArea)

Expand Down Expand Up @@ -204,7 +205,6 @@ def changeLanguage(self):
self.toolbarTranslate()

def updateTitle(self):
settings = QSettings("berkaygediz", "RichSpan")
file = self.file_name if self.file_name else translations[lang]["new"]
if file.endswith(".docx"):
textMode = " - Read Only"
Expand All @@ -230,10 +230,9 @@ def textChanged(self):
if not self.text_changed_timer.isActive():
self.text_changed_timer.start()

def updateStatistics(self):
def updateStatistics(self, lang=lang):
self.text_changed_timer.stop()
self.thread_running = False
lang = settings.value("appLanguage")
text = self.DocumentArea.toPlainText()
character_count = len(text)
word_count = len(text.split())
Expand Down Expand Up @@ -265,8 +264,8 @@ def updateStatistics(self):
if word_count > 20:
try:
DetectorFactory.seed = 0
lang = detect(text)
statistics += f"<td>{translations[lang]['analysis_message_5'].format(lang)}</td>"
langdetect = detect(text)
statistics += f"<td>{translations[lang]['analysis_message_5'].format(langdetect)}</td>"
except:
None

Expand Down Expand Up @@ -302,7 +301,6 @@ def updateStatistics(self):
self.updateTitle()

def saveState(self):
settings = QSettings("berkaygediz", "RichSpan")
settings.setValue("windowScale", self.saveGeometry())
settings.setValue("defaultDirectory", self.directory)
settings.setValue("fileName", self.file_name)
Expand All @@ -319,7 +317,6 @@ def saveState(self):
settings.sync()

def restoreState(self):
settings = QSettings("berkaygediz", "RichSpan")
self.geometry = settings.value("windowScale")
self.directory = settings.value("defaultDirectory", self.default_directory)
self.file_name = settings.value("fileName")
Expand Down Expand Up @@ -376,7 +373,6 @@ def restoreState(self):
self.updateTitle()

def restoreTheme(self):
settings = QSettings("berkaygediz", "RichSpan")
if settings.value("appTheme") == "dark":
self.setPalette(self.dark_theme)
else:
Expand Down Expand Up @@ -404,7 +400,6 @@ def themePalette(self):
self.dark_theme.setColor(QPalette.ButtonText, QColor(255, 255, 255))

def themeAction(self):
settings = QSettings("berkaygediz", "RichSpan")
if self.palette() == self.light_theme:
self.setPalette(self.dark_theme)
settings.setValue("appTheme", "dark")
Expand Down Expand Up @@ -624,7 +619,6 @@ def createAction(self, text, status_tip, function, shortcut=None, icon=None):
return action

def initActions(self):
settings = QSettings("berkaygediz", "RichSpan")
self.newaction = self.createAction(
translations[lang]["new"],
translations[lang]["new_message"],
Expand Down Expand Up @@ -792,7 +786,6 @@ def initActions(self):
)

def initToolbar(self):
settings = QSettings("berkaygediz", "RichSpan")
self.toolbar = self.addToolBar(translations[lang]["file"])
self.toolbarLabel(
self.toolbar,
Expand Down Expand Up @@ -951,7 +944,6 @@ def detectEncoding(file_path):
return detector.result["encoding"]

def New(self):
settings = QSettings("berkaygediz", "RichSpan")
if self.is_saved == True:
self.DocumentArea.clear()
self.DocumentArea.setFontFamily(fallbackValues["fontFamily"])
Expand Down Expand Up @@ -1000,7 +992,6 @@ def New(self):

def Open(self):
options = QFileDialog.Options()
settings = QSettings("berkaygediz", "RichSpan")
options |= QFileDialog.ReadOnly
selected_file, _ = QFileDialog.getOpenFileName(
self,
Expand Down Expand Up @@ -1053,7 +1044,6 @@ def Save(self):

def SaveAs(self):
options = QFileDialog.Options()
settings = QSettings("berkaygediz", "RichSpan")
options |= QFileDialog.ReadOnly
selected_file, _ = QFileDialog.getSaveFileName(
self,
Expand Down Expand Up @@ -1108,7 +1098,6 @@ def PrintDocument(self):
preview_dialog.exec()

def addImage(self):
settings = QSettings("berkaygediz", "RichSpan")
options = QFileDialog.Options()
options |= QFileDialog.ReadOnly
selected_file, _ = QFileDialog.getOpenFileName(
Expand Down Expand Up @@ -1201,7 +1190,6 @@ def decFont(self):
self.DocumentArea.setCurrentFont(font)

def find(self):
settings = QSettings("berkaygediz", "RichSpan")
self.find_dialog = QInputDialog(self)
self.find_dialog.setInputMode(QInputDialog.TextInput)
app_language = lang
Expand All @@ -1216,7 +1204,6 @@ def findText(self, text):
self.DocumentArea.find(text)

def replace(self):
settings = QSettings("berkaygediz", "RichSpan")
self.replace_dialog = QInputDialog(self)
self.replace_dialog.setInputMode(QInputDialog.TextInput)
self.replace_dialog.setLabelText(translations[lang]["replace"])
Expand Down

0 comments on commit 3ae0079

Please sign in to comment.