Skip to content

Commit

Permalink
1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Kadir Aksoy committed May 15, 2021
1 parent d6408a9 commit 638df4f
Show file tree
Hide file tree
Showing 10 changed files with 225 additions and 67 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ dist/
olddist/
pyqt5Custom.egg-info/
setup.py
MANIFEST.in
42 changes: 24 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<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-1.0.0-orange">
<img src="https://img.shields.io/badge/version-1.0.1-orange">
</p>
More useful and stylish widgets for PyQt5 such as toggle switches, animated buttons, etc..
<br>
Expand All @@ -12,9 +12,9 @@ More useful and stylish widgets for PyQt5 such as toggle switches, animated butt
- [Installing](#Installing)
- [Usage](#Usage)
- [Widgets](#Widgets)
- [Examples](#Examples)
- [Documentation](#Documentation)
- [Styling Reference](#Styling)
- [Examples](#References)
- [Documentation](#References)
- [Styling Reference](#References)
- [Dependencies](#Dependencies)
- [TODO](#Todo)
- [License](#License)
Expand All @@ -31,15 +31,25 @@ 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:
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 StyledButton widget:
```py
from pyqt5Custom import ToggleSwitch
from pyqt5Custom import StyledButton

...

togglesw = ToggleSwitch("Turn on/off the lights", style="ios")
togglesw.setStyleSheet("font-size:15px; color: #444444;")
layout.addWidget(togglesw)
btn = StyledButton(text="Hello!")
btn.setStyleDict({
"border-radius" : 20,
"font-family" : "Helvetica",
"font-size" : 17
})

@btn.clicked.connect
def slot():
print("Quitting!")
app.exit()

layout.addWidget(btn)

...
```
Expand All @@ -49,17 +59,13 @@ 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) |
| ![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.gif) <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) |

## Examples
See [examples](https://github.com/kadir014/pyqt5-custom-widgets/blob/main/examples/) page

## Documentation
See [documentation](documentation.md) page

# Styling
See [styling reference](stylingref.md) page
## References
- See [Examples](https://github.com/kadir014/pyqt5-custom-widgets/blob/main/examples/) page for examples
- See [Documentation](documentation.md) page for documentation and detailed widget references
- See [styling reference](stylingref.md) page for styling instructions on custom widget

## Dependencies
- [PyQt5](https://pypi.org/project/PyQt5/)
Expand Down
38 changes: 34 additions & 4 deletions documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,51 @@ Other stuff that the the library provides but are not mainly widgets. Some are t
## TitleBar
`TitleBar` lets the developer use a custom window title bar, this widget also provides window resizing controls (WIP) \
\
![TitleBar](https://github.com/kadir014/pyqt5-custom-widgets/blob/main/examples/data/titlebarshowcase.png)
![TitleBar](https://github.com/kadir014/pyqt5-custom-widgets/blob/main/examples/data/titlebarshowcase.gif)

#### Parameters
- `parent` (QWidget) : Parent widget of the window
- `title` (str) : Title of the window (Optional)

#### Attributes
- `close_btn` (StyledButton) : Close button
- `max_btn` (StyledButton) : Maximize button
- `min_btn` (StyledButton) : Minimize button
- `closeButton` (StyledButton) : Close button
- `maxButton` (StyledButton) : Maximize button
- `minButton` (StyledButton) : Minimize button

#### Methods
- `setTitle(title)` : Change title
- `title()` (str) : Get title

## Spinner
`Spinner` is just a visual widget that has a spinning circle on it. You can use this as `icon` parameter on widgets that has icons\
\
![Spinner](https://github.com/kadir014/pyqt5-custom-widgets/blob/main/examples/data/spinnershowcase.gif)

#### Parameters
- `width` (float) : Width of the circle
- `color` (QColor) : Color of the circle

## Toast
`Toast` is notification widget that appears at the bottom of the window.\
\
![Toast](https://github.com/kadir014/pyqt5-custom-widgets/blob/main/examples/data/toastshowcase.gif)

#### Parameters
- `parent` (QWidget) : Parent widget
- `text` (str) : Text of the widget (Optional)
- `icon` (str/Spinner) : Icon of the widget (Optional)
- `closeButton` (bool) : Whether to show the close button or not

#### Methods
- `rise(duration: int)` : Shows the toast notification for duration seconds
- `fall()` : Hides the toast notification

<br>
<br>
<br>
<br>
<br>


# Other stuff
Other stuff that the the library provides but are not mainly widgets. Some are tools, data classes, etc...
Expand Down
11 changes: 8 additions & 3 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ You can view or run example scripts to have a better understanding of the `pyqt5
Assets in the `data` folder is _**only for examples**_ and is not required to use the module alone. \
\
Quick look at example scripts:
- `example_showcase.py` is an example where most widgets and styling variatons are shown <br><img src="https://github.com/kadir014/pyqt5-custom-widgets/blob/main/examples/data/showcase.gif" width="450">
- `example_requesthandler.py` is an example about using RequestHandler class <br><img src="https://github.com/kadir014/pyqt5-custom-widgets/blob/main/examples/data/rqshowcase.gif" width="250">
- `example_ios.py` is a replica of iOS design <br><img src="https://github.com/kadir014/pyqt5-custom-widgets/blob/main/examples/data/iosshowcase.gif" width="450">
## `example_showcase.py` is an example where most widgets and styling variatons are shown
<img src="https://github.com/kadir014/pyqt5-custom-widgets/blob/main/examples/data/showcase.gif" width="450">
## `example_requesthandler.py` is an example about using RequestHandler class
<img src="https://github.com/kadir014/pyqt5-custom-widgets/blob/main/examples/data/rqshowcase.gif" width="250">
## `example_ios.py` is a replica of iOS design
<img src="https://github.com/kadir014/pyqt5-custom-widgets/blob/main/examples/data/iosshowcase.gif" width="450">
## `example_titlebar.py` is an example about customizing titlebar
<img src="https://github.com/kadir014/pyqt5-custom-widgets/blob/main/examples/data/titlebarshowcase.gif" width="410">
Binary file added examples/data/titlebarshowcase.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 added examples/data/toastshowcase.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
81 changes: 81 additions & 0 deletions examples/example_titlebar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# 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

from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QWidget, QApplication, QVBoxLayout
from PyQt5.QtGui import QColor, QFontDatabase, QBrush, QPalette, QLinearGradient

from pyqt5Custom import TitleBar



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

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

self.setGeometry(100, 100, 410, 240)

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

self.titlebar = TitleBar(self, title="Custom TitleBar!")
self.layout.addWidget(self.titlebar, alignment=Qt.AlignTop)
self.titlebar.setStyleDict({
"background-color" : (255, 255, 255),
"font-size" : 18,
"font-subpixel-aa" : True,
"font-family" : "SF Pro Display",
})

self.titlebar.closeButton.setStyleDict({
"border-radius" : 100,
"background-color" : (255, 255, 255, 120),
"font-size" : 18,
"font-family" : "SF Pro Display",
"render-fast" : True
})
self.titlebar.maxButton.copyStyleDict(self.titlebar.closeButton)
self.titlebar.minButton.copyStyleDict(self.titlebar.closeButton)


self.anim = self.titlebar.newAnimation()
self.anim.speed = 0.7

@self.anim.tick
def callback():
r = QColor(255, 100, 100)
g = QColor(100, 255, 100)
b = QColor(100, 100, 255)

if self.anim.current() < 0.25:
c = self.anim.lerp(r, g)
elif self.anim.current() < 0.75:
c = self.anim.lerp(g, b)
else:
c = self.anim.lerp(r, b)

self.titlebar.setStyleDict({
"background-color" : (c.red(), c.green(), c.blue()),
})

self.anim.start(loop = True)



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

mw = MainWindow()
mw.show()

sys.exit(app.exec_())
2 changes: 1 addition & 1 deletion pyqt5Custom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# https://github.com/kadir014/pyqt5-custom-widgets #


__version__ = "1.0.0"
__version__ = "1.0.1"


from .toggleswitch import ToggleSwitch
Expand Down
34 changes: 25 additions & 9 deletions pyqt5Custom/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,32 @@ def __init__(self, widget, startv, endv, type):
self.sensitivity = 0.001

self.reverse = False
self.start_time = None
self.interval = 20 / 1000
self.loop = False
self.started = None

self._tickfunc = None

def __repr__(self):
return f"<pyqt5Custom.AnimationHandler({self.startv}->{self.endv}, interval={self.interval:.4})>"
return f"<pyqt5Custom.AnimationHandler({self.startv}->{self.endv})>"

def tick(self, func):
self._tickfunc = func
return func

def start(self, reverse=False):
def start(self, reverse=False, loop=False):
self.reverse = reverse
self.start_time = True
self.loop = loop
self.started = True
self.orgstart_time = time.time()
self.value = 0
self.widget.update()

def reset(self):
self.value = 0
self.start_time = None
self.started = None

def done(self):
return self.start_time is None
return self.started is None

def update(self):
if not self.done():
Expand All @@ -59,9 +67,17 @@ def update(self):
self.value = self.type(ep * self.speed)

if self.reverse:
if self.current() <= self.startv + self.sensitivity: self.start_time = None
if self.current() <= self.startv + self.sensitivity: self.started = None
else:
if self.current() >= self.endv - self.sensitivity: self.start_time = None
if self.current() >= self.endv - self.sensitivity: self.started = None

if self.done():
if self.loop:
self.start(reverse=not self.reverse, loop=True)
return

#print(self.value)
if self._tickfunc: self._tickfunc()

def current(self):
if self.reverse:
Expand Down
Loading

0 comments on commit 638df4f

Please sign in to comment.