Skip to content

Commit 638df4f

Browse files
author
Kadir Aksoy
committed
1.0.1
1 parent d6408a9 commit 638df4f

File tree

10 files changed

+225
-67
lines changed

10 files changed

+225
-67
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ dist/
44
olddist/
55
pyqt5Custom.egg-info/
66
setup.py
7+
MANIFEST.in

README.md

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<p>
33
<img src="https://img.shields.io/badge/python-3.6%2B-green">
44
<img src="https://img.shields.io/badge/license-GPL%203.0-blue.svg">
5-
<img src="https://img.shields.io/badge/version-1.0.0-orange">
5+
<img src="https://img.shields.io/badge/version-1.0.1-orange">
66
</p>
77
More useful and stylish widgets for PyQt5 such as toggle switches, animated buttons, etc..
88
<br>
@@ -12,9 +12,9 @@ More useful and stylish widgets for PyQt5 such as toggle switches, animated butt
1212
- [Installing](#Installing)
1313
- [Usage](#Usage)
1414
- [Widgets](#Widgets)
15-
- [Examples](#Examples)
16-
- [Documentation](#Documentation)
17-
- [Styling Reference](#Styling)
15+
- [Examples](#References)
16+
- [Documentation](#References)
17+
- [Styling Reference](#References)
1818
- [Dependencies](#Dependencies)
1919
- [TODO](#Todo)
2020
- [License](#License)
@@ -31,15 +31,25 @@ python -m pip install pyqt5Custom
3131
Also you can also use PySide2 instead of PyQt5 with just litte changes.
3232

3333
## Usage
34-
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:
34+
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:
3535
```py
36-
from pyqt5Custom import ToggleSwitch
36+
from pyqt5Custom import StyledButton
3737

3838
...
3939

40-
togglesw = ToggleSwitch("Turn on/off the lights", style="ios")
41-
togglesw.setStyleSheet("font-size:15px; color: #444444;")
42-
layout.addWidget(togglesw)
40+
btn = StyledButton(text="Hello!")
41+
btn.setStyleDict({
42+
"border-radius" : 20,
43+
"font-family" : "Helvetica",
44+
"font-size" : 17
45+
})
46+
47+
@btn.clicked.connect
48+
def slot():
49+
print("Quitting!")
50+
app.exit()
51+
52+
layout.addWidget(btn)
4353

4454
...
4555
```
@@ -49,17 +59,13 @@ layout.addWidget(togglesw)
4959
| :---: | :---: |
5060
| ![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) |
5161
| ![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) |
52-
| ![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) |
62+
| ![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) |
5363
| ![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) |
5464

55-
## Examples
56-
See [examples](https://github.com/kadir014/pyqt5-custom-widgets/blob/main/examples/) page
57-
58-
## Documentation
59-
See [documentation](documentation.md) page
60-
61-
# Styling
62-
See [styling reference](stylingref.md) page
65+
## References
66+
- See [Examples](https://github.com/kadir014/pyqt5-custom-widgets/blob/main/examples/) page for examples
67+
- See [Documentation](documentation.md) page for documentation and detailed widget references
68+
- See [styling reference](stylingref.md) page for styling instructions on custom widget
6369

6470
## Dependencies
6571
- [PyQt5](https://pypi.org/project/PyQt5/)

documentation.md

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,21 +114,51 @@ Other stuff that the the library provides but are not mainly widgets. Some are t
114114
## TitleBar
115115
`TitleBar` lets the developer use a custom window title bar, this widget also provides window resizing controls (WIP) \
116116
\
117-
![TitleBar](https://github.com/kadir014/pyqt5-custom-widgets/blob/main/examples/data/titlebarshowcase.png)
117+
![TitleBar](https://github.com/kadir014/pyqt5-custom-widgets/blob/main/examples/data/titlebarshowcase.gif)
118118

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

123123
#### Attributes
124-
- `close_btn` (StyledButton) : Close button
125-
- `max_btn` (StyledButton) : Maximize button
126-
- `min_btn` (StyledButton) : Minimize button
124+
- `closeButton` (StyledButton) : Close button
125+
- `maxButton` (StyledButton) : Maximize button
126+
- `minButton` (StyledButton) : Minimize button
127127

128128
#### Methods
129129
- `setTitle(title)` : Change title
130130
- `title()` (str) : Get title
131131

132+
## Spinner
133+
`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\
134+
\
135+
![Spinner](https://github.com/kadir014/pyqt5-custom-widgets/blob/main/examples/data/spinnershowcase.gif)
136+
137+
#### Parameters
138+
- `width` (float) : Width of the circle
139+
- `color` (QColor) : Color of the circle
140+
141+
## Toast
142+
`Toast` is notification widget that appears at the bottom of the window.\
143+
\
144+
![Toast](https://github.com/kadir014/pyqt5-custom-widgets/blob/main/examples/data/toastshowcase.gif)
145+
146+
#### Parameters
147+
- `parent` (QWidget) : Parent widget
148+
- `text` (str) : Text of the widget (Optional)
149+
- `icon` (str/Spinner) : Icon of the widget (Optional)
150+
- `closeButton` (bool) : Whether to show the close button or not
151+
152+
#### Methods
153+
- `rise(duration: int)` : Shows the toast notification for duration seconds
154+
- `fall()` : Hides the toast notification
155+
156+
<br>
157+
<br>
158+
<br>
159+
<br>
160+
<br>
161+
132162

133163
# Other stuff
134164
Other stuff that the the library provides but are not mainly widgets. Some are tools, data classes, etc...

examples/README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ You can view or run example scripts to have a better understanding of the `pyqt5
33
Assets in the `data` folder is _**only for examples**_ and is not required to use the module alone. \
44
\
55
Quick look at example scripts:
6-
- `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">
7-
- `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">
8-
- `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">
6+
## `example_showcase.py` is an example where most widgets and styling variatons are shown
7+
<img src="https://github.com/kadir014/pyqt5-custom-widgets/blob/main/examples/data/showcase.gif" width="450">
8+
## `example_requesthandler.py` is an example about using RequestHandler class
9+
<img src="https://github.com/kadir014/pyqt5-custom-widgets/blob/main/examples/data/rqshowcase.gif" width="250">
10+
## `example_ios.py` is a replica of iOS design
11+
<img src="https://github.com/kadir014/pyqt5-custom-widgets/blob/main/examples/data/iosshowcase.gif" width="450">
12+
## `example_titlebar.py` is an example about customizing titlebar
13+
<img src="https://github.com/kadir014/pyqt5-custom-widgets/blob/main/examples/data/titlebarshowcase.gif" width="410">

examples/data/titlebarshowcase.gif

218 KB
Loading

examples/data/toastshowcase.gif

67.8 KB
Loading

examples/example_titlebar.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# PyQt5 Custom Widgets #
2+
# GPL 3.0 - Kadir Aksoy #
3+
# https://github.com/kadir014/pyqt5-custom-widgets #
4+
# #
5+
# This script is one of the pyqt5Custom examples #
6+
7+
8+
import sys
9+
10+
from PyQt5.QtCore import Qt
11+
from PyQt5.QtWidgets import QWidget, QApplication, QVBoxLayout
12+
from PyQt5.QtGui import QColor, QFontDatabase, QBrush, QPalette, QLinearGradient
13+
14+
from pyqt5Custom import TitleBar
15+
16+
17+
18+
class MainWindow(QWidget):
19+
def __init__(self):
20+
super().__init__()
21+
22+
QFontDatabase.addApplicationFont("data/SFPro.ttf")
23+
24+
self.setGeometry(100, 100, 410, 240)
25+
26+
self.layout = QVBoxLayout()
27+
self.layout.setAlignment(Qt.AlignTop)
28+
self.setLayout(self.layout)
29+
self.layout.setContentsMargins(0, 0, 0, 0)
30+
31+
self.titlebar = TitleBar(self, title="Custom TitleBar!")
32+
self.layout.addWidget(self.titlebar, alignment=Qt.AlignTop)
33+
self.titlebar.setStyleDict({
34+
"background-color" : (255, 255, 255),
35+
"font-size" : 18,
36+
"font-subpixel-aa" : True,
37+
"font-family" : "SF Pro Display",
38+
})
39+
40+
self.titlebar.closeButton.setStyleDict({
41+
"border-radius" : 100,
42+
"background-color" : (255, 255, 255, 120),
43+
"font-size" : 18,
44+
"font-family" : "SF Pro Display",
45+
"render-fast" : True
46+
})
47+
self.titlebar.maxButton.copyStyleDict(self.titlebar.closeButton)
48+
self.titlebar.minButton.copyStyleDict(self.titlebar.closeButton)
49+
50+
51+
self.anim = self.titlebar.newAnimation()
52+
self.anim.speed = 0.7
53+
54+
@self.anim.tick
55+
def callback():
56+
r = QColor(255, 100, 100)
57+
g = QColor(100, 255, 100)
58+
b = QColor(100, 100, 255)
59+
60+
if self.anim.current() < 0.25:
61+
c = self.anim.lerp(r, g)
62+
elif self.anim.current() < 0.75:
63+
c = self.anim.lerp(g, b)
64+
else:
65+
c = self.anim.lerp(r, b)
66+
67+
self.titlebar.setStyleDict({
68+
"background-color" : (c.red(), c.green(), c.blue()),
69+
})
70+
71+
self.anim.start(loop = True)
72+
73+
74+
75+
if __name__ == "__main__":
76+
app = QApplication(sys.argv)
77+
78+
mw = MainWindow()
79+
mw.show()
80+
81+
sys.exit(app.exec_())

pyqt5Custom/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# https://github.com/kadir014/pyqt5-custom-widgets #
44

55

6-
__version__ = "1.0.0"
6+
__version__ = "1.0.1"
77

88

99
from .toggleswitch import ToggleSwitch

pyqt5Custom/animation.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,32 @@ def __init__(self, widget, startv, endv, type):
3333
self.sensitivity = 0.001
3434

3535
self.reverse = False
36-
self.start_time = None
37-
self.interval = 20 / 1000
36+
self.loop = False
37+
self.started = None
38+
39+
self._tickfunc = None
3840

3941
def __repr__(self):
40-
return f"<pyqt5Custom.AnimationHandler({self.startv}->{self.endv}, interval={self.interval:.4})>"
42+
return f"<pyqt5Custom.AnimationHandler({self.startv}->{self.endv})>"
43+
44+
def tick(self, func):
45+
self._tickfunc = func
46+
return func
4147

42-
def start(self, reverse=False):
48+
def start(self, reverse=False, loop=False):
4349
self.reverse = reverse
44-
self.start_time = True
50+
self.loop = loop
51+
self.started = True
4552
self.orgstart_time = time.time()
4653
self.value = 0
54+
self.widget.update()
4755

4856
def reset(self):
4957
self.value = 0
50-
self.start_time = None
58+
self.started = None
5159

5260
def done(self):
53-
return self.start_time is None
61+
return self.started is None
5462

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

6169
if self.reverse:
62-
if self.current() <= self.startv + self.sensitivity: self.start_time = None
70+
if self.current() <= self.startv + self.sensitivity: self.started = None
6371
else:
64-
if self.current() >= self.endv - self.sensitivity: self.start_time = None
72+
if self.current() >= self.endv - self.sensitivity: self.started = None
73+
74+
if self.done():
75+
if self.loop:
76+
self.start(reverse=not self.reverse, loop=True)
77+
return
78+
79+
#print(self.value)
80+
if self._tickfunc: self._tickfunc()
6581

6682
def current(self):
6783
if self.reverse:

0 commit comments

Comments
 (0)