Skip to content

Commit

Permalink
1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Kadir Aksoy committed May 14, 2021
1 parent f770b57 commit 46f77c2
Show file tree
Hide file tree
Showing 32 changed files with 2,737 additions and 1,431 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
__pycache__/
dev/
dist/
olddist/
pyqt5Custom.egg-info/
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
<p>
<img src="https://img.shields.io/badge/python-3.6%2B-green">
<img src="https://img.shields.io/badge/license-GPL%203.0-blue.svg">
<img src="https://img.shields.io/badge/version-0.0.4-orange">
<img src="https://img.shields.io/badge/version-1.0.0-orange">
</p>
More useful and stylish widgets for PyQt5 such as toggle switches, animated buttons, etc..
More useful and stylish widgets for PyQt5 such as toggle switches, animated buttons, etc..
<br>
<img src="https://github.com/kadir014/pyqt5-custom-widgets/blob/main/examples/data/showcase.gif" width="500">

**DISCLAIMER:** \
Currently most widgets can't use style sheets properly so you have to use attributes to stylize them. I'm working on removing this inconvenience and make their usage as close as to base Qt widgets
<img src="https://github.com/kadir014/pyqt5-custom-widgets/blob/main/examples/data/showcase.gif" width="500">

## Table of Contents
- [Installing](#Installing)
Expand All @@ -22,8 +19,15 @@ Currently most widgets can't use style sheets properly so you have to use attrib
- [License](#License)

## Installing
The module (version 0.0.4) is not on PyPi yet, so you have to manually download `pyqt5Custom` folder. Version 0.0.5 will be on PyPi. \
You can also use PySide2 instead of PyQt5 with just litte changes.
Install using PIP (it might be `pip3` or `python3` depending on your platform)
```
pip install pyqt5Custom
```
or
```
python -m pip install pyqt5Custom
```
Also you can also use PySide2 instead of PyQt5 with just litte changes.

## Usage
Just import `pyqt5Custom` and you're ready to go. You can check out [Examples](https://github.com/kadir014/pyqt5-custom-widgets/blob/main/examples/), one little example for ToggleSwitch widget:
Expand All @@ -45,6 +49,7 @@ layout.addWidget(togglesw)
| ![ImageBox](https://github.com/kadir014/pyqt5-custom-widgets/blob/main/examples/data/imagebox.png) <br> **ImageBox** <br> [Documentation](documentation.md) | ![ColorPicker](https://github.com/kadir014/pyqt5-custom-widgets/blob/main/examples/data/colorpicker.png) <br> **ColorPicker** <br> [Documentation](documentation.md) |
| ![DragDropFile](https://github.com/kadir014/pyqt5-custom-widgets/blob/main/examples/data/dropfileshowcase.gif) <br> **DragDropFile** <br> [Documentation](documentation.md) | ![EmbedWindow](https://github.com/kadir014/pyqt5-custom-widgets/blob/main/examples/data/embedwindowshowcase.gif) <br> **EmbedWindow** <br> [Documentation](documentation.md) |
| ![CodeTextEdit](https://github.com/kadir014/pyqt5-custom-widgets/blob/main/examples/data/codetextshowcase.gif) <br> **CodeTextEdit** <br> [Documentation](documentation.md) | ![TitleBar](https://github.com/kadir014/pyqt5-custom-widgets/blob/main/examples/data/titlebarshowcase.png) <br> **TitleBar** <br> [Documentation](documentation.md) |
| ![Spinner](https://github.com/kadir014/pyqt5-custom-widgets/blob/main/examples/data/spinnershowcase.gif) <br> **Spinner** <br> [Documentation](documentation.md) | ![Toast](https://github.com/kadir014/pyqt5-custom-widgets/blob/main/examples/data/toastshowcase.gif) <br> **Toast** <br> [Documentation](documentation.md) |


## Dependencies
Expand Down
45 changes: 31 additions & 14 deletions documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,17 @@ Here is the list of currently implemented widgets
- [EmbedWindow](#DEmbedWindow)
- [CodeTextEdit](#CodeTextEdit)
- [TitleBar](#TitleBar)
- [Misc](#misc)
- [Spinner](#Spinner)
- [Toast](#Toast)

## Other stuff
Other stuff that the the library provides but are not mainly widgets. Some are tools, data classes, etc...
- [RequestHandler](#RequestHandler)
- [FileDetails](#FileDetails)
- [Animation](#Animation)
- [AnimationHandler](#AnimationHandler)
- [ColorPreview](#ColorPreview)
- [SyntaxHighlighter](#SyntaxHighlighter)


## ToggleSwitch
Expand Down Expand Up @@ -121,13 +130,21 @@ Here is the list of currently implemented widgets
- `title()` (str) : Get title


# Misc
Other stuff _(which you mostly don't need to know they existed)_ included within the module other than custom widgets
- [FileDetails](#FileDetails)
- [ColorPreview](#ColorPreview)
- [SyntaxHighlighter](#SyntaxHighlighter)
- [Animation](#Animation)
- [AnimationHandler](#AnimationHandler)
# Other stuff
Other stuff that the the library provides but are not mainly widgets. Some are tools, data classes, etc...

## RequestHandler
`RequestHandler` is a thread (QThread) that can be used to handle HTTP requests while avoiding blocking Qt's event loop. You can see [Examples](https://github.com/kadir014/pyqt5-custom-widgets/blob/main/examples/) to see usage of this class.

#### Methods
- `newRequest(method, url, headers, data)`
- `method` (str) : Request method
- `url` (str) : Address where request will be sent at
- `headers` (dict) : Request headers
- `data` (dict) : Request data

#### Signals
- `requestResponded` : Emitted when a requeest in the current pool gets responded. Response is a [requests.Response](https://docs.python-requests.org/en/latest/api/#requests.Response) object

## FileDetails
`FileDetails` object is a data class which is meant to be used by `DragDropFile` for `fileDropped` signal
Expand All @@ -139,14 +156,14 @@ Other stuff _(which you mostly don't need to know they existed)_ included within
- `pureName` (str) : File's name without the extension
- `extension` (str) : File's extension

## ColorPreview
`ColorPreview` is a widget to display some color. It can bee seen used next to ColorPicker example. But this widget is most likely going to be deprecated

## SyntaxHighlighter
`SyntaxHighlighter` inherits `QSyntaxHighlighter`, it's only purpose is to serve `CodeTextEdit` widget. `pyqt5Custom` module currently (version 0.0.4) supports only Python and C++ syntax highlighting.

## Animation
`Animation` is just a static class holding easing animation functions. This class is most likely going to be deprecated when I rework animations.

## AnimationHandler
`AnimationHandler` animates widget's properties using `Animation` class's functions. This class is most likely going to be deprecated when I rework animations.

## ColorPreview
`ColorPreview` is a widget to display some color. It can bee seen used next to ColorPicker example. But this widget is most likely going to be deprecated

## SyntaxHighlighter
`SyntaxHighlighter` inherits `QSyntaxHighlighter`, it's only purpose is to serve `CodeTextEdit` widget. `pyqt5Custom` module currently supports only Python and C++ syntax highlighting.
Binary file added examples/data/SFPro.ttf
Binary file not shown.
Binary file added examples/data/checkicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/data/dlicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/data/homeiconw.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/data/spinnericon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/data/spinnershowcase.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/data/styledbutton.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
149 changes: 149 additions & 0 deletions examples/requesthandler_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# PyQt5 Custom Widgets #
# GPL 3.0 - Kadir Aksoy #
# https://github.com/kadir014/pyqt5-custom-widgets #
# #
# This script is one of the pyqt5Custom examples #


import sys
import time

from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QWidget, QApplication, QHBoxLayout, QVBoxLayout, QLabel, QLineEdit
from PyQt5.QtGui import QColor, QFontDatabase

from pyqt5Custom import StyledButton, TitleBar, Spinner, RequestHandler



class MainWindow(QWidget):
def __init__(self):
super().__init__()

self.setFixedSize(400, 400)
self.setGeometry(100, 100, 400, 400)
self.setWindowTitle("RequestHandler Example")

QFontDatabase.addApplicationFont("data/SFPro.ttf")

self.setAutoFillBackground(True)
p = self.palette()
p.setColor(self.backgroundRole(), QColor(255, 255, 255))
self.setPalette(p)

self.layout = QVBoxLayout()
self.layout.setAlignment(Qt.AlignTop)
self.setLayout(self.layout)
self.layout.setContentsMargins(0, 0, 0, 0)

# Creating and starting the RequestHandler object
self.rh = RequestHandler()
self.rh.start()

self.btn = StyledButton("GET Request", icon="data/dlicon.png")
self.btn.setIconSize(33, 33)
self.btn.setMinimumSize(178, 44)
self.btn.setStyleDict({
"background-color" : (52, 199, 89),
"border-color" : (2, 199, 89),
"border-radius" : 39,
"color" : (255, 255, 255),
"font-family" : "SF Pro Display",
"font-size" : 21,
})
self.btn.setStyleDict({
"background-color" : (47, 212, 119),
"border-color" : (47, 212, 119)
}, "hover")
self.btn.setStyleDict({
"background-color" : (89, 227, 149),
"border-color" : (89, 227, 149),
"color" : (255, 255, 255),
}, "press")

self.layout.addSpacing(80)
self.layout.addWidget(self.btn, alignment=Qt.AlignHCenter)

self.search = QLineEdit()
self.search.setFixedSize(220, 41)
self.search.setStyleSheet("padding: 10px; padding-bottom: 3px; font-size:16px; font-family: SF Pro Display; border: none; border-bottom: 2px solid rgb(0,122,255);")
self.search.setText("https://github.com/")
self.layout.addWidget(self.search, alignment=Qt.AlignHCenter)

self.layout.addSpacing(25)

self.panel = QWidget()
self.panel.setStyleSheet("font-size: 17px; font-family: SF Pro Default;")
self.panel.setFixedWidth(350)
self.panellyt = QVBoxLayout()
self.panellyt.setContentsMargins(0, 10, 0, 10)
self.panel.setLayout(self.panellyt)
self.layout.addWidget(self.panel, alignment=Qt.AlignHCenter)

self.panel.setAutoFillBackground(True)
p = self.panel.palette()
p.setColor(self.backgroundRole(), QColor(250, 250, 250))
self.panel.setPalette(p)

self.row1 = QHBoxLayout()
self.panellyt.addLayout(self.row1)
self.row1.setContentsMargins(10, 0, 10, 0)

self.row2wdt = QWidget()
self.row2 = QHBoxLayout()
self.row2wdt.setLayout(self.row2)
self.panellyt.addWidget(self.row2wdt)
self.row2.setContentsMargins(10, 8, 10, 8)

self.row2wdt.setAutoFillBackground(True)
p = self.row2wdt.palette()
p.setColor(self.backgroundRole(), QColor(222, 222, 222))
self.row2wdt.setPalette(p)

self.row3 = QHBoxLayout()
self.panellyt.addLayout(self.row3)
self.row3.setContentsMargins(10, 0, 10, 0)

self.info_status_d = QLabel("HTTP Code:")
self.info_status = QLabel("0")
self.row1.addWidget(self.info_status_d, alignment=Qt.AlignLeft)
self.row1.addWidget(self.info_status, alignment=Qt.AlignRight)

self.info_conlength_d = QLabel("Response content size:")
self.info_conlength = QLabel("0 MB")
self.row2.addWidget(self.info_conlength_d, alignment=Qt.AlignLeft)
self.row2.addWidget(self.info_conlength, alignment=Qt.AlignRight)

self.info_elaps_d = QLabel("Elapsed time:")
self.info_elaps = QLabel("0 ms")
self.row3.addWidget(self.info_elaps_d, alignment=Qt.AlignLeft)
self.row3.addWidget(self.info_elaps, alignment=Qt.AlignRight)


@self.btn.clicked.connect
def slot():
self.btn.setIcon(Spinner(2.4, QColor(255, 255, 255)))
# Add new GET request to the pool
self.rh.newRequest("GET", self.search.text())

@self.rh.requestResponsed.connect
def slot(response):
self.btn.setIcon("data/dlicon.png")
self.btn.setIconSize(28, 28)

self.info_status.setText(str(response.status_code))
l = len(response.content) / 1048576
if l > 1: l = int(l)

self.info_conlength.setText(f"{l:.2} MB")
self.info_elaps.setText(str(response.elapsed.microseconds//1000)+" ms")



if __name__ == "__main__":
app = QApplication(sys.argv)

mw = MainWindow()
mw.show()

sys.exit(app.exec_())
Loading

0 comments on commit 46f77c2

Please sign in to comment.