Use a QListWidget for web_links
Fix web_link in md_attributes
This commit is contained in:
parent
b2d3869488
commit
05423c8270
@ -27,11 +27,12 @@ import sys
|
||||
import webbrowser
|
||||
from datetime import datetime
|
||||
from typing import Any, Callable
|
||||
from urllib.parse import urlparse
|
||||
|
||||
import natsort
|
||||
import settngs
|
||||
import urllib3.util
|
||||
from PyQt5 import QtCore, QtGui, QtNetwork, QtWidgets, uic
|
||||
from urllib3.util.url import LocationParseError
|
||||
|
||||
import comictaggerlib.ui
|
||||
from comicapi import utils
|
||||
@ -112,7 +113,7 @@ class TaggerWindow(QtWidgets.QMainWindow):
|
||||
"alternate_count": self.leAltIssueCount,
|
||||
"imprint": self.leImprint,
|
||||
"notes": self.teNotes,
|
||||
"web_link": self.leWebLink,
|
||||
"web_links": self.leWebLink,
|
||||
"format": self.cbFormat,
|
||||
"manga": self.cbManga,
|
||||
"black_and_white": self.cbBW,
|
||||
@ -532,6 +533,28 @@ class TaggerWindow(QtWidgets.QMainWindow):
|
||||
self.toolBar.addAction(self.actionPageBrowser)
|
||||
self.toolBar.addAction(self.actionAutoImprint)
|
||||
|
||||
self.leWebLink.addAction(self.actionAddWebLink)
|
||||
self.leWebLink.addAction(self.actionRemoveWebLink)
|
||||
|
||||
self.actionAddWebLink.triggered.connect(self.add_weblink_item)
|
||||
self.actionRemoveWebLink.triggered.connect(self.remove_weblink_item)
|
||||
|
||||
def add_weblink_item(self, url: str = "") -> None:
|
||||
item = ""
|
||||
if isinstance(url, str):
|
||||
item = url
|
||||
self.leWebLink.addItem(item)
|
||||
self.leWebLink.item(self.leWebLink.count() - 1).setFlags(
|
||||
QtCore.Qt.ItemFlag.ItemIsEditable
|
||||
| QtCore.Qt.ItemFlag.ItemIsEnabled
|
||||
| QtCore.Qt.ItemFlag.ItemIsDragEnabled
|
||||
| QtCore.Qt.ItemFlag.ItemIsSelectable
|
||||
)
|
||||
|
||||
def remove_weblink_item(self) -> None:
|
||||
item = self.leWebLink.takeItem(self.leWebLink.currentRow())
|
||||
del item
|
||||
|
||||
def repackage_archive(self) -> None:
|
||||
ca_list = self.fileSelectionList.get_selected_archive_list()
|
||||
non_zip_count = 0
|
||||
@ -844,7 +867,10 @@ class TaggerWindow(QtWidgets.QMainWindow):
|
||||
assign_text(self.leAltSeries, md.alternate_series)
|
||||
assign_text(self.leAltIssueNum, md.alternate_number)
|
||||
assign_text(self.leAltIssueCount, md.alternate_count)
|
||||
assign_text(self.leWebLink, " ".join(u.url for u in md.web_links))
|
||||
self.leWebLink: QtWidgets.QListWidget
|
||||
self.leWebLink.clear()
|
||||
for u in md.web_links:
|
||||
self.add_weblink_item(u.url)
|
||||
assign_text(self.teCharacters, "\n".join(md.characters))
|
||||
assign_text(self.teTeams, "\n".join(md.teams))
|
||||
assign_text(self.teLocations, "\n".join(md.locations))
|
||||
@ -967,7 +993,7 @@ class TaggerWindow(QtWidgets.QMainWindow):
|
||||
md.scan_info = utils.xlate(self.leScanInfo.text())
|
||||
md.series_groups = utils.split(self.leSeriesGroup.text(), ",")
|
||||
md.alternate_series = self.leAltSeries.text()
|
||||
md.web_links = utils.split_urls(utils.xlate(self.leWebLink.text()))
|
||||
md.web_links = [urllib3.util.parse_url(self.leWebLink.item(i).text()) for i in range(self.leWebLink.count())]
|
||||
md.characters = set(utils.split(self.teCharacters.toPlainText(), "\n"))
|
||||
md.teams = set(utils.split(self.teTeams.toPlainText(), "\n"))
|
||||
md.locations = set(utils.split(self.teLocations.toPlainText(), "\n"))
|
||||
@ -1336,14 +1362,17 @@ class TaggerWindow(QtWidgets.QMainWindow):
|
||||
self.set_dirty_flag()
|
||||
|
||||
def open_web_link(self) -> None:
|
||||
if self.leWebLink is not None:
|
||||
web_link = self.leWebLink.text().strip()
|
||||
try:
|
||||
result = urlparse(web_link)
|
||||
all([result.scheme in ["http", "https"], result.netloc])
|
||||
webbrowser.open_new_tab(web_link)
|
||||
except ValueError:
|
||||
QtWidgets.QMessageBox.warning(self, self.tr("Web Link"), self.tr("Web Link is invalid."))
|
||||
row = self.leWebLink.currentRow()
|
||||
if row < 0:
|
||||
if self.leWebLink.count() < 1:
|
||||
return
|
||||
row = 0
|
||||
web_link = self.leWebLink.item(row).text()
|
||||
try:
|
||||
urllib3.util.parse_url(web_link)
|
||||
webbrowser.open_new_tab(web_link)
|
||||
except LocationParseError:
|
||||
QtWidgets.QMessageBox.warning(self, "Web Link", "Web Link is invalid.")
|
||||
|
||||
def show_settings(self) -> None:
|
||||
settingswin = SettingsWindow(self, self.config, self.talkers)
|
||||
|
@ -952,10 +952,32 @@
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<layout class="QGridLayout" name="gridLayout_7">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLineEdit" name="leWebLink">
|
||||
<property name="acceptDrops">
|
||||
<bool>false</bool>
|
||||
<item row="0" column="0" rowspan="3">
|
||||
<widget class="QListWidget" name="leWebLink">
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::ActionsContextMenu</enum>
|
||||
</property>
|
||||
<property name="dragEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="dragDropMode">
|
||||
<enum>QAbstractItemView::DropOnly</enum>
|
||||
</property>
|
||||
<property name="defaultDropAction">
|
||||
<enum>Qt::MoveAction</enum>
|
||||
</property>
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::SingleSelection</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QPushButton" name="btnWebLinkRemove">
|
||||
<property name="text">
|
||||
<string>Delete Item</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -975,6 +997,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="btnWebLinkAdd">
|
||||
<property name="text">
|
||||
<string>Add Item</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
@ -1169,7 +1198,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1096</width>
|
||||
<height>28</height>
|
||||
<height>30</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuComicTagger">
|
||||
@ -1459,6 +1488,16 @@
|
||||
<string>Open Folder as Comic</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionAddWebLink">
|
||||
<property name="text">
|
||||
<string>Add Item</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionRemoveWebLink">
|
||||
<property name="text">
|
||||
<string>Remove Web Link</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<customwidgets>
|
||||
@ -1469,5 +1508,38 @@
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>btnWebLinkAdd</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>actionAddWebLink</receiver>
|
||||
<slot>trigger()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>900</x>
|
||||
<y>536</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>-1</x>
|
||||
<y>-1</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>btnWebLinkRemove</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>actionRemoveWebLink</receiver>
|
||||
<slot>trigger()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>900</x>
|
||||
<y>576</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>-1</x>
|
||||
<y>-1</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
|
Loading…
Reference in New Issue
Block a user