Giter Club home page Giter Club logo

Comments (3)

israel-dryer avatar israel-dryer commented on July 17, 2024

The only problem with a process is that you can't easily share memory. So it's harder to use global variables and other things to communicate between different components of the program. But, I have found that the threads work find for loading and other types of screens as long as more than one screen is not required (in an event loop) at the same time. And believe it or not... there are some very creative ways of getting around that.

from animated-popup.

israel-dryer avatar israel-dryer commented on July 17, 2024

btw, I really like the notification program. I'm definitely going to steal that at some point.

from animated-popup.

PySimpleGUI avatar PySimpleGUI commented on July 17, 2024

I thought I would revisit this Issue now that I released ptoaster.

Here's a little test program I just wrote that starts up as many animated popups as you want and also allows you to stop each of them individually. I dunno, maybe it'll resonate with you some, or, maybe not. No biggie either way. I'm having fun seeing how to use multiprocessing with PySimpleGUI. So far it's been pretty fun and interesting.

from multiprocessing import Process, Queue
from queue import Empty
from random import randint
import PySimpleGUI as sg

screen_dim = sg.Window.get_screen_size()    # to make it easier to start windows is random locations

def main():

    layout = [[sg.Button('Start'), sg.Button('Stop'), sg.Button('Exit')]]

    window = sg.Window('Multiprocess Tester', layout, keep_on_top=True)

    queues = []
    while True:  # Event Loop
        event, values = window.read()
        if event in (None, 'Exit'):
            break
        if event == 'Start':
            gui_queue = Queue()             # create a queue to communicate with process
            queues.append(gui_queue)        # add the queue to list of active queues
            show_animated_popup(gui_queue)  # start the process
        if event == 'Stop':
            if queues:
                queues[0].put('Stop')
                del queues[0]
    window.close()


def show_animated_popup(gui_queue):
    proc = Process(target=_animated_popup_process, args=(gui_queue,), daemon=True)
    proc.start()
    return proc


def _animated_popup_process(gui_queue):
    while True:
        sg.popup_animated(sg.DEFAULT_BASE64_LOADING_GIF, 'Loading', text_color='black', transparent_color='blue', background_color='blue', time_between_frames=100, location=(screen_dim[0]//2+randint(100,400),screen_dim[1]//2+randint(100,400)))
        try:
            message = gui_queue.get_nowait()    # see if something has been posted to Queue
        except Empty:
            message = None                      # nothing in queue so do nothing
        if message:                             # if something arrived, break from loop and exit process
            break
    sg.popup_animated(None)                     # stop the animated popup before exiting the process


if __name__ == '__main__':
    main()

from animated-popup.

Related Issues (1)

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.