Skip to content

Instantly share code, notes, and snippets.

@eyllanesc
Created November 8, 2017 04:53
Show Gist options
  • Save eyllanesc/3d200020db4af413282dc8a96eb732b5 to your computer and use it in GitHub Desktop.
Save eyllanesc/3d200020db4af413282dc8a96eb732b5 to your computer and use it in GitHub Desktop.
47165998
import os
import os.path
class DownloadItem:
def __init__(self, path):
self.dirname = os.path.dirname(path)
self.filename = os.path.basename(path)
self.fullpath = path
self.type = ""
#----------------- START -----------------------#
entries = ('/home/user/video1.mp4', '/home/user/videos/video11.mkv', '/home/user2/my-vacation.avi', \
'/home/user4/training.avi', '/home/user99/bootleg_movie.mkv')
Listing = []
for item in entries:
obj = DownloadItem(item)
Listing.append(obj)
#!/usr/bin/python3
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QHBoxLayout, QGroupBox, QDialog, QVBoxLayout, \
QGridLayout
from PyQt5.QtCore import pyqtSlot
from DirListing import Listing
class ButtonTest(QDialog):
def __init__(self):
super(ButtonTest, self).__init__()
self.top = 10
self.left = 10
self.width = 320
self.height = 500
self.initUI()
def initUI(self):
self.setWindowTitle("Directory Buttons")
self.setGeometry(self.left, self.top, self.width, self.height)
self.createGridLayout()
windowLayout = QVBoxLayout()
windowLayout.addWidget(self.horizontalGroupBox)
self.setLayout(windowLayout)
self.show()
def createGridLayout(self):
self.horizontalGroupBox = QGroupBox("Joe")
layout = QGridLayout()
counter = 0
for obj in Listing:
button = QPushButton(obj.filename)
button.clicked.connect(self.on_click)
layout.addWidget(button, counter, 0)
counter = counter + 1
self.horizontalGroupBox.setLayout(layout)
@pyqtSlot()
def on_click(self):
print(self.sender().text())
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = ButtonTest()
sys.exit(app.exec_())
#!/usr/bin/python3
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QHBoxLayout, QGroupBox, QDialog, QVBoxLayout, \
QGridLayout
from PyQt5.QtCore import pyqtSlot
from DirListing import Listing
class ButtonTest(QDialog):
def __init__(self):
super(ButtonTest, self).__init__()
self.top = 10
self.left = 10
self.width = 320
self.height = 500
self.initUI()
def initUI(self):
self.setWindowTitle("Directory Buttons")
self.setGeometry(self.left, self.top, self.width, self.height)
self.createGridLayout()
windowLayout = QVBoxLayout()
windowLayout.addWidget(self.horizontalGroupBox)
self.setLayout(windowLayout)
self.show()
def createGridLayout(self):
self.horizontalGroupBox = QGroupBox("Joe")
layout = QGridLayout()
counter = 0
for obj in Listing:
button = QPushButton(obj.filename)
button.clicked.connect(self.on_click)
button.setObjectName(obj.filename)
layout.addWidget(button, counter, 0)
counter = counter + 1
self.horizontalGroupBox.setLayout(layout)
@pyqtSlot()
def on_click(self):
print(self.sender().objectName())
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = ButtonTest()
sys.exit(app.exec_())
#!/usr/bin/python3
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QHBoxLayout, QGroupBox, QDialog, QVBoxLayout, \
QGridLayout
from PyQt5.QtCore import pyqtSlot
from DirListing import Listing
class ButtonTest(QDialog):
def __init__(self):
super(ButtonTest, self).__init__()
self.top = 10
self.left = 10
self.width = 320
self.height = 500
self.initUI()
def initUI(self):
self.setWindowTitle("Directory Buttons")
self.setGeometry(self.left, self.top, self.width, self.height)
self.createGridLayout()
windowLayout = QVBoxLayout()
windowLayout.addWidget(self.horizontalGroupBox)
self.setLayout(windowLayout)
self.show()
def createGridLayout(self):
self.horizontalGroupBox = QGroupBox("Joe")
layout = QGridLayout()
counter = 0
for obj in Listing:
button = QPushButton(obj.filename)
button.clicked.connect(lambda checked, filename=obj.filename: self.on_click(filename))
layout.addWidget(button, counter, 0)
counter = counter + 1
self.horizontalGroupBox.setLayout(layout)
@pyqtSlot()
def on_click(self, filename):
print(filename)
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = ButtonTest()
sys.exit(app.exec_())
#!/usr/bin/python3
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QHBoxLayout, QGroupBox, QDialog, QVBoxLayout, \
QGridLayout, QButtonGroup
from PyQt5.QtCore import pyqtSlot
from DirListing import Listing
class ButtonTest(QDialog):
def __init__(self):
super(ButtonTest, self).__init__()
self.top = 10
self.left = 10
self.width = 320
self.height = 500
self.initUI()
def initUI(self):
self.setWindowTitle("Directory Buttons")
self.setGeometry(self.left, self.top, self.width, self.height)
self.createGridLayout()
windowLayout = QVBoxLayout()
windowLayout.addWidget(self.horizontalGroupBox)
self.setLayout(windowLayout)
self.show()
def createGridLayout(self):
self.horizontalGroupBox = QGroupBox("Joe")
layout = QGridLayout()
counter = 0
group = QButtonGroup(self)
for obj in Listing:
button = QPushButton(obj.filename)
layout.addWidget(button, counter, 0)
counter = counter + 1
group.addButton(button, counter)
group.buttonClicked[int].connect(self.on_click)
group.buttonClicked.connect(self.on_click2)
self.horizontalGroupBox.setLayout(layout)
@pyqtSlot(int)
def on_click(self, i):
print("button{}".format(i))
def on_click2(self, btn):
print(btn.text())
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = ButtonTest()
sys.exit(app.exec_())
#!/usr/bin/python3
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QHBoxLayout, QGroupBox, QDialog, QVBoxLayout, \
QGridLayout
from PyQt5.QtCore import pyqtSlot
from DirListing import Listing
class ButtonTest(QDialog):
def __init__(self):
super(ButtonTest, self).__init__()
self.top = 10
self.left = 10
self.width = 320
self.height = 500
self.initUI()
def initUI(self):
self.setWindowTitle("Directory Buttons")
self.setGeometry(self.left, self.top, self.width, self.height)
self.createGridLayout()
windowLayout = QVBoxLayout()
windowLayout.addWidget(self.horizontalGroupBox)
self.setLayout(windowLayout)
self.show()
def createGridLayout(self):
self.horizontalGroupBox = QGroupBox("Joe")
layout = QGridLayout()
counter = 0
for obj in Listing:
button = QPushButton(obj.filename)
import functools
button.clicked.connect(functools.partial(self.on_click, obj.filename))
layout.addWidget(button, counter, 0)
counter = counter + 1
self.horizontalGroupBox.setLayout(layout)
def on_click(self, filename):
print(filename)
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = ButtonTest()
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment