Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #19

Merged
merged 3 commits into from
Nov 7, 2021
Merged

Dev #19

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed assets/CheckTabScreenShot.png
Binary file not shown.
Binary file removed assets/CreateTabScreenShot.png
Binary file not shown.
Binary file removed assets/InfoTabScreenShot.png
Binary file not shown.
Binary file added assets/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/torrent-icon.png
Binary file not shown.
Binary file added assets/torrentfile.ico
Binary file not shown.
Binary file removed assets/torrentfile.png
Binary file not shown.
Binary file removed assets/transparent.png
Binary file not shown.
644 changes: 330 additions & 314 deletions coverage.xml

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion tests/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import shutil
import string
import atexit
import time


TESTS = os.path.dirname(os.path.abspath(__file__))
Expand Down Expand Up @@ -106,4 +107,8 @@ def tstdir():

@atexit.register
def teardown():
rmpath(TESTDIR)
try:
rmpath(TESTDIR)
except PermissionError:
time.sleep(1.5)
teardown()
10 changes: 0 additions & 10 deletions tests/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import os
import pytest
from pathlib import Path

from PyQt6.QtWidgets import QApplication, QMainWindow, QStatusBar

Expand Down Expand Up @@ -65,7 +64,6 @@ def ttorrent1(tfile, request):
return outfile



@pytest.fixture(scope="module", params=[TorrentFile, TorrentFileV2, TorrentFileHybrid])
def ttorrent2(tfile, request):
path = tfile
Expand Down Expand Up @@ -95,14 +93,6 @@ def test_window_menubar1(wind):
assert wind.menubar is not None


def test_window_menubar_action1(wind):
menubar = wind.menubar
menubar.actionDocs.trigger()
menubar.actionRepo.trigger()
menubar.actionExit.trigger()
assert True


def test_window_statusbar1(wind):
assert wind.statusbar is not None

Expand Down
42 changes: 33 additions & 9 deletions torrentfileQt/checkTab.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,22 @@
QToolButton,
QTreeWidget,
QTreeWidgetItem,
QLineEdit,
QLabel
)
from torrentfile.progress import CheckerClass


from torrentfileQt.qss import (
logTextEditSheet,
lineEditSheet,
labelSheet,
pushButtonSheet,
toolButtonSheet,
treeSheet,
headerSheet,
)

from torrentfileQt.widgets import Label, LineEdit


class CheckWidget(QWidget):

labelRole = QFormLayout.ItemRole.LabelRole
Expand Down Expand Up @@ -108,6 +109,7 @@ class ReCheckButton(QPushButton):
text (`str`): The text displayed on the button itself.
parent (`QWidget`, default=None): This widgets parent widget.
"""

process = None

def __init__(self, text, parent=None):
Expand All @@ -121,19 +123,19 @@ def __init__(self, text, parent=None):

def submit(self):
tree = self.widget.treeWidget
tree.clear()
textEdit = self.widget.textEdit
textEdit.clear()
searchInput = self.widget.searchInput
fileInput = self.widget.fileInput
metafile = fileInput.text()
content = searchInput.text()
tree.setRoot(content)
CheckerClass.register_callback(textEdit.callback)
logging.debug("Registering Callback, setting root")
piece_hasher(metafile, content, tree)
# tree.start_thread(metafile, content)



class BrowseTorrents(QToolButton):
"""BrowseButton ToolButton for activating filebrowser.

Expand Down Expand Up @@ -230,7 +232,8 @@ def getProgressBar(self):
def set_top(self, path, icon):
pix = QIcon(icon)
self.setIcon(0, pix)
self.setText(1, path)
if path:
self.setText(1, path)

