Skip to content

PyQt6 Mediator Mixin is a Python library that enhances PyQt6's signal-slot mechanism by implementing the mediator pattern. It allows for more modular and maintainable code by enabling classes to emit and receive signals without knowing about each other. The library also provides the ability to extend the SignalCode enum for custom signals.

License

Notifications You must be signed in to change notification settings

Capsize-Games/PyQt6-mediator-mixin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyQt6 Mediator Mixin

Upload Python Package

image

PyQt6 Mediator Mixin is a Python library that enhances PyQt6's signal-slot mechanism by implementing the mediator pattern. This pattern allows classes to emit and receive signals without knowing about each other, leading to more modular and maintainable code.

Key features:

  • Mediator pattern implementation for PyQt6 signals.
  • Ability to extend the SignalCode enum for custom signals.

Installation

pip install PyQt6-mediator-mixin

Usage

from PyQt6_mediator_mixin.mediator_mixin import MediatorMixin
from PyQt6_mediator_mixin.enums import SignalCode

class MyClass(MediatorMixin):
    def __init__(self):
        super().__init__()
        self.register(SignalCode.MY_SIGNAL, self.my_slot_function)

    def my_slot_function(self, data):
        print("Received signal with data:", data)

    def some_method(self):
        self.emit(SignalCode.MY_SIGNAL, "some data")

Extending SignalCode Enum

from enum import Enum
from PyQt6_mediator_mixin.signal_code_factory import set_signal_code

class MySignalCode(Enum):
    MY_SIGNAL_1 = 1
    MY_SIGNAL_2 = 2

set_signal_code(MySignalCode)

Now, MyClass can register and emit MY_SIGNAL_1 and MY_SIGNAL_2 using the MediatorMixin.

About

PyQt6 Mediator Mixin is a Python library that enhances PyQt6's signal-slot mechanism by implementing the mediator pattern. It allows for more modular and maintainable code by enabling classes to emit and receive signals without knowing about each other. The library also provides the ability to extend the SignalCode enum for custom signals.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages