Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yjg30737/pyqt-viewer-widget
PyQt viewer widget
https://github.com/yjg30737/pyqt-viewer-widget
pyqt pyqt-examples pyqt-gui pyqt-viewer pyqt-viewer-widget pyqt5 pyqt5-examples pyqt5-gui pyqt5-tutorial pyqt5-viewer pyqt5-viewer-widget python python3 qgraphicsview qt
Last synced: 18 days ago
JSON representation
PyQt viewer widget
- Host: GitHub
- URL: https://github.com/yjg30737/pyqt-viewer-widget
- Owner: yjg30737
- License: mit
- Created: 2021-12-07T04:28:14.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-07-30T06:17:43.000Z (over 2 years ago)
- Last Synced: 2024-10-11T20:15:28.495Z (about 1 month ago)
- Topics: pyqt, pyqt-examples, pyqt-gui, pyqt-viewer, pyqt-viewer-widget, pyqt5, pyqt5-examples, pyqt5-gui, pyqt5-tutorial, pyqt5-viewer, pyqt5-viewer-widget, python, python3, qgraphicsview, qt
- Language: Python
- Homepage:
- Size: 882 KB
- Stars: 7
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# 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.
* pyqt-comic-viewer - Comic reading app
* pyqt-html-viewer - HTML viewer app
* pyqt-svg-viewer - SVG viewer app## Setup
`python -m pip install pyqt-viewer-widget`## Included Package
* pyqt-toast - to notify user the very beginning/last page when flip the page
* pyqt-single-image-graphics-view - main view## 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)
```python
import osfrom PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton
from pyqt_viewer_widget import ViewerWidgetclass 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 sysapp = 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.