Skip to content

Commit

Permalink
release 0.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
omamkaz committed Jan 8, 2024
1 parent 1256463 commit 5c44a68
Show file tree
Hide file tree
Showing 195 changed files with 3,340 additions and 30 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@
### Added
- `animations.ParallelAnimationGroup`
- `animations.SequentialAnimationGroup`
- `tools.Brush`

### Changed

Expand Down
Binary file added Qtica/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions Qtica/animations/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .property_animation import PropertyAnimation
from .parallel_animation_group import ParallelAnimationGroup
from .sequential_animation_group import SequentialAnimationGroup
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
25 changes: 25 additions & 0 deletions Qtica/animations/parallel_animation_group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/python3

from PySide6.QtCore import QParallelAnimationGroup, QAbstractAnimation
from PySide6.QtWidgets import QWidget
from ..core import QObjectDec


class ParallelAnimationGroup(QObjectDec, QParallelAnimationGroup):
def __init__(self,
*,
target: QWidget,
children: list[QAbstractAnimation] = None,
running: bool = False,
**kwargs) -> QWidget:
QParallelAnimationGroup.__init__(self)
super().__init__(**kwargs)

for child in children:
child.setTargetObject(target)
self.addAnimation(child)

if running:
self.start()

return target
23 changes: 23 additions & 0 deletions Qtica/animations/property_animation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/python3

from PySide6.QtCore import QPropertyAnimation
from PySide6.QtWidgets import QWidget
from ..core import QObjectDec


class PropertyAnimation(QObjectDec, QPropertyAnimation):
def __init__(self,
*,
target: QWidget,
running: bool = False,
**kwargs) -> QWidget:
QPropertyAnimation.__init__(self)

self.setTargetObject(target)

super().__init__(**kwargs)

if running:
self.start()

return target
25 changes: 25 additions & 0 deletions Qtica/animations/sequential_animation_group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/python3

from PySide6.QtCore import QSequentialAnimationGroup, QAbstractAnimation
from PySide6.QtWidgets import QWidget
from ..core import QObjectDec


class SequentialAnimationGroup(QObjectDec, QSequentialAnimationGroup):
def __init__(self,
*,
target: QWidget,
children: list[QAbstractAnimation] = None,
running: bool = False,
**kwargs) -> QWidget:
QSequentialAnimationGroup.__init__(self)
super().__init__(**kwargs)

for child in children:
child.setTargetObject(target)
self.addAnimation(child)

if running:
self.start()

return target
Binary file added Qtica/core/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file added Qtica/core/__pycache__/_base.cpython-312.pyc
Binary file not shown.
Binary file added Qtica/core/__pycache__/_config.cpython-312.pyc
Binary file not shown.
Binary file not shown.
Binary file added Qtica/core/__pycache__/_dialog.cpython-312.pyc
Binary file not shown.
Binary file added Qtica/core/__pycache__/_icons.cpython-312.pyc
Binary file not shown.
Binary file added Qtica/core/__pycache__/_painter.cpython-312.pyc
Binary file not shown.
Binary file added Qtica/core/__pycache__/_qobject.cpython-312.pyc
Binary file not shown.
Binary file added Qtica/core/__pycache__/_tool.cpython-312.pyc
Binary file not shown.
Binary file added Qtica/core/__pycache__/_widget.cpython-312.pyc
Binary file not shown.
Binary file added Qtica/core/__pycache__/api.cpython-312.pyc
Binary file not shown.
152 changes: 152 additions & 0 deletions Qtica/core/_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
#!/usr/bin/python3

from typing import Any, Sequence, Union
from PySide6.QtWidgets import QApplication
from PySide6.QtCore import Qt, QObject
from ..utils._classes import Func, Args
from ..enums.events import Events, EventTypeVar
from ..enums.widgets import Widgets, WidgetTypeVar
from ..enums.signals import Signals, SignalTypeVar
from ..utils.caseconverter import camelcase, snakecase


class AbstractBase:
def __init__(self,
uid: str = None,
signals: SignalTypeVar = None,
events: EventTypeVar = None,
methods: Sequence[Union[tuple[str, Any], Func]] = None,
enable_event_stack: bool = True,
**kwargs):

self._enable_event_stack = enable_event_stack

self._set_uid(uid)
self._set_events(events)
self._set_signals(signals)
self._set_methods(methods)
self._set_property_from_kwargs(**kwargs)

def _getattr(self, name: str, default: object = None) -> object:
return getattr(self, name, default)

def _set_uid(self, uid: str):
if uid is not None:
self.setObjectName(uid.strip())

def _set_methods(self, methods):
if not methods:
return

for method in methods:
if isinstance(method, Func):
if (func := getattr(self, method.func())) is not None and callable(func):
func(*method.args(), **method.kwargs())
elif (func := getattr(self, method[0])) is not None and callable(func):
func(method[1])

def _set_events(self, events: EventTypeVar):
if not events:
return

for event, slot in events:
ename = (camelcase(event.name)
if isinstance(event, Events)
else event.strip())

