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 #23

Merged
merged 6 commits into from
Nov 9, 2021
Merged

Dev #23

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
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ help:

clean: clean-build ## remove all build, test, coverage and Python artifacts

upgrade: clean ## upgrade all dependencies
python -m pip install --upgrade pip
pip install --upgrade --pre -rrequirements.txt

environment:
.\env\Scripts\activate.bat

Expand Down
Binary file removed assets/percentage.png
Binary file not shown.
Binary file removed assets/ruler.png
Binary file not shown.
Binary file added assets/scale.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
torrentfile
pyben
PyQt6
224 changes: 95 additions & 129 deletions torrentfileQt/checkTab.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ def submit(self):
CheckerClass.register_callback(textEdit.callback)
logging.debug("Registering Callback, setting root")
piece_hasher(metafile, content, tree)
# tree.start_thread(metafile, content)


class BrowseTorrents(QToolButton):
Expand Down Expand Up @@ -214,67 +213,92 @@ def browse(self, path=None):
self.parent().searchInput.setText(path)


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


class LogTextEdit(QPlainTextEdit):
def __init__(self, parent=None):
super().__init__(parent=parent)
self._parent = parent
self.setBackgroundVisible(True)
font = self.font()
font.setFamily("Consolas")
font.setBold(True)
font.setPointSize(8)
self.setFont(font)
self.setStyleSheet(logTextEditSheet)

def clear_data(self):
self.clear()

def callback(self, msg):
self.insertPlainText(msg)
self.insertPlainText("\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 TreePieceItem(QTreeWidgetItem):
def __init__(self, type=0, tree=None):
super().__init__(type=type)
policy = self.ChildIndicatorPolicy.DontShowIndicatorWhenChildless
self.setChildIndicatorPolicy(policy)
self.tree = tree
self.window = tree.window
self.counted = self.value = 0
self.progbar = None
self.total = self.value = self.counted = 0

def setProgressBar(self, progressBar, size):
self.total = size
self.progbar = progressBar
self.progbar.setRange(0, size)
@property
def total(self):
return self.progbar.total

def addValue(self, value):
left = self.total - self.counted
if left > value:
self.progbar.addValue(value)
self.value += value
self.counted += value
return 0
self.progbar.addValue(left)
self.counted += left
self.value += left
remainder = value - left
return remainder

def counted(self, value):
left = self.total - self.counted
if left < value:
self.counted += left
remainder = value - left
return remainder
if self.counted + value > self.total:
consumed = self.total - self.value
else:
consumed = value
self.value += consumed
self.counted += consumed
self.progbar.valueChanged.emit(consumed)
self.window.app.processEvents()
return consumed

def cont(self, value):
if self.counted + value > self.total:
consumed = self.total - self.value
self.counted += consumed
return consumed
self.counted += value
return 0
return value


class ProgressBar(QProgressBar):

def __repr__(self):
return f"<TreeItem: {self.val}>"


class Filler:
def __init__(self, **kwargs):
self.tree = kwargs["tree"]
self.value = None
self.expected = None

def set_val(self, val, expected):
self.expected = expected
self.value = val

def text(self):
if self.expected:
return self.expected

valueChanged = pyqtSignal([int])

class ProgressBar(QProgressBar):
def __init__(self, parent=None):
def __init__(self, parent=None, size=0):
super().__init__(parent=parent)
self.setRange(0, 100)
self.total = size
self.setValue(0)
self.setRange(0, size)
self.valueChanged.connect(self.addValue)

def addValue(self, value):
currentvalue = self.value()
Expand Down Expand Up @@ -311,17 +335,8 @@ def __init__(self, parent=None):
self.total = 0
self.piece_length = None
self.item_tree = {"widget": self.item}
self.valueUpdate.connect(self.updateValue)
self.addPathChild.connect(self.add_path_child)

def updateValue(self, args):
actual, expected, path, size = args
widget = self.itemWidgets[path]["widget"]
# print(actual, expected)
if actual == expected:
widget.add_piece(size)
self.window.repaint()

def clear(self):
super().clear()
self.item_tree = {"widget": self.invisibleRootItem()}
Expand All @@ -344,16 +359,16 @@ def add_path_child(self, path, size):
item_tree[partial] = {"widget": item}
if i == len(partials) - 1:
fileicon = QIcon("./assets/file.png")
progressBar = ProgressBar()
progressBar = ProgressBar(parent=None, size=size)
self.setItemWidget(item, 2, progressBar)
item.setProgressBar(progressBar, size)
item.progbar = progressBar
self.itemWidgets[str(path)] = item
else:
fileicon = QIcon("./assets/folder.png")
item.setIcon(0, fileicon)
item.setText(1, partial)
item_tree = item_tree[partial]
self.window.repaint()
self.window.app.processEvents()
self.paths.append(path)

def remainder(self, path):
Expand All @@ -362,81 +377,32 @@ def remainder(self, path):


def piece_hasher(metafile, content, tree):
mapping = {}
checker = CheckerClass(metafile, content)
parent = os.path.dirname(content)
fileinfo = checker.fileinfo
pathlist = checker.paths
for path in pathlist:
relpath = path.lstrip(parent)
length = checker.fileinfo[path]["length"]
relpath = path.lstrip(tree.root)
length = fileinfo[path]["length"]
tree.addPathChild.emit(relpath, length)
index, current = 0, None
if checker.meta_version == 1:
current = 0
for actual, expected, path, size in checker.iter_hashes():
value = size
while True:
path = pathlist[current].lstrip(tree.root)
widget = tree.itemWidgets[path]
if actual == expected:
consumed = widget.addValue(value)
else:
consumed = widget.count(value)
value -= consumed
if not value:
break
current += 1
return
for actual, expected, path, size in checker.iter_hashes():
print(mapping)
if not current: current = path
elif path != current:
current = path
index = pathlist.index(path)
relpath = path.lstrip(parent)
widget = tree.itemWidgets[relpath]
if actual == expected:
methodname = "addValue"
leaf = tree.itemWidgets[path.lstrip(tree.root)]
leaf.addValue(size)
else:
methodname = "counted"
method = widget.__getattribute__(methodname)
remainder = method(size)
mapping[path] = {"size": size, "remiander": remainder}
while remainder > 0:
index += 1
nextpath = pathlist[index]
current = nextpath
rpath = nextpath.lstrip(parent)
nwidget = tree.itemWidgets[rpath]
size = remainder
method = nwidget.__getattribute__(methodname)
remainder = method(size)
mapping[nextpath] = {"size": size, "remiander": remainder}


class LogTextEdit(QPlainTextEdit):
def __init__(self, parent=None):
super().__init__(parent=parent)
self._parent = parent
self.setBackgroundVisible(True)
font = self.font()
font.setFamily("Consolas")
font.setBold(True)
font.setPointSize(8)
self.setFont(font)
self.setStyleSheet(logTextEditSheet)

def clear_data(self):
self.clear()

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




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)
leaf.count(size)
Loading