Label Link widget instead of setting every label individually

master
Jaka Perovšek 2024-10-03 18:09:49 +02:00
parent bdc9270ba8
commit e8ffff4739
2 changed files with 19 additions and 19 deletions

View File

@ -5,6 +5,7 @@ import logging
import time
from tape_editor_widgets import *
from widgets import LabelWebLink
from deploy import download_ffmpeg, get_ffmpeg_version, download_git
from PIL import ImageGrab
@ -364,19 +365,14 @@ class UpdateWidget(QWidget):
super().__init__()
hr_html_string = "<hr style=\"background-color:gray;\">"
download_link = ("https://github.com/git-for-windows/git/releases/download/"
"v2.46.2.windows.1/PortableGit-2.46.2-64-bit.7z.exe")
self.grid = QGridLayout()
self.git_checkbox = QCheckBox()
self.git_checkbox.setDisabled(True)
self.git_label = QLabel("Download and unpack git")
self.git_label_link = QLabel(f"<a href=\"{download_link}\">"
f"{download_link.replace('https://', '').replace('download/', 'download/<br>')}</a>")
self.git_label_link.setTextInteractionFlags(Qt.TextInteractionFlag.TextBrowserInteraction)
self.git_label_link.setTextInteractionFlags(Qt.TextInteractionFlag.LinksAccessibleByMouse)
self.git_label_link.setOpenExternalLinks(True)
self.git_label_link = LabelWebLink("https://github.com/git-for-windows/git/releases/download/"
"v2.46.2.windows.1/PortableGit-2.46.2-64-bit.7z.exe")
self.git_label_link.break_at("download")
self.git_pushbutton = QPushButton("Download")
self.git_pushbutton.clicked.connect(self.download_git_action)
self.git_dir = DirWidget("./utils")
@ -389,11 +385,7 @@ class UpdateWidget(QWidget):
self.git_update_checkbox = QCheckBox()
self.git_update_checkbox.setDisabled(True)
self.git_update_label = QLabel("Download update from git")
self.git_update_label_link = QLabel("<a href=\"https://git.kompot.si/jaka/barotrauma-sunken-tapes\">"
"git.kompot.si/jaka/barotrauma-sunken-tapes</a>")
self.git_update_label_link.setTextInteractionFlags(Qt.TextInteractionFlag.TextBrowserInteraction)
self.git_update_label_link.setTextInteractionFlags(Qt.TextInteractionFlag.LinksAccessibleByMouse)
self.git_update_label_link.setOpenExternalLinks(True)
self.git_update_label_link = LabelWebLink("https://git.kompot.si/jaka/barotrauma-sunken-tapes")
self.git_update_pushbutton = QPushButton("Update")
self.grid.addWidget(self.git_update_checkbox, 10, 0)
self.grid.addWidget(self.git_update_label, 10, 1)
@ -432,16 +424,11 @@ class InstallWidget(QWidget):
self.grid = QGridLayout()
hr_html_string = "<hr style=\"background-color:gray;\">"
download_link = "https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-full.7z"
self.ffmpeg_checkbox = QCheckBox()
self.ffmpeg_checkbox.setDisabled(True)
self.ffmpeg_label = QLabel("Download and unpack ffmpeg")
self.ffmpeg_label_link = QLabel(f"<a href=\"{download_link}\">"
f"{download_link.replace('https://', '')}</a>")
self.ffmpeg_label_link.setTextInteractionFlags(Qt.TextInteractionFlag.TextBrowserInteraction)
self.ffmpeg_label_link.setTextInteractionFlags(Qt.TextInteractionFlag.LinksAccessibleByMouse)
self.ffmpeg_label_link.setOpenExternalLinks(True)
self.ffmpeg_label_link = LabelWebLink("https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-full.7z")
self.ffmpeg_pushbutton = QPushButton("Download")
self.ffmpeg_pushbutton.clicked.connect(self.download_ffmpeg_action)
self.ffmpeg_dir = DirWidget("./utils")

View File

@ -10,6 +10,19 @@ import datetime
import os
from pathlib import Path
from typing import Optional
class LabelWebLink(QLabel):
def __init__(self, text):
text = f"<a href=\"{text}\">{text.replace('https://', '')}</a>"
super().__init__(text)
self.setTextInteractionFlags(Qt.TextInteractionFlag.TextBrowserInteraction)
self.setTextInteractionFlags(Qt.TextInteractionFlag.LinksAccessibleByMouse)
self.setOpenExternalLinks(True)
def break_at(self, string):
self.setText(self.text().replace(f'{string}/', f'{string}/<br>'))
class LineNumberArea(QWidget):