_comp = ename + "Event"
if hasattr(self, _comp):
ename = _comp

self.__setattr__(ename, slot)

def _set_signals(self,
signals: SignalTypeVar,
disconnect: bool = False):

if not signals:
return

for signal, slot in signals:
sname = (camelcase(signal.name)
if isinstance(signal, Signals)
else signal.strip())

if (attr := self._getattr(sname)) is not None:
if disconnect:
attr.disconnect(slot)
else:
attr.connect(slot)

def _get_wtype(self, qtype: Union[WidgetTypeVar, QObject] = Widgets.any):
return (qtype.value
if isinstance(qtype, Widgets)
else qtype)

def fetch(self,
uid: str,
qtype: Union[WidgetTypeVar, QObject] = Widgets.any) -> QObject:

return self.findChild(self._get_wtype(qtype),
uid.strip(),
Qt.FindChildOption.FindChildrenRecursively)

def _set_property_from_kwargs(self, **kwargs):
for name, value in kwargs.items():
if hasattr(self, name) or self.property(name) is not None:
snake_case = snakecase(name)

# handle signals
if snake_case in Signals._member_names_:
self._getattr(name).connect(value)

# handle events
elif snake_case in Events._member_names_:
self.__setattr__(name, value)

# handle parent parametar
elif name == "parent":
if isinstance(value, str):
for parent in QApplication.topLevelWidgets():
if parent.objectName().strip() == value.strip():
self.setParent(parent)

elif (widget := parent.findChild(QObject,
value.strip(),
Qt.FindChildOption.FindChildrenRecursively)) is not None:
self.setParent(widget)

elif callable(value):
self.setParent(value())

else:
self.setParent(value)

# handle properties
elif self.property(name) is not None:
self.setProperty(name, value)

# handle set callables methods
elif name.lower().startswith("set"):
if (func := self._getattr(name)) is not None and callable(func):
if isinstance(value, Args):
func(*value.args(), **value.kwargs())
else:
func(value)

def setEventStackEnable(self, state: bool):
self._enable_event_stack = state

def __setattr__(self, __name: str, __value: Any) -> None:
if hasattr(self, "_enable_event_stack") and self._enable_event_stack:
# Events Stack
if __name.endswith("Event"):
__func = self.__getattribute__(__name)
def __event(e):
__func(e) # load prev events
__value(e) # load new event
return getattr(self.__class__, __name)

return super().__setattr__(__name, __event)

return super().__setattr__(__name, __value)
32 changes: 32 additions & 0 deletions Qtica/core/_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/python3

from abc import ABCMeta, abstractmethod
from typing import Any, Callable
from PySide6.QtCore import Signal


class AbstractConfig(metaclass=ABCMeta):
@abstractmethod
def name(self) -> str:
raise NotImplementedError

@abstractmethod
def get(self) -> Callable:
raise NotImplementedError

@abstractmethod
def set(self) -> Callable:
raise NotImplementedError

@abstractmethod
def signal(self) -> Signal:
raise NotImplementedError

def group(self) -> str:
...

def default(self) -> Any:
...

def type(self) -> object | None:
...
77 changes: 77 additions & 0 deletions Qtica/core/_declarative.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/python3

from typing import Any


class DuplicateKeyError(Exception):
def __init__(self, uid: str):
super().__init__(uid)
print(f"'{uid}' was registered in this dictionary!")


class _TrackingDec:
def __init__(self):
self._instances_dict = dict()

def _register(self, uid: str, obj: Any) -> None:
if not isinstance(uid, str):
raise ValueError("invalid uid, must be str type.")

if uid in self._instances_dict:
raise DuplicateKeyError(uid)
self._instances_dict[uid] = obj

def _deregister(self, uid: str) -> Any:
""" deregister widget from manager """
if not isinstance(uid, str):
raise ValueError("invalid uid, must be str type.")

if uid not in self._instances_dict:
return

return self._instances_dict.pop(uid)

def pop(self, uid: str) -> Any:
self._deregister(uid)

def get(self, uid: str) -> Any:
return self._instances_dict.get(uid)

def items(self) -> Any:
return self._instances_dict.items()

TrackingDec = _TrackingDec()


class AbstractDec:
"""
`__init__` method can now return a value
### usage example
```python
class Object(AbstractDec):
def __init__(self, *args, **kwargs) -> object:
return ...
```
#### NOTE: use `uid` parameter to store this class in `TrackingDec`, \
and call it with Api.fetch
"""

def __new__(cls, *args, **kwargs) -> Any:
instance = super().__new__(cls)

if not hasattr(cls, "objectName"):
_uid = (kwargs.pop
if 'uid' not in
instance.__init__.__code__.co_varnames
else kwargs.get)("uid", None)

if _uid is not None:
TrackingDec._register(_uid, instance)

return instance.__init__(*args, **kwargs)


class BehaviorDec(AbstractDec):
pass
Loading

0 comments on commit 5c44a68

Please sign in to comment.