def setTotal(self, total):
self.total = total
Expand Down Expand Up @@ -276,6 +279,7 @@ class TreeWidget(QTreeWidget):
Args:
parent(`QWidget`, default=None)
"""

valueUpdate = pyqtSignal([list])
addPathChild = pyqtSignal([str, int])

Expand All @@ -294,7 +298,7 @@ def __init__(self, parent=None):
self.itemWidgets = {}
self.paths = []
self.total = 0
self.item_tree = {"widget" : self.item}
self.item_tree = {"widget": self.item}
self.valueUpdate.connect(self.updateValue)
self.addPathChild.connect(self.add_path_child)

Expand All @@ -307,7 +311,7 @@ def updateValue(self, args):

def clear(self):
super().clear()
self.item_tree = {"widget" : self.invisibleRootItem()}
self.item_tree = {"widget": self.invisibleRootItem()}
self.itemWidgets = {}
self.paths = []
self.root = None
Expand All @@ -327,6 +331,7 @@ def add_path_child(self, path, size):
item_tree[partial] = {"widget": item}
if i == len(partials) - 1:
item.setTotal(size)
item.set_top(None, "./assets/file.png")
progressbar = ProgressBar()
self.setItemWidget(item, 2, progressbar)
item.setProgressBar(progressbar)
Expand All @@ -337,7 +342,6 @@ def add_path_child(self, path, size):


class LogTextEdit(QPlainTextEdit):

def __init__(self, parent=None):
super().__init__(parent=parent)
self._parent = parent
Expand Down Expand Up @@ -368,3 +372,23 @@ def piece_hasher(metafile, content, tree):
tree.addPathChild.emit(relpath, length)
itemWidgets.append(relpath)
tree.valueUpdate.emit([actual, expected, relpath, size])

class LineEdit(QLineEdit):
def __init__(self, parent=None):
super().__init__(parent=parent)
self._parent = parent
self.setStyleSheet(lineEditSheet)

class Label(QLabel):
"""Label Identifier for Window Widgets.

Subclass: QLabel
"""

def __init__(self, text, parent=None):
super().__init__(text, parent=parent)
self.setStyleSheet(labelSheet)
font = self.font()
font.setBold(True)
font.setPointSize(12)
self.setFont(font)
87 changes: 65 additions & 22 deletions torrentfileQt/createTab.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import os
import threading
from collections.abc import Sequence

from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import (
Expand All @@ -33,18 +34,23 @@
QSpacerItem,
QToolButton,
QWidget,
QPlainTextEdit,
QLabel,
QLineEdit
)
from torrentfile import TorrentFile, TorrentFileHybrid, TorrentFileV2
from torrentfile.utils import path_stat

from torrentfileQt.qss import (
checkBoxSheet,
comboBoxSheet,
labelSheet,
push2ButtonSheet,
pushButtonSheet,
toolButtonSheet,
textEditSheet,
createLineEditSheet
)
from torrentfileQt.widgets import Label, LineEdit, PlainTextEdit


class CreateWidget(QWidget):
Expand All @@ -68,13 +74,13 @@ def setup_Ui(self):
self.hlayout3 = QHBoxLayout()
self.hlayout0 = QHBoxLayout()

self.path_label = Label("Path:", parent=self)
self.output_label = Label("Save Path:", parent=self)
self.version_label = Label("Meta-version", parent=self)
self.comment_label = Label("Comment:", parent=self)
self.announce_label = Label("Trackers:", parent=self)
self.source_label = Label("Source:", parent=self)
self.piece_length_label = Label("Piece Length:", parent=self)
self.path_label = Label("Path: ", parent=self)
self.output_label = Label("Save Path: ", parent=self)
self.version_label = Label("Meta Version: ", parent=self)
self.comment_label = Label("Comment: ", parent=self)
self.announce_label = Label("Trackers: ", parent=self)
self.source_label = Label("Source: ", parent=self)
self.piece_length_label = Label("Piece Length: ", parent=self)

self.path_input = LineEdit(parent=self)
self.output_input = LineEdit(parent=self)
Expand All @@ -93,7 +99,6 @@ def setup_Ui(self):

self.v2button = QRadioButton("v2", parent=self)
self.hybridbutton = QRadioButton("v1+2 (hybrid)", parent=self)
self.output_input.setDisabled(True)
self.spacer = QSpacerItem(50, 0)

self.path_label.setAlignment(Qt.AlignmentFlag.AlignLeft)
Expand Down Expand Up @@ -124,18 +129,19 @@ def setup_Ui(self):
self.layout.addLayout(self.hlayout1, 1, 1, 1, 3)
self.layout.addWidget(self.version_label, 2, 0, 1, 1)
self.layout.addLayout(self.hlayout0, 2, 1, 1, 3)
self.layout.addWidget(self.source_label, 3, 0, 1, 1)
self.layout.addWidget(self.source_input, 3, 1, 1, 3)
self.layout.addWidget(self.comment_label, 4, 0, 1, 1)
self.layout.addWidget(self.comment_input, 4, 1, 1, 3)
self.layout.addWidget(self.piece_length_label, 5, 0, 1, 1)
self.layout.addLayout(self.hlayout2, 5, 1, 1, 3)
self.layout.addWidget(self.output_label, 6, 0, 1, 1)
self.layout.addLayout(self.hlayout3, 6, 1, 1, 3)
self.layout.addWidget(self.piece_length_label, 3, 0, 1, 1)
self.layout.addLayout(self.hlayout2, 3, 1, 1, 3)
self.layout.addWidget(self.output_label, 4, 0, 1, 1)
self.layout.addLayout(self.hlayout3, 4, 1, 1, 3)
self.layout.addWidget(self.source_label, 5, 0, 1, 1)
self.layout.addWidget(self.source_input, 5, 1, 1, 3)
self.layout.addWidget(self.comment_label, 6, 0, 1, 1)
self.layout.addWidget(self.comment_input, 6, 1, 1, 3)
self.layout.addWidget(self.announce_label, 7, 0, 1, 1)
self.layout.addWidget(self.announce_input, 7, 1, 1, 3)
self.layout.addWidget(self.submit_button, 8, 0, 1, 4)

for i in range(1, self.layout.columnCount()):
self.layout.setColumnStretch(i, 1)
self.layout.setObjectName("createWidget_formLayout")
self.hlayout2.setObjectName("createWidget_hlayout2")
self.submit_button.setObjectName("createWidget_submit_button")
Expand Down Expand Up @@ -261,9 +267,10 @@ def browse(self, path=None):
caption = "Choose File"
if not path:
path = QFileDialog.getOpenFileName(parent=self, caption=caption)
if not path:
return
path = os.path.realpath(path)
if not isinstance(path, str):
path = os.path.normpath(path[0])
else:
path = os.path.normpath(path)
self.window.path_input.clear()
self.window.path_input.insert(path)
self.window.output_input.clear()
Expand Down Expand Up @@ -314,7 +321,10 @@ def browse(self, path=None):
outfile = os.path.splitext(os.path.split(str(path))[-1])[0] + ".torrent"
outpath = os.path.realpath(os.path.join(outdir, outfile))
self.window.output_input.insert(outpath)
_, size, piece_length = path_stat(path)
try:
_, size, piece_length = path_stat(path)
except PermissionError:
return
if piece_length < (2 ** 20):
val = f"{piece_length//(2**10)}KB"
else:
Expand Down Expand Up @@ -346,3 +356,36 @@ class CheckBox(QCheckBox):
def __init__(self, label, parent=None):
super().__init__(label, parent=parent)
self.setStyleSheet(checkBoxSheet)

class PlainTextEdit(QPlainTextEdit):
def __init__(self, parent=None):
super().__init__(parent=parent)
self._parent = parent
self.setBackgroundVisible(True)
self.setStyleSheet(textEditSheet)

def callback(self, msg):
self.insertPlainText(msg)
self.insertPlainText("\n\n")



class Label(QLabel):
"""Label Identifier for Window Widgets.

