Partially fix tab close memory leak
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import gc
|
||||||
import sys
|
import sys
|
||||||
import hashlib
|
import hashlib
|
||||||
import pathlib
|
import pathlib
|
||||||
@@ -526,7 +527,7 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
|
|||||||
|
|
||||||
# Update the database in the background
|
# Update the database in the background
|
||||||
self.thread = BackGroundBookDeletion(
|
self.thread = BackGroundBookDeletion(
|
||||||
delete_hashes, self.database_path, self)
|
delete_hashes, self.database_path)
|
||||||
self.thread.finished.connect(self.move_on)
|
self.thread.finished.connect(self.move_on)
|
||||||
self.thread.start()
|
self.thread.start()
|
||||||
|
|
||||||
@@ -647,7 +648,10 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
|
|||||||
self.thread.start()
|
self.thread.start()
|
||||||
|
|
||||||
self.tabWidget.widget(tab_index).update_last_accessed_time()
|
self.tabWidget.widget(tab_index).update_last_accessed_time()
|
||||||
self.tabWidget.removeTab(tab_index)
|
|
||||||
|
self.tabWidget.widget(tab_index).deleteLater()
|
||||||
|
self.tabWidget.widget(tab_index).setParent(None)
|
||||||
|
gc.collect()
|
||||||
|
|
||||||
def set_toc_position(self, event=None):
|
def set_toc_position(self, event=None):
|
||||||
current_tab = self.tabWidget.widget(self.tabWidget.currentIndex())
|
current_tab = self.tabWidget.widget(self.tabWidget.currentIndex())
|
||||||
@@ -773,7 +777,7 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
|
|||||||
# New tabs are created here
|
# New tabs are created here
|
||||||
# Initial position adjustment is carried out by the tab itself
|
# Initial position adjustment is carried out by the tab itself
|
||||||
file_data = contents[i]
|
file_data = contents[i]
|
||||||
Tab(file_data, self.tabWidget)
|
Tab(file_data, self)
|
||||||
|
|
||||||
if self.settings['last_open_tab'] == 'library':
|
if self.settings['last_open_tab'] == 'library':
|
||||||
self.tabWidget.setCurrentIndex(0)
|
self.tabWidget.setCurrentIndex(0)
|
||||||
|
@@ -32,7 +32,7 @@ from resources import settingswindow
|
|||||||
|
|
||||||
|
|
||||||
class SettingsUI(QtWidgets.QDialog, settingswindow.Ui_Dialog):
|
class SettingsUI(QtWidgets.QDialog, settingswindow.Ui_Dialog):
|
||||||
def __init__(self, parent):
|
def __init__(self, parent=None):
|
||||||
super(SettingsUI, self).__init__()
|
super(SettingsUI, self).__init__()
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
self._translate = QtCore.QCoreApplication.translate
|
self._translate = QtCore.QCoreApplication.translate
|
||||||
@@ -216,7 +216,7 @@ class SettingsUI(QtWidgets.QDialog, settingswindow.Ui_Dialog):
|
|||||||
# Traverse directories looking for files
|
# Traverse directories looking for files
|
||||||
self.parent.statusMessage.setText(
|
self.parent.statusMessage.setText(
|
||||||
self._translate('SettingsUI', 'Checking library folders'))
|
self._translate('SettingsUI', 'Checking library folders'))
|
||||||
self.thread = BackGroundBookSearch(data_pairs, self)
|
self.thread = BackGroundBookSearch(data_pairs)
|
||||||
self.thread.finished.connect(self.finished_iterating)
|
self.thread.finished.connect(self.finished_iterating)
|
||||||
self.thread.start()
|
self.thread.start()
|
||||||
|
|
||||||
|
@@ -44,12 +44,12 @@ class BackGroundTabUpdate(QtCore.QThread):
|
|||||||
|
|
||||||
|
|
||||||
class BackGroundBookAddition(QtCore.QThread):
|
class BackGroundBookAddition(QtCore.QThread):
|
||||||
def __init__(self, file_list, database_path, addition_mode, parent=None):
|
def __init__(self, file_list, database_path, addition_mode, main_window, parent=None):
|
||||||
super(BackGroundBookAddition, self).__init__(parent)
|
super(BackGroundBookAddition, self).__init__(parent)
|
||||||
self.file_list = file_list
|
self.file_list = file_list
|
||||||
self.parent = parent
|
|
||||||
self.database_path = database_path
|
self.database_path = database_path
|
||||||
self.addition_mode = addition_mode
|
self.addition_mode = addition_mode
|
||||||
|
self.main_window = main_window
|
||||||
|
|
||||||
self.prune_required = True
|
self.prune_required = True
|
||||||
if self.addition_mode == 'manual':
|
if self.addition_mode == 'manual':
|
||||||
@@ -60,21 +60,20 @@ class BackGroundBookAddition(QtCore.QThread):
|
|||||||
self.file_list,
|
self.file_list,
|
||||||
('addition', self.addition_mode),
|
('addition', self.addition_mode),
|
||||||
self.database_path,
|
self.database_path,
|
||||||
self.parent.settings['auto_tags'],
|
self.main_window.settings['auto_tags'],
|
||||||
self.parent.temp_dir.path())
|
self.main_window.temp_dir.path())
|
||||||
|
|
||||||
parsed_books = books.initiate_threads()
|
parsed_books = books.initiate_threads()
|
||||||
self.parent.lib_ref.generate_model('addition', parsed_books, False)
|
self.main_window.lib_ref.generate_model('addition', parsed_books, False)
|
||||||
database.DatabaseFunctions(self.database_path).add_to_database(parsed_books)
|
database.DatabaseFunctions(self.database_path).add_to_database(parsed_books)
|
||||||
|
|
||||||
if self.prune_required:
|
if self.prune_required:
|
||||||
self.parent.lib_ref.prune_models(self.file_list)
|
self.main_window.lib_ref.prune_models(self.file_list)
|
||||||
|
|
||||||
|
|
||||||
class BackGroundBookDeletion(QtCore.QThread):
|
class BackGroundBookDeletion(QtCore.QThread):
|
||||||
def __init__(self, hash_list, database_path, parent=None):
|
def __init__(self, hash_list, database_path, parent=None):
|
||||||
super(BackGroundBookDeletion, self).__init__(parent)
|
super(BackGroundBookDeletion, self).__init__(parent)
|
||||||
self.parent = parent
|
|
||||||
self.hash_list = hash_list
|
self.hash_list = hash_list
|
||||||
self.database_path = database_path
|
self.database_path = database_path
|
||||||
|
|
||||||
@@ -86,7 +85,6 @@ class BackGroundBookDeletion(QtCore.QThread):
|
|||||||
class BackGroundBookSearch(QtCore.QThread):
|
class BackGroundBookSearch(QtCore.QThread):
|
||||||
def __init__(self, data_list, parent=None):
|
def __init__(self, data_list, parent=None):
|
||||||
super(BackGroundBookSearch, self).__init__(parent)
|
super(BackGroundBookSearch, self).__init__(parent)
|
||||||
self.parent = parent
|
|
||||||
self.valid_files = []
|
self.valid_files = []
|
||||||
|
|
||||||
# Filter for checked directories
|
# Filter for checked directories
|
||||||
|
@@ -41,15 +41,16 @@ from lector.sorter import resize_image
|
|||||||
|
|
||||||
|
|
||||||
class Tab(QtWidgets.QWidget):
|
class Tab(QtWidgets.QWidget):
|
||||||
def __init__(self, metadata, parent=None):
|
def __init__(self, metadata, main_window, parent=None):
|
||||||
super(Tab, self).__init__(parent)
|
super(Tab, self).__init__(parent)
|
||||||
self._translate = QtCore.QCoreApplication.translate
|
self._translate = QtCore.QCoreApplication.translate
|
||||||
|
|
||||||
self.parent = parent
|
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
|
||||||
|
|
||||||
|
self.main_window = main_window
|
||||||
self.metadata = metadata # Save progress data into this dictionary
|
self.metadata = metadata # Save progress data into this dictionary
|
||||||
self.are_we_doing_images_only = self.metadata['images_only']
|
self.are_we_doing_images_only = self.metadata['images_only']
|
||||||
self.is_fullscreen = False
|
self.is_fullscreen = False
|
||||||
self.main_window = self.window()
|
|
||||||
|
|
||||||
self.masterLayout = QtWidgets.QHBoxLayout(self)
|
self.masterLayout = QtWidgets.QHBoxLayout(self)
|
||||||
self.masterLayout.setContentsMargins(0, 0, 0, 0)
|
self.masterLayout.setContentsMargins(0, 0, 0, 0)
|
||||||
@@ -152,7 +153,7 @@ class Tab(QtWidgets.QWidget):
|
|||||||
self.horzLayout.addWidget(self.contentView)
|
self.horzLayout.addWidget(self.contentView)
|
||||||
self.horzLayout.addWidget(self.dockWidget)
|
self.horzLayout.addWidget(self.dockWidget)
|
||||||
title = self.metadata['title']
|
title = self.metadata['title']
|
||||||
self.parent.addTab(self, title)
|
self.main_window.tabWidget.addTab(self, title)
|
||||||
|
|
||||||
# Hide mouse cursor timer
|
# Hide mouse cursor timer
|
||||||
self.mouse_hide_timer = QtCore.QTimer()
|
self.mouse_hide_timer = QtCore.QTimer()
|
||||||
|
Reference in New Issue
Block a user