Skip to content

Commit

Permalink
Merge pull request #73 from alexpdev/v0.3.2
Browse files Browse the repository at this point in the history
V0.3.2
  • Loading branch information
alexpdev authored Mar 31, 2022
2 parents 11bc68b + eabe9f6 commit 235758f
Show file tree
Hide file tree
Showing 20 changed files with 411 additions and 291 deletions.
Binary file modified assets/icons/archive.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 modified assets/icons/file.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 modified assets/icons/folder.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 modified assets/icons/hash.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 modified assets/icons/music.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 modified assets/icons/plus.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 modified assets/icons/scale.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 modified assets/icons/video.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
493 changes: 271 additions & 222 deletions coverage.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "torrentfileqt",
"displayName": "TorrentfileQt",
"version": "0.3.1",
"version": "0.3.2",
"description": "GUI torrentfile creator.",
"repository": {
"type": "git",
Expand Down
35 changes: 25 additions & 10 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,34 +248,49 @@ class MockEvent:

def __init__(self, path):
"""Construct event."""
self.prefix = "file:///"
self.path = path
self.accepted = False

def accept(self):
"""Accept function."""
self.accepted = True

def ignore(self):
"""Ignore event."""
self.accepted = False

class MimeData:
"""Mock Qt MimeData class."""

def __init__(self, text):
"""Construct mimeData class."""
self.txt = text
self.dat = {'text/plain': text}
if self.txt == "":
self.hasUrls = False
else:
self.hasUrls = True

def text(self):
"""Return the text passed to constructor."""
return self.txt
class URL:
"""URL Mock object."""

def __init__(self, url):
"""Construct URL Mock object."""
self.url = url

def data(self, key):
"""Return dictionary value that belongs to key."""
return self.dat[key]
def toLocalFile(self):
"""Convert URL to local path."""
return self.url

def urls(self):
"""Return the text passed to constructor."""
return [self.URL(self.txt)]

def mime_data(self):
"""Return a mock of Qt MimeData class."""
text = self.prefix + self.path
mdata = self.MimeData(text)
if not self.path:
mdata = self.MimeData("")
else:
mdata = self.MimeData(self.path)
return mdata

mimeData = mime_data
22 changes: 16 additions & 6 deletions tests/test_edittab.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,20 @@ def test_editor_accept_method(wind, ttorrent):
app.processEvents()
event = MockEvent(ttorrent)
assert editor.dragEnterEvent(event)
assert editor.data == event.mimeData().data('text/plain')
event = MockEvent(None)
assert not editor.dragEnterEvent(event)


def test_editor_move_event(wind, ttorrent):
"""Test move event on editor widget."""
window, app = wind
editor = window.central.editorWidget
editor.window.central.setCurrentWidget(editor)
app.processEvents()
event = MockEvent(ttorrent)
assert editor.dragMoveEvent(event)
event = MockEvent(None)
assert not editor.dragMoveEvent(event)


def test_editor_drop_event(wind, ttorrent):
Expand All @@ -80,19 +93,16 @@ def test_editor_drop_event(wind, ttorrent):
editor.window.central.setCurrentWidget(editor)
app.processEvents()
event = MockEvent(ttorrent)
amount = len("file:///")
assert editor.dropEvent(event)
assert editor.line.text() == event.mimeData().text()[amount:]


def test_editor_drop_false(wind, ttorrent):
def test_editor_drop_false(wind):
"""Test drop event on editor widget is false."""
window, app = wind
editor = window.central.editorWidget
editor.window.central.setCurrentWidget(editor)
app.processEvents()
event = MockEvent(ttorrent)
event.prefix = ""
event = MockEvent(None)
assert not editor.dropEvent(event)


Expand Down
24 changes: 17 additions & 7 deletions tests/test_infotab.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,27 @@ def test_infotab_nested(wind, creator, dir3):


def test_info_accept_method(wind, ttorrent):
"""Test drag enter event on editor widget."""
"""Test drag enter event on info widget."""
window, app = wind
info = window.central.infoWidget
info.window.central.setCurrentWidget(info)
app.processEvents()
event = MockEvent(ttorrent)
assert info.dragEnterEvent(event)
assert info.filename == event.mimeData().data('text/plain')
event = MockEvent(None)
assert not info.dragEnterEvent(event)


def test_info_move_event(wind, ttorrent):
"""Test move event on info widget."""
window, app = wind
info = window.central.infoWidget
info.window.central.setCurrentWidget(info)
app.processEvents()
event = MockEvent(ttorrent)
assert info.dragMoveEvent(event)
event = MockEvent(None)
assert not info.dragMoveEvent(event)


def test_info_drop_event(wind, ttorrent):
Expand All @@ -123,17 +136,14 @@ def test_info_drop_event(wind, ttorrent):
info.window.central.setCurrentWidget(info)
app.processEvents()
event = MockEvent(ttorrent)
amount = len("file:///")
assert info.dropEvent(event)
assert info.pathEdit.text() == event.mimeData().text()[amount:]


def test_info_drop_false(wind, ttorrent):
def test_info_drop_false(wind):
"""Test drop event on editor widget is false."""
window, app = wind
info = window.central.infoWidget
info.window.central.setCurrentWidget(info)
app.processEvents()
event = MockEvent(ttorrent)
event.prefix = ""
event = MockEvent(None)
assert not info.dropEvent(event)
22 changes: 16 additions & 6 deletions tests/test_magnettab.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,20 @@ def test_magnet_accept_method(wind, ttorrent):
app.processEvents()
event = MockEvent(ttorrent)
assert magnet.dragEnterEvent(event)
assert magnet.current_path == event.mimeData().data('text/plain')
event = MockEvent(None)
assert not magnet.dragEnterEvent(event)


def test_magnet_move_event(wind, ttorrent):
"""Test move event on magnet widget."""
window, app = wind
magnet = window.central.magnetWidget
magnet.window.central.setCurrentWidget(magnet)
app.processEvents()
event = MockEvent(ttorrent)
assert magnet.dragMoveEvent(event)
event = MockEvent(None)
assert not magnet.dragMoveEvent(event)


def test_magnet_drop_event(wind, ttorrent):
Expand All @@ -89,17 +102,14 @@ def test_magnet_drop_event(wind, ttorrent):
magnet.window.central.setCurrentWidget(magnet)
app.processEvents()
event = MockEvent(ttorrent)
amount = len("file:///")
assert magnet.dropEvent(event)
assert magnet.metafile_input.text() == event.mimeData().text()[amount:]


def test_magnet_drop_false(wind, ttorrent):
def test_magnet_drop_false(wind):
"""Test drop event on editor widget returns None."""
window, app = wind
magnet = window.central.magnetWidget
magnet.window.central.setCurrentWidget(magnet)
app.processEvents()
event = MockEvent(ttorrent)
event.prefix = ""
event = MockEvent(None)
assert not magnet.dropEvent(event)
3 changes: 0 additions & 3 deletions torrentfileQt/createTab.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,6 @@ def browse(self, path=None):
break





class BrowseDirButton(QPushButton):
"""Browse filesystem folders for path."""

Expand Down
40 changes: 24 additions & 16 deletions torrentfileQt/editorTab.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"""Widgets and procedures for the "Torrent Editor" tab."""

import os
import re
from copy import deepcopy
from pathlib import Path

Expand All @@ -44,6 +43,7 @@ def __init__(self, parent=None):
"""
super().__init__(parent=parent)
self.window = parent.window
self.counter = 0
self.layout = QVBoxLayout()
self.line = QLineEdit(parent=self)
self.line.setStyleSheet("QLineEdit{margin-left: 15px;}")
Expand All @@ -70,24 +70,32 @@ def __init__(self, parent=None):
self.setAcceptDrops(True)

def dragEnterEvent(self, event):
"""Accept drag events for dragging."""
self.data = event.mimeData().data("text/plain")
event.accept()
return True
"""Drag enter event for widget."""
if event.mimeData().hasUrls:
self.counter += 1
event.accept()
return True
self.counter -= 1
return event.ignore()

def dragMoveEvent(self, event):
"""Drag Move Event for widgit."""
if event.mimeData().hasUrls:
self.counter -= 1
event.accept()
return True
self.counter += 1
return event.ignore()

def dropEvent(self, event):
"""Accept drop event."""
pattern = r"^file:/+"
txt = event.mimeData().text()
match = re.match(pattern, txt)
if match:
end = match.end()
txt = txt[end:]
self.line.setText(txt)
self.table.clear()
self.table.handleTorrent.emit(txt)
"""Drag drop event for widgit."""
urls = event.mimeData().urls()
path = urls[0].toLocalFile()
if os.path.exists(path):
self.line.setText(path)
self.table.handleTorrent.emit(path)
return True
return False # pragma: nocover
return False


class Button(QPushButton):
Expand Down
28 changes: 19 additions & 9 deletions torrentfileQt/infoTab.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,27 @@ def clear(self):
widget.clear()

def dragEnterEvent(self, event):
"""Accept incoming drag events."""
self.filename = event.mimeData().data("text/plain")
event.accept()
return True
"""Drag enter event for widget."""
if event.mimeData().hasUrls:
self.data = event.mimeData()
event.accept()
return True
return event.ignore()

def dragMoveEvent(self, event):
"""Drag Move Event for widgit."""
if event.mimeData().hasUrls:
self.data = event.mimeData()
event.accept()
return True
return event.ignore()

def dropEvent(self, event):
"""Accept drop events."""
text = event.mimeData().text()
if text.startswith("file:///"):
text = text[8:]
kws = format_data(text)
"""Accept drop event for info widgit."""
urls = event.mimeData().urls()
path = urls[0].toLocalFile()
if os.path.exists(path):
kws = format_data(path)
self.fill(**kws)
return True
return False
Expand Down
28 changes: 19 additions & 9 deletions torrentfileQt/magnetTab.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,27 @@ def __init__(self, parent=None):
self.setAcceptDrops(True)

def dragEnterEvent(self, event):
"""Accept incoming drag events for magnet tab."""
self.current_path = event.mimeData().data("text/plain")
event.accept()
return True
"""Drag enter event for widget."""
if event.mimeData().hasUrls:
self.urls = event.mimeData().urls()
event.accept()
return True
return event.ignore()

def dragMoveEvent(self, event):
"""Drag Move Event for widgit."""
if event.mimeData().hasUrls:
self.urls = event.mimeData().urls()
event.accept()
return True
return event.ignore()

def dropEvent(self, event):
"""Accept drop events for magnet tab."""
text = event.mimeData().text()
if text.startswith("file:///"):
text = text[8:]
self.metafile_input.setText(text)
"""Drag drop event for widgit."""
urls = event.mimeData().urls()
path = urls[0].toLocalFile()
if os.path.exists(path):
self.metafile_input.setText(path)
self.submit_button.click()
return True
return False
Expand Down
3 changes: 2 additions & 1 deletion torrentfileQt/qss.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,8 @@
border-right-width: 0;
}
QHeaderView::section:checked {
background-color: red;
color: #fff;
background-color: #222;
}
QMenuBar {
background-color: #322;
Expand Down
2 changes: 1 addition & 1 deletion torrentfileQt/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ def _conf():
ASSETS = str(_conf())
os.environ['ASSETS'] = ASSETS

__version__ = "0.3.1"
__version__ = "0.3.2"

0 comments on commit 235758f

Please sign in to comment.