GithubHelp home page GithubHelp logo

wiktorsusfal / python_observable_objects Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 4.24 MB

Publisher/Observer pattern for python objects to synchronize data in the background with the use of event-driven callbacks mechanism.

Python 100.00%
data-synchronization event-handling observer-pattern

python_observable_objects's Introduction

python_observable_objects

Publisher/Observer pattern for python objects to synchronize data in the background with the use of event-driven callbacks mechanism.

modules created:

Useful modules to implement background data synchronization between objects:

  • Utilities.py - contains definition of 'PropertyChangedEventHandler' class used to manage the event-driven callbacks mechanism
  • ObservableObjects.py - contains definitions of 'ObservableObject' and 'ObserverObject' classes used to create objects that can easily subscribe to given source attribute's changes (for receiving value updates automatically) and publish notifications about their attributes' changing values. 'Utilities.py' is a dependency for 'ObservableObjects.py'.

modules containing examples of usage:

Simple presentation of solution:

  • testing.py - simple data synchronization setup between 2 instances of classes that inherit from 'ObservableObject' and 'ObserverObject' class

Framework for creating PyQt5 GUI python applications in a model similar to C# MVVM (Model, View, ViewModel):

  • DataModels.py - contains definition of object(s) that receive raw data unprepared for visualization
  • ViewModels.py - contains definition of object(s) that store (lists of) 'DataModels' object(s) and perform necessary data transformations to prepare it to visualization. These transformations are often done by 'getter'/'setter' custom functions assigned to python properties - exposed attributes that act like an interface for interacting with internal variables - e.g. from data models stored.
  • Views.py - contains definition of PyQt5 GUI objects. Data to be displayed with the use of these objects comes from view models object(s).

In this case, Views.py contains also a few lines of execution code to present some solution - in-background synchronization between plain attributes (e.g. strings) and PyQt5 objects (e.g. QLabels). When the value of the string attribute of view model object changes, a property changed event is triggered and the new value is automatically set to the QLabel.

Also there is a solution for one consistent way of providing values FROM input GUI objects (like QLineEdits) TO plain variables - using PyQt5 signal slots.

The two above are done using Utilities.py and ObservableObjects.py modules.

Two QLineEdit objects (input fields) update in real time two properties. Third property (which consists of the two mentioned before) is synchronized with QLabel.

My Image

python_observable_objects's People

Contributors

wiktorsusfal avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.