Delete some objects when necessary

This commit is contained in:
Olivier Keshavjee 2015-07-03 13:59:41 +02:00
parent fc3d178acf
commit 3a8062f710
4 changed files with 22 additions and 10 deletions

View file

@ -8,6 +8,7 @@ import os
# Used to detect multiple connections
AUC = Qt.AutoConnection | Qt.UniqueConnection
MW = None
def wordCount(text):
return len(text.strip().replace(" ", "\n").split("\n")) if text else 0
@ -58,10 +59,15 @@ def colorFromProgress(progress):
return c3
def mainWindow():
for i in qApp.topLevelWidgets():
if i.objectName() == "MainWindow":
return i
return None
global MW
if not MW:
for i in qApp.topLevelWidgets():
if i.objectName() == "MainWindow":
MW = i
return MW
return None
else:
return MW
def iconColor(icon):
"Returns a QRgb from a QIcon, assuming its all the same color"
@ -165,4 +171,10 @@ def allPaths(suffix=None):
return paths
def lightBlue():
return QColor(Qt.blue).lighter(190)
return QColor(Qt.blue).lighter(190)
def totalObjects():
return len(mainWindow().findChildren(QObject))
def printObjects():
print("Objects:", str(totalObjects()))

View file

@ -106,6 +106,7 @@ class editorWidget(QWidget, Ui_editorWidget_ui):
highlighting=True,
autoResize=True)
edt.setFrameShape(QFrame.NoFrame)
edt.setStyleSheet("background: {};".format(settings.textEditor["background"]))
edt.setStatusTip("{} ({})".format(itm.path(), itm.type()))
self.toggledSpellcheck.connect(edt.toggleSpellcheck, AUC)
self.dictChanged.connect(edt.setDict, AUC)
@ -147,9 +148,9 @@ class editorWidget(QWidget, Ui_editorWidget_ui):
if item and item.isFolder() and self.folderView == "text":
self.stack.setCurrentIndex(1)
w = QWidget()
l = QVBoxLayout(w)
w.setStyleSheet("background: {};".format(settings.textEditor["background"]))
#self.scroll.setWidgetResizable(False)
self.txtEdits = []

View file

@ -66,7 +66,9 @@ class mainEditor(QWidget, Ui_mainEditor):
def closeTab(self, index):
#FIXME: submit data if textedit?
w = self.tab.widget(index)
self.tab.removeTab(index)
w.deleteLater()
def allTabs(self):
return [self.tab.widget(i) for i in range(self.tab.count())]

View file

@ -21,7 +21,6 @@ class textEditView(QTextEdit):
def __init__(self, parent=None, index=None, html=None, spellcheck=True, highlighting=False, dict="", autoResize=False):
QTextEdit.__init__(self, parent)
self._column = Outline.text.value
self._index = None
self._indexes = None
@ -38,7 +37,7 @@ class textEditView(QTextEdit):
self.spellcheck = spellcheck
self.currentDict = dict if dict else settings.dict
self.highlighter = None
self._autoResize = autoResize
self.setAutoResize(autoResize)
self._defaultBlockFormat = QTextBlockFormat()
self._defaultCharFormat = QTextCharFormat()
self.highlightWord = ""
@ -69,8 +68,6 @@ class textEditView(QTextEdit):
elif html:
self.document().setHtml(html)
self.setReadOnly(True)
self.setAutoResize(self._autoResize)
# Spellchecking
if enchant and self.spellcheck: