Coder Social home page Coder Social logo

yjg30737 / pyqt-image-file-explorer-table-widget Goto Github PK

View Code? Open in Web Editor NEW
11.0 1.0 3.0 55 KB

PyQt QTableWidget for image file explorer

License: MIT License

Python 98.39% CSS 1.61%
pyqt5-image-file-explorer pyqt-image-file-explorer pyqt5-file-explorer pyqt-file-explorer image-file-explorer file-explorer pyqt5-qtablewidget pyqt-qtablewidget qtablewidget pyqt5

pyqt-image-file-explorer-table-widget's Introduction

pyqt-image-file-explorer-table-widget

PyQt QTableWidget for image file explorer

Requirements

PyQt5 >= 5.8

Setup

python -m pip install pyqt-image-file-explorer-table-widget

Included Packages

Feature

  • Being able to set column count with setColumnCount(columns: int)
  • Being able to remove selected cells with removeSelectedCells()
  • Set cell padding with setCellPadding(padding: int). No padding by defeault.
  • Set cell margin (set space between cells) with setCellMargin(margin: int) - This doesn't give the space between cells, just looks like it. I will figure it out how to set the space between cells properly. No margin by default.
  • Resize friendly
  • If you want to add grid(no grid by default), use setShowGrid(f: bool) even though this is provided by QTableWidget originally.
  • showTinyImageBigger(f: bool) to expand image which is so small that it's hard to see

Example

import os

from pyqt_image_file_explorer_table_widget.imageFileExplorerTableWidget import ImageFileExplorerTableWidget
from PyQt5.QtWidgets import QWidget, QPushButton, QHBoxLayout, QGridLayout, QFileDialog, QApplication


class ImageFileExplorerExample(QWidget):
    def __init__(self):
        super().__init__()
        self.__initUi()

    def __initUi(self):
        self.__tableWidget = ImageFileExplorerTableWidget()

        addBtn = QPushButton('Add')
        addBtn.clicked.connect(self.__add)

        delBtn = QPushButton('Remove')
        delBtn.clicked.connect(self.__delete)

        lay = QHBoxLayout()
        lay.addWidget(addBtn)
        lay.addWidget(delBtn)
        lay.setContentsMargins(0, 0, 0, 0)

        btns = QWidget()
        btns.setLayout(lay)

        self.__tableWidget.setColumnCount(6)

        lay = QGridLayout()
        lay.addWidget(btns)
        lay.addWidget(self.__tableWidget)
        lay.setContentsMargins(0, 0, 0, 0)

        self.setLayout(lay)

    def __add(self):
        dirname = QFileDialog.getExistingDirectory(self, 'Open directory', '')
        if dirname:
            filenames = [os.path.join(dirname, filename) for filename in os.listdir(dirname)]
            filenames = list(filter(lambda x: os.path.splitext(x)[-1] in ['.png'],
                                    [filename for filename in filenames])) # In this example, png only
            self.__tableWidget.addCells(filenames)

    def __delete(self):
        self.__tableWidget.removeSelectedCells()


if __name__ == "__main__":
    import sys

    app = QApplication(sys.argv)
    imageFileExplorerExample = ImageFileExplorerExample()
    imageFileExplorerExample.show()
    app.exec_()

Result

image

After select add.png, addTab.png, bold.png and remove all of them

image

pyqt-image-file-explorer-table-widget's People

Contributors

yjg30737 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.