mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 02:36:34 +01:00
RunAction: Fix string conversion from bytestring, correct codestyle
Summary: - Fix action execution when url wrongly converted to string as bytestring. This resulted in not working actions (loading b"b"url"") - Make codestyle more pythonic - Remove not required imports - Configue dialog: - Set label weight to bold in QtDesigner (UI file) - Make listview scroll per pixel Reviewers: #falkon, drosca Reviewed By: #falkon, drosca Subscribers: falkon Tags: #falkon Differential Revision: https://phabricator.kde.org/D21718
This commit is contained in:
parent
44730ae16d
commit
493421dd84
@ -16,9 +16,13 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# ============================================================
|
||||
import Falkon
|
||||
import os, re, enum, shlex
|
||||
import os
|
||||
import re
|
||||
import enum
|
||||
import shlex
|
||||
from PySide2 import QtCore, QtGui
|
||||
|
||||
|
||||
class Action():
|
||||
class Type(enum.Enum):
|
||||
Invalid, Url, Command = range(3)
|
||||
@ -53,19 +57,22 @@ class Action():
|
||||
self.supported = data.tryExec()
|
||||
|
||||
def testAction(self, condition, url):
|
||||
if not self.supported: return False
|
||||
if not condition in self.typeCondition: return False
|
||||
if not re.match(self.urlCondition, url.toString()): return False
|
||||
if not self.supported:
|
||||
return False
|
||||
if condition not in self.typeCondition:
|
||||
return False
|
||||
if not re.match(self.urlCondition, url.toString()):
|
||||
return False
|
||||
return True
|
||||
|
||||
def execAction(self, url, text=""):
|
||||
url = str(url.toEncoded())
|
||||
url = str(url.toEncoded(), "utf-8")
|
||||
if self.actionType == Action.Type.Command:
|
||||
url = shlex.quote(url)
|
||||
text = shlex.quote(text)
|
||||
elif self.actionType == Action.Type.Url:
|
||||
url = str(QtCore.QUrl.toPercentEncoding(url))
|
||||
text = str(QtCore.QUrl.toPercentEncoding(text))
|
||||
url = str(QtCore.QUrl.toPercentEncoding(url), "utf-8")
|
||||
text = str(QtCore.QUrl.toPercentEncoding(text), "utf-8")
|
||||
command = self.normalExec if text == "" else self.textExec
|
||||
command = command.replace("{url}", url)
|
||||
command = command.replace("{text}", text)
|
||||
|
@ -16,11 +16,13 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# ============================================================
|
||||
import Falkon
|
||||
import os, subprocess
|
||||
from PySide2 import QtCore, QtGui, QtWidgets, QtUiTools
|
||||
import os
|
||||
import subprocess
|
||||
from PySide2 import QtCore
|
||||
from runaction.action import Action
|
||||
from runaction.settingsdialog import SettingsDialog
|
||||
|
||||
|
||||
class ActionManager(QtCore.QObject):
|
||||
actions = []
|
||||
|
||||
@ -58,7 +60,7 @@ class ActionManager(QtCore.QObject):
|
||||
act = Falkon.Action(action.icon, action.title, self)
|
||||
act.triggered.connect(lambda a=action, w=webView, u=url, t=text: self.execAction(a, w, u, t))
|
||||
if action.submenu:
|
||||
if not action.submenu in menus:
|
||||
if action.submenu not in menus:
|
||||
menu = Falkon.Menu(action.menuTitle, webView)
|
||||
menus[action.submenu] = menu
|
||||
out.append(menu)
|
||||
|
@ -20,6 +20,7 @@ import os
|
||||
from PySide2 import QtGui, QtWidgets
|
||||
from runaction.i18n import i18n
|
||||
|
||||
|
||||
class RunActionButton(Falkon.AbstractButtonInterface):
|
||||
def __init__(self, manager):
|
||||
super().__init__()
|
||||
|
@ -19,6 +19,7 @@ import Falkon
|
||||
from PySide2 import QtCore
|
||||
from runaction import actionmanager, button
|
||||
|
||||
|
||||
class RunActionPlugin(Falkon.PluginInterface, QtCore.QObject):
|
||||
buttons = {}
|
||||
manager = None
|
||||
@ -61,10 +62,12 @@ class RunActionPlugin(Falkon.PluginInterface, QtCore.QObject):
|
||||
self.buttons[window] = b
|
||||
|
||||
def mainWindowDeleted(self, window):
|
||||
if not window in self.buttons: return
|
||||
if window not in self.buttons:
|
||||
return
|
||||
b = self.buttons[window]
|
||||
window.statusBar().removeButton(b)
|
||||
window.navigationBar().removeToolButton(b)
|
||||
del self.buttons[window]
|
||||
|
||||
|
||||
Falkon.registerPlugin(RunActionPlugin())
|
||||
|
@ -15,7 +15,14 @@
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label"/>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListWidget" name="listWidget">
|
||||
@ -28,6 +35,9 @@
|
||||
<height>16</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="verticalScrollMode">
|
||||
<enum>QAbstractItemView::ScrollPerPixel</enum>
|
||||
</property>
|
||||
<property name="uniformItemSizes">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
|
@ -15,11 +15,11 @@
|
||||
# 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, QtUiTools
|
||||
from PySide2 import QtCore, QtWidgets, QtUiTools
|
||||
from runaction.i18n import i18n
|
||||
|
||||
|
||||
class SettingsDialog(QtWidgets.QDialog):
|
||||
def __init__(self, manager, parent=None):
|
||||
super().__init__(parent)
|
||||
@ -36,7 +36,7 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
|
||||
self.setMinimumSize(400, 250)
|
||||
self.setWindowTitle(i18n("Run Action Settings"))
|
||||
self.ui.label.setText("<b>{}</b>".format(i18n("Available actions")))
|
||||
self.ui.label.setText(i18n("Available actions"))
|
||||
|
||||
for action in self.manager.actions:
|
||||
item = QtWidgets.QListWidgetItem(self.ui.listWidget)
|
||||
|
Loading…
Reference in New Issue
Block a user