Skip to main content

PyQt viewer widget which helps you make viewer application easily

Project description

pyqt-viewer-widget

PyQt viewer widget which helps you make viewer application easily

Requirements

PyQt5 >= 5.8

Overview

This is image viewer widget, not an application itself. But you can make image viewer application out of this.

For example, apps below are using this efficiently.

Setup

python -m pip install pyqt-viewer-widget

Included Package

Feature

  • setExtensions(extensions: list) to set file extensions to show on the view (e.g. ['.html'])

  • addFilenames(filenames: list, cur_filename: str = '') - Add filenames. cur_filename is file's name which you want to set as current file.

  • setFilenames(filenames: list, cur_filename: str = '') - Clear file list before adding files.

  • addDirectory(dirname: str, cur_filename: str = '') - Add files in the directory

  • setDirectory(dirname: str, cur_filename: str = '') - Clear file list before adding files in the directory

  • setCurrentIndex(idx: int), getCurrentIndex() -> int. The latter one can be used for checking at least one file exists or not.

  • setCurrentFilename(filename: str), getCurrentFilename() -> str.

  • clear()

  • Flip the page back and forth with prev, next button on bottom navigation widget, mouse wheel, left and right pad of keyboards.

  • Being able to check the current page

  • Being able to toggle the visibility of the bottom widget

  • Give the emitting signal when clicked prev, next, close buttons: prevSignal(str), nextSignal(str), closeSignal(bool) - prev/next signals' arguments are previous/next file's name. close signal's bool value is always False to set the visibility of bottom widget (navigation widget) of viewer widget False. There's also clearSignal which is emitted when there is no file. (except for init moment)

  • When you've got the absoulte beginning/last of the files list, toast(pyqt-toast) will show up. You can get either direction of toast with getFirstPageToast, getLastPageToast to change the toast's style such as font, color.

  • setView(view: QWidget), getView() -> QWidget

  • setBottomWidgetVisible(f: bool) to toggle the visibility of bottom navigation bar.

  • getFirstPageToast() -> Toast, getLastPageToast() -> Toast

  • setWindowTitleBasedOnCurrentFileEnabled(f: bool, prefix: str) to set the title based on current file like "Prefix - def.png" if current file of viewer is "def.png". You can activate the feature by giving True to first argument f. You can give the default window title to prefix.

  • isWindowTitleBasedOnCurrentFileEnabled() -> bool

  • removeSomeFilesFromViewer(filenames_to_remove: list) is used when you want to remove some files in viewer, not all files. If filenames_to_remove includes the file name which was not included in list, error will be occured.

  • setHome(widget: QWidget) to set home page widget, goHome().

Simple Example

Code Example (Extremely basic image viewer)

import os



from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton

from pyqt_viewer_widget import ViewerWidget





class MainWindow(QMainWindow):

    def __init__(self):

        super().__init__()

        self.__initUi()



    def __initUi(self):

        self.__viewerWidget = ViewerWidget()

        dirname = os.path.join(os.getcwd(), 'viewerWidgetExampleImagesDir')

        self.__viewerWidget.setExtensions(['.jpg'])

        self.__viewerWidget.setDirectory(dirname)

        self.__viewerWidget.closeSignal.connect(self.__bottomWidgetClosed)



        self.setCentralWidget(self.__viewerWidget)

        self.__setToolBar()



    def __setToolBar(self):

        self.__bottomWidgetToggleBtn = QPushButton('Show')

        self.__bottomWidgetToggleBtn.setCheckable(True)

        self.__bottomWidgetToggleBtn.setChecked(True)

        self.__bottomWidgetToggleBtn.toggled.connect(self.__viewerWidget.setBottomWidgetVisible)



        fileToolbar = self.addToolBar('File')

        fileToolbar.addWidget(self.__bottomWidgetToggleBtn)

        fileToolbar.setMovable(False)



    def __bottomWidgetClosed(self):

        self.__bottomWidgetToggleBtn.setChecked(False)





if __name__ == "__main__":

    import sys



    app = QApplication(sys.argv)

    mainWindow = MainWindow()

    mainWindow.show()

    sys.exit(app.exec_())

Result

https://user-images.githubusercontent.com/55078043/145040849-0c7326ed-e043-4a8b-8c55-c9b7e1d1756e.mp4

Note: This is result of very first version.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyqt-viewer-widget-0.0.20.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

pyqt_viewer_widget-0.0.20-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file pyqt-viewer-widget-0.0.20.tar.gz.

File metadata

  • Download URL: pyqt-viewer-widget-0.0.20.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/0.0.0 CPython/3.7.6

File hashes

Hashes for pyqt-viewer-widget-0.0.20.tar.gz
Algorithm Hash digest
SHA256 490eeedffc5f9979c23a69795dcf3564df0bf7a95e0ad85e9a18c61a3b172d7c
MD5 212b7118a0e555d8c6244824ecf688ca
BLAKE2b-256 b69478b859aa9e26349639f17ba447e105dcde41201848143227a74021a9222c

See more details on using hashes here.

File details

Details for the file pyqt_viewer_widget-0.0.20-py3-none-any.whl.

File metadata

File hashes

Hashes for pyqt_viewer_widget-0.0.20-py3-none-any.whl
Algorithm Hash digest
SHA256 f16d1e933ea0a3d7d5ee1fb83d271414d4bb5fd382b692f9c13302053eef77bb
MD5 5e2f07702921181f1b85bf1647e140b6
BLAKE2b-256 7cdc4067b83c9ecdbf779e733abc8333b5e1a1b94fa90b23c9ec2246165d9c78

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page