Initial commit
Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
This commit is contained in:
commit
3f55fd0eb9
75
autoZoomer/__init__.py
Normal file
75
autoZoomer/__init__.py
Normal file
@ -0,0 +1,75 @@
|
||||
# ============================================================
|
||||
# Auto Zoomer - plugin for Falkon
|
||||
# Copyright (C) 2019 Juraj Oravec <sgd.orava@gmail.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# ============================================================
|
||||
|
||||
import Falkon
|
||||
from PySide2 import QtCore
|
||||
from autoZoomer.autoZoomer import AutoZoomer
|
||||
from autoZoomer.button import AutoZoomerButton
|
||||
|
||||
|
||||
class Zoomer_Plugin(Falkon.PluginInterface, QtCore.QObject):
|
||||
manager = None
|
||||
buttons = {}
|
||||
|
||||
def init(self, state, settingsPath):
|
||||
plugins = Falkon.MainApplication.instance().plugins()
|
||||
|
||||
plugins.mainWindowCreated.connect(self.mainWindowCreated)
|
||||
plugins.mainWindowDeleted.connect(self.mainWindowDeleted)
|
||||
|
||||
plugins.webPageCreated.connect(self.onWebPageCreated)
|
||||
|
||||
if state == Falkon.PluginInterface.LateInitState:
|
||||
for window in Falkon.MainApplication.instance().windows():
|
||||
self.mainWindowCreated(window)
|
||||
|
||||
self.manager = AutoZoomer(settingsPath)
|
||||
|
||||
def unload(self):
|
||||
self.manager.saveSettings()
|
||||
self.mainWindowDeleted(self.window)
|
||||
|
||||
def testPlugin(self):
|
||||
return True
|
||||
|
||||
def showSettings(self, parent):
|
||||
self.manager.showSettings(parent)
|
||||
|
||||
def mainWindowCreated(self, window):
|
||||
b = AutoZoomerButton(self.manager)
|
||||
window.statusBar().addButton(b)
|
||||
window.navigationBar().addToolButton(b)
|
||||
self.buttons[window] = b
|
||||
|
||||
def mainWindowDeleted(self, window):
|
||||
if window not in self.buttons:
|
||||
return
|
||||
|
||||
b = self.buttons[window]
|
||||
window.statusBar().removeButton(b)
|
||||
window.navigationBar().removeToolButton(b)
|
||||
del self.buttons[window]
|
||||
|
||||
def onWebPageCreated(self, page):
|
||||
def onLoadFinished(ok):
|
||||
self.manager.onLoadFinished(page)
|
||||
|
||||
page.loadFinished.connect(onLoadFinished)
|
||||
|
||||
|
||||
Falkon.registerPlugin(Zoomer_Plugin())
|
107
autoZoomer/autoZoomer.py
Normal file
107
autoZoomer/autoZoomer.py
Normal file
@ -0,0 +1,107 @@
|
||||
# ============================================================
|
||||
# Auto Zoomer - plugin for Falkon
|
||||
# Copyright (C) 2019 Juraj Oravec <sgd.orava@gmail.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# ============================================================
|
||||
|
||||
import Falkon
|
||||
import os
|
||||
from PySide2 import QtCore, QtGui, QtWidgets
|
||||
from autoZoomer.settingsDialog import SettingsDialog
|
||||
from autoZoomer.str2bool import str2bool
|
||||
|
||||
class AutoZoomer(QtCore.QObject):
|
||||
data = None
|
||||
remove = None
|
||||
config = None
|
||||
|
||||
def __init__(self, settingsPath, parent=None):
|
||||
super().__init__(parent)
|
||||
|
||||
self.config = {
|
||||
"settingsFile": os.path.join(settingsPath, "autoZoomer", "settings.ini"),
|
||||
"active": True
|
||||
}
|
||||
self.data = {}
|
||||
self.remove = []
|
||||
|
||||
self.loadSettings()
|
||||
|
||||
def showSettings(self, parent=None):
|
||||
settings = SettingsDialog(self.config, self.data, self.remove, parent)
|
||||
settings.exec_()
|
||||
|
||||
self.saveSettings()
|
||||
|
||||
def loadSettings(self):
|
||||
settings = QtCore.QSettings(self.config["settingsFile"], QtCore.QSettings.IniFormat)
|
||||
|
||||
settings.beginGroup("AutoZoomer")
|
||||
self.config["active"] = str2bool(settings.value("active", True))
|
||||
settings.endGroup()
|
||||
|
||||
for group in settings.childGroups():
|
||||
if group == "AutoZoomer":
|
||||
continue
|
||||
|
||||
settings.beginGroup(group)
|
||||
self.data[group] = {
|
||||
"active": str2bool(settings.value("active", False)),
|
||||
"zoom": int(settings.value("zoom", 6))
|
||||
}
|
||||
settings.endGroup()
|
||||
|
||||
def saveSettings(self):
|
||||
settings = QtCore.QSettings(self.config["settingsFile"], QtCore.QSettings.IniFormat)
|
||||
|
||||
settings.beginGroup("AutoZoomer")
|
||||
settings.setValue("active", self.config["active"])
|
||||
settings.endGroup()
|
||||
|
||||
for host in self.remove:
|
||||
settings.remove(host)
|
||||
self.remove.clear()
|
||||
|
||||
for key, value in self.data.items():
|
||||
settings.beginGroup(key)
|
||||
settings.setValue("active", value["active"])
|
||||
settings.setValue("zoom", value["zoom"])
|
||||
settings.endGroup()
|
||||
|
||||
settings.sync()
|
||||
|
||||
def onLoadFinished(self, page):
|
||||
if not self.config["active"]:
|
||||
return
|
||||
|
||||
view = page.view()
|
||||
host = page.url().host()
|
||||
|
||||
if host in self.data.keys():
|
||||
if self.data[host]["active"]:
|
||||
view.setZoomLevel(self.data[host]["zoom"])
|
||||
|
||||
def addItem(self, host, zoom=6, active=True):
|
||||
if not host:
|
||||
return
|
||||
|
||||
if host in self.data.keys():
|
||||
self.data[host]["zoom"] = zoom
|
||||
self.data[host]["active"] = active
|
||||
else:
|
||||
self.data[host] = {
|
||||
"active": active,
|
||||
"zoom": zoom
|
||||
}
|
47
autoZoomer/button.py
Normal file
47
autoZoomer/button.py
Normal file
@ -0,0 +1,47 @@
|
||||
# ============================================================
|
||||
# Auto Zoomer - plugin for Falkon
|
||||
# Copyright (C) 2019 Juraj Oravec <sgd.orava@gmail.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# ============================================================
|
||||
|
||||
import Falkon
|
||||
import os
|
||||
from PySide2 import QtGui
|
||||
|
||||
|
||||
class AutoZoomerButton(Falkon.AbstractButtonInterface):
|
||||
manager = None
|
||||
|
||||
def __init__(self, manager):
|
||||
super().__init__()
|
||||
self.manager = manager
|
||||
|
||||
self.setIcon(QtGui.QIcon(os.path.join(os.path.dirname(__file__), "icon.svg")))
|
||||
self.setTitle("Auto Zoomer")
|
||||
self.setToolTip("Save current zoom level")
|
||||
|
||||
self.clicked.connect(self.onClicked)
|
||||
|
||||
def id(self):
|
||||
return "auto-zoomer-button"
|
||||
|
||||
def name(self):
|
||||
return "Auto Zoomer button"
|
||||
|
||||
def onClicked(self, controller):
|
||||
host = self.webView().page().url().host()
|
||||
zoom = self.webView().zoomLevel()
|
||||
|
||||
self.manager.addItem(host=host, zoom=zoom)
|
67
autoZoomer/icon.svg
Normal file
67
autoZoomer/icon.svg
Normal file
@ -0,0 +1,67 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
viewBox="0 0 24 24"
|
||||
version="1.1"
|
||||
id="svg6"
|
||||
sodipodi:docname="icon.svg"
|
||||
inkscape:version="0.92.4 5da689c313, 2019-01-14">
|
||||
<metadata
|
||||
id="metadata10">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<sodipodi:namedview
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1"
|
||||
objecttolerance="10"
|
||||
gridtolerance="10"
|
||||
guidetolerance="10"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:window-width="1280"
|
||||
inkscape:window-height="974"
|
||||
id="namedview8"
|
||||
showgrid="false"
|
||||
inkscape:zoom="13.906433"
|
||||
inkscape:cx="21.460845"
|
||||
inkscape:cy="15.79201"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="29"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="svg6" />
|
||||
<defs
|
||||
id="defs3051">
|
||||
<style
|
||||
type="text/css"
|
||||
id="current-color-scheme">
|
||||
.ColorScheme-Text {
|
||||
color:#4d4d4d;
|
||||
}
|
||||
</style>
|
||||
</defs>
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-style:normal;font-weight:normal;font-size:40px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#4d4d4d;fill-opacity:1;stroke:none;"
|
||||
x="1.1505469"
|
||||
y="22.058453"
|
||||
id="text823"><tspan
|
||||
sodipodi:role="line"
|
||||
id="tspan821"
|
||||
x="1.1505469"
|
||||
y="22.058453"
|
||||
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:29.33333397px;font-family:MathJax_Math;-inkscape-font-specification:'MathJax_Math, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;writing-mode:lr-tb;text-anchor:start;fill:#4d4d4d;">Z</tspan></text>
|
||||
</svg>
|
After Width: | Height: | Size: 2.3 KiB |
57
autoZoomer/listItem.py
Normal file
57
autoZoomer/listItem.py
Normal file
@ -0,0 +1,57 @@
|
||||
# ============================================================
|
||||
# Auto Zoomer - plugin for Falkon
|
||||
# Copyright (C) 2019 Juraj Oravec <sgd.orava@gmail.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# ============================================================
|
||||
|
||||
import os
|
||||
from PySide2 import QtCore, QtWidgets, QtUiTools
|
||||
|
||||
|
||||
class ListItem(QtWidgets.QWidget):
|
||||
ui = None
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
|
||||
file = QtCore.QFile(os.path.join(os.path.dirname(__file__), "listItem.ui"))
|
||||
file.open(QtCore.QFile.ReadOnly)
|
||||
self.ui = QtUiTools.QUiLoader().load(file, self)
|
||||
file.close()
|
||||
|
||||
layout = QtWidgets.QVBoxLayout(self)
|
||||
layout.addWidget(self.ui)
|
||||
self.setLayout(layout)
|
||||
|
||||
def active(self):
|
||||
return self.ui.checkBoxActive.isChecked()
|
||||
|
||||
def host(self):
|
||||
return self.ui.labelHost.text()
|
||||
|
||||
def zoom(self):
|
||||
return self.ui.spinBoxZoomLevel.value()
|
||||
|
||||
def setActive(self, active):
|
||||
active = bool(active)
|
||||
self.ui.checkBoxActive.setChecked(active)
|
||||
|
||||
def setHost(self, host):
|
||||
host = str(host)
|
||||
self.ui.labelHost.setText(host)
|
||||
|
||||
def setZoom(self, zoom):
|
||||
zoom = int(zoom)
|
||||
self.ui.spinBoxZoomLevel.setValue(zoom)
|
55
autoZoomer/listItem.ui
Normal file
55
autoZoomer/listItem.ui
Normal file
@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Form</class>
|
||||
<widget class="QWidget" name="Form">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>354</width>
|
||||
<height>30</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetMinimumSize</enum>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,1,0">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBoxActive">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="labelHost">
|
||||
<property name="text">
|
||||
<string>Host</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinBoxZoomLevel">
|
||||
<property name="maximum">
|
||||
<number>18</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
11
autoZoomer/metadata.desktop
Normal file
11
autoZoomer/metadata.desktop
Normal file
@ -0,0 +1,11 @@
|
||||
[Desktop Entry]
|
||||
Name=Auto Zoomer
|
||||
Comment=Remember zoom level per site
|
||||
|
||||
Type=Service
|
||||
X-Falkon-Type=Extension/Python
|
||||
|
||||
X-Falkon-Author=Juraj Oravec
|
||||
X-Falkon-Email=sgd.orava@gmail.com
|
||||
X-Falkon-Version=1.0.0
|
||||
X-Falkon-Settings=true
|
128
autoZoomer/settings.ui
Normal file
128
autoZoomer/settings.ui
Normal file
@ -0,0 +1,128 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>SettingsDialog</class>
|
||||
<widget class="QWidget" name="SettingsDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>379</width>
|
||||
<height>334</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Auto Zoomer Settings</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEditNew">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>www.example.com</string>
|
||||
</property>
|
||||
<property name="clearButtonEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinBoxNew">
|
||||
<property name="maximum">
|
||||
<number>18</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>6</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QListWidget" name="listWidget">
|
||||
<property name="sizeAdjustPolicy">
|
||||
<enum>QAbstractScrollArea::AdjustIgnored</enum>
|
||||
</property>
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="verticalScrollMode">
|
||||
<enum>QAbstractItemView::ScrollPerPixel</enum>
|
||||
</property>
|
||||
<property name="uniformItemSizes">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="selectionRectVisible">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButtonAdd">
|
||||
<property name="text">
|
||||
<string>Add</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButtonRemove">
|
||||
<property name="text">
|
||||
<string>Remove</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBoxEnableAutoZoomer">
|
||||
<property name="text">
|
||||
<string>Enable AutoZoomer</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBoxConfirm">
|
||||
<property name="tabletTracking">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>pushButtonAdd</tabstop>
|
||||
<tabstop>pushButtonRemove</tabstop>
|
||||
<tabstop>listWidget</tabstop>
|
||||
<tabstop>checkBoxEnableAutoZoomer</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
138
autoZoomer/settingsDialog.py
Normal file
138
autoZoomer/settingsDialog.py
Normal file
@ -0,0 +1,138 @@
|
||||
# ============================================================
|
||||
# Auto Zoomer - plugin for Falkon
|
||||
# Copyright (C) 2019 Juraj Oravec <sgd.orava@gmail.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# ============================================================
|
||||
|
||||
import os
|
||||
from PySide2 import QtCore, QtWidgets, QtUiTools
|
||||
from autoZoomer.listItem import ListItem
|
||||
from autoZoomer.i18n import i18n
|
||||
|
||||
|
||||
class SettingsDialog(QtWidgets.QDialog):
|
||||
ui = None
|
||||
data = None
|
||||
remove = None
|
||||
prepareRemove = None
|
||||
config = None
|
||||
|
||||
def __init__(self, config, data, remove, parent=None):
|
||||
super().__init__(parent)
|
||||
|
||||
self.config = config
|
||||
self.data = data
|
||||
self.remove = remove
|
||||
self.prepareRemove = []
|
||||
|
||||
file = QtCore.QFile(os.path.join(os.path.dirname(__file__), "settings.ui"))
|
||||
file.open(QtCore.QFile.ReadOnly)
|
||||
self.ui = QtUiTools.QUiLoader().load(file, self)
|
||||
file.close()
|
||||
|
||||
layout = QtWidgets.QVBoxLayout(self)
|
||||
layout.addWidget(self.ui)
|
||||
self.setLayout(layout)
|
||||
|
||||
self.ui.checkBoxEnableAutoZoomer.setChecked(self.config["active"])
|
||||
|
||||
for key, value in self.data.items():
|
||||
widget = ListItem()
|
||||
widget.setHost(key)
|
||||
widget.setActive(value["active"])
|
||||
widget.setZoom(value["zoom"])
|
||||
|
||||
item = QtWidgets.QListWidgetItem(self.ui.listWidget)
|
||||
item.setSizeHint(widget.sizeHint() * 1.2)
|
||||
self.ui.listWidget.setItemWidget(item, widget)
|
||||
|
||||
self.ui.pushButtonRemove.clicked.connect(self.handleItemRemove)
|
||||
self.ui.pushButtonAdd.clicked.connect(self.handleItemAdd)
|
||||
|
||||
self.ui.buttonBoxConfirm.accepted.connect(self.accept)
|
||||
self.ui.buttonBoxConfirm.rejected.connect(self.reject)
|
||||
|
||||
def addListItem(self, host, zoom=6, active=True):
|
||||
if not host:
|
||||
return
|
||||
|
||||
if host in self.data.keys():
|
||||
for i in range(0, self.ui.listWidget.count()):
|
||||
item = self.ui.listWidget.item(i)
|
||||
widget = self.ui.listWidget.itemWidget(item)
|
||||
|
||||
if widget.host() == host:
|
||||
widget.setActive(active)
|
||||
widget.setZoom(zoom)
|
||||
|
||||
break
|
||||
else:
|
||||
widget = ListItem()
|
||||
widget.setHost(host)
|
||||
widget.setActive(active)
|
||||
widget.setZoom(zoom)
|
||||
|
||||
item = QtWidgets.QListWidgetItem(self.ui.listWidget)
|
||||
item.setSizeHint(widget.sizeHint() * 1.2)
|
||||
self.ui.listWidget.setItemWidget(item, widget)
|
||||
|
||||
def updateData(self):
|
||||
self.config["active"] = self.ui.checkBoxEnableAutoZoomer.isChecked()
|
||||
|
||||
self.data.clear()
|
||||
|
||||
for i in range(0, self.ui.listWidget.count()):
|
||||
item = self.ui.listWidget.item(i)
|
||||
widget = self.ui.listWidget.itemWidget(item)
|
||||
|
||||
self.data[widget.host()] = {
|
||||
"active": widget.active(),
|
||||
"zoom": widget.zoom()
|
||||
}
|
||||
|
||||
self.remove.clear()
|
||||
|
||||
for host in self.prepareRemove:
|
||||
self.remove.append(host)
|
||||
|
||||
self.prepareRemove.clear()
|
||||
|
||||
def handleItemAdd(self):
|
||||
host = self.ui.lineEditNew.text()
|
||||
zoom = self.ui.spinBoxNew.value()
|
||||
|
||||
if not host:
|
||||
return
|
||||
|
||||
self.ui.lineEditNew.clear()
|
||||
|
||||
self.addListItem(host, zoom=zoom)
|
||||
|
||||
def handleItemRemove(self):
|
||||
listWidget = self.ui.listWidget
|
||||
itemList = listWidget.selectedItems()
|
||||
|
||||
if not itemList:
|
||||
return
|
||||
|
||||
self.prepareRemove.append(listWidget.itemWidget(itemList[-1]).host())
|
||||
|
||||
listWidget.takeItem(listWidget.row(itemList[-1]))
|
||||
|
||||
def accept(self):
|
||||
self.updateData()
|
||||
|
||||
super().accept()
|
||||
self.close()
|
55
autoZoomer/str2bool.py
Normal file
55
autoZoomer/str2bool.py
Normal file
@ -0,0 +1,55 @@
|
||||
"""BSD 3-Clause License
|
||||
|
||||
Copyright (c) 2017, SymonSoft
|
||||
Copyright (c) 2019, Juraj Oravec
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
* Neither the name of the copyright holder nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."""
|
||||
|
||||
import sys
|
||||
|
||||
_true_set = {'yes', 'true', 't', 'y', '1'}
|
||||
_false_set = {'no', 'false', 'f', 'n', '0'}
|
||||
|
||||
|
||||
def str2bool(value, raise_exc=False):
|
||||
if isinstance(value, bool):
|
||||
return value
|
||||
|
||||
if isinstance(value, str) or sys.version_info[0] < 3 and isinstance(value, basestring):
|
||||
value = value.lower()
|
||||
if value in _true_set:
|
||||
return True
|
||||
if value in _false_set:
|
||||
return False
|
||||
|
||||
if raise_exc:
|
||||
raise ValueError('Expected "%s"' % '", "'.join(_true_set | _false_set))
|
||||
return None
|
||||
|
||||
|
||||
def str2bool_exc(value):
|
||||
return str2bool(value, raise_exc=True)
|
Loading…
Reference in New Issue
Block a user