Subclass: QLabel
"""

def __init__(self, text, parent=None):
super().__init__(text, parent=parent)
self.setStyleSheet(labelSheet)
font = self.font()
font.setBold(True)
font.setPointSize(12)
self.setFont(font)

class LineEdit(QLineEdit):
def __init__(self, parent=None):
super().__init__(parent=parent)
self._parent = parent
self.setStyleSheet(createLineEditSheet)
30 changes: 28 additions & 2 deletions torrentfileQt/infoTab.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@
QPushButton,
QTreeWidgetItem,
QWidget,
QLineEdit,
QLabel,
)

from torrentfileQt.qss import pushButtonSheet
from torrentfileQt.qss import pushButtonSheet, infoLineEditSheet, labelSheet
from torrentfileQt.treewidget import TreeWidget
from torrentfileQt.widgets import InfoLineEdit, Label


class InfoWidget(QWidget):
Expand Down Expand Up @@ -251,3 +252,28 @@ def parse_filetree(filetree):
for k, v in out.items():
paths[os.path.join(key, k)] = v
return paths

class Label(QLabel):
"""Label Identifier for Window Widgets.

Subclass: QLabel
"""

def __init__(self, text, parent=None):
super().__init__(text, parent=parent)
self.setStyleSheet(labelSheet)
font = self.font()
font.setBold(True)
font.setPointSize(12)
self.setFont(font)


class InfoLineEdit(QLineEdit):
def __init__(self, parent=None):
super().__init__(parent=parent)
self.setReadOnly(True)
self.setStyleSheet(infoLineEditSheet)
self.setDragEnabled(True)
font = self.font()
font.setBold(True)
self.setFont(font)
4 changes: 2 additions & 2 deletions torrentfileQt/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def repository(self):
webbrowser.open_new_tab("https://github.com/alexpdev/torrentfileQt")

def about_qt(self):
self.window.app.aboutQt()
self.window.app.aboutQt() # pragma: nocover

def exit_app(self):
self.parent().app.quit()
self.parent().app.quit() # pragma: nocover
Loading