Skip to content

Commit

Permalink
feat: Supported to restore user-adjusted geometry and size for the wi…
Browse files Browse the repository at this point in the history
…ndow.
  • Loading branch information
bookfere committed Oct 7, 2023
1 parent 9b78a09 commit 8dc8d06
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
1 change: 1 addition & 0 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class EbookTranslator(InterfaceActionBase):
name = _z('Ebook Translator')
title = _(name)
supported_platforms = ['windows', 'osx', 'linux']
identifier = 'ebook-translator'
author = 'bookfere.com'
version = (2, 2, 0)
__version__ = 'v' + '.'.join(map(str, version))
Expand Down
6 changes: 2 additions & 4 deletions advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
Qt, QObject, QDialog, QGroupBox, QWidget, QVBoxLayout, QHBoxLayout,
QPlainTextEdit, QPushButton, QSplitter, QLabel, QThread, QLineEdit,
QGridLayout, QProgressBar, pyqtSignal, pyqtSlot, QPixmap, QEvent,
QStackedWidget, QSpacerItem, QTextCursor, QSettings, QTabWidget)
QStackedWidget, QSpacerItem, QTextCursor, QTabWidget)
except ImportError:
from PyQt5.Qt import (
Qt, QObject, QDialog, QGroupBox, QWidget, QVBoxLayout, QHBoxLayout,
QPlainTextEdit, QPushButton, QSplitter, QLabel, QThread, QLineEdit,
QGridLayout, QProgressBar, pyqtSignal, pyqtSlot, QPixmap, QEvent,
QStackedWidget, QSpacerItem, QTextCursor, QSettings, QTabWidget)
QStackedWidget, QSpacerItem, QTextCursor, QTabWidget)

load_translations()

Expand Down Expand Up @@ -235,8 +235,6 @@ def show_advanced(self):


class AdvancedTranslation(QDialog):
ui_setting = QSettings()

raw_text = pyqtSignal(str)
original_text = pyqtSignal(str)
translation_text = pyqtSignal((), (str,))
Expand Down
3 changes: 2 additions & 1 deletion lib/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ def add_translation(self, translation, placeholder, position=None,
new_element.set('style', 'color:%s' % color)
if lang is not None:
new_element.set('lang', lang)
self.element.tail = None # Make sure it has no tail

self.element.tail = None # Make sure the element has no tail
if position == 'before':
self.element.addprevious(new_element)
else:
Expand Down
4 changes: 2 additions & 2 deletions setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
QIntValidator, QScrollArea, QRadioButton, QGridLayout, QCheckBox,
QButtonGroup, QColorDialog, QSpinBox, QPalette, QApplication,
QComboBox, QRegularExpression, pyqtSignal, QFormLayout, QDoubleSpinBox,
QSpacerItem, QRegularExpressionValidator)
QSettings, QSpacerItem, QRegularExpressionValidator)
except ImportError:
from PyQt5.Qt import (
Qt, QLabel, QDialog, QWidget, QLineEdit, QPushButton, QPlainTextEdit,
QTabWidget, QHBoxLayout, QVBoxLayout, QGroupBox, QFileDialog, QColor,
QIntValidator, QScrollArea, QRadioButton, QGridLayout, QCheckBox,
QButtonGroup, QColorDialog, QSpinBox, QPalette, QApplication,
QComboBox, QRegularExpression, pyqtSignal, QFormLayout, QDoubleSpinBox,
QSpacerItem, QRegularExpressionValidator)
QSettings, QSpacerItem, QRegularExpressionValidator)

load_translations()

Expand Down
28 changes: 25 additions & 3 deletions ui.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from types import MethodType

from calibre.gui2.actions import InterfaceAction

from . import EbookTranslator
Expand All @@ -19,18 +21,23 @@
from calibre.gui2.convert.single import get_input_format_for_book

try:
from qt.core import QMenu
from qt.core import QMenu, QCoreApplication, QSettings
except ImportError:
from PyQt5.Qt import QMenu
from PyQt5.Qt import QMenu, QCoreApplication, QSettings

load_translations()

QCoreApplication.setOrganizationName(EbookTranslator.author)
QCoreApplication.setOrganizationDomain(EbookTranslator.author)
QCoreApplication.setApplicationName(EbookTranslator.identifier)


class EbookTranslatorGui(InterfaceAction):
name = EbookTranslator.name
action_spec = (
_('Translate Book'), None, _('Translate Ebook Content'), None)
title = '%s - %s' % (EbookTranslator.title, EbookTranslator.__version__)
settings = QSettings()

class Status:
jobs = {}
Expand Down Expand Up @@ -167,9 +174,24 @@ def select_preferred_mode(self):
modes.get(preferred_mode)()

def add_window(self, name, window):
identifier = name.split('_')[0]

window_size = 'window_size/%s' % identifier
size = self.settings.value(window_size)
size and window.resize(size)

window_position = 'window_position/%s' % identifier
position = self.settings.value(window_position)
position and window.restoreGeometry(position)

windows = self.gui.bookfere_ebook_translator.windows
windows[name] = window
window.finished.connect(lambda: windows.pop(name))

def setup_window():
self.settings.setValue(window_size, window.size())
self.settings.setValue(window_position, window.saveGeometry())
windows.pop(name)
window.finished.connect(setup_window)

def get_window(self, name):
return self.gui.bookfere_ebook_translator.windows.get(name)
Expand Down

0 comments on commit 8dc8d06

Please sign in to comment.