Skip to main content

A Python GUI-based Python debugger enabling realtime watching and modification of variables and expressions, plus a REPL-light

Project description

Downloads

imwatchingyou

A "debugger" that's based on PySimpleGUI. It was developed to help debug PySimpleGUI based programs, but it can be used to debug any program. The only requirement is that a refresh() function be called on a "periodic basis".

What you can do with this "debugger" is:

  • Set "watch points" that update in realtime
  • Write expressions / code that update in realtime
  • Use a REPL style prompt to type in "code" / modify variables

All of this is done using a window secondary and separate from your primary application window.

Check out this video as a guide. The user's window is the smaller one one top. The PySimpleGUIdebugger is the green window on the buttom. You can watch variables, evaluate expressions, even execute code.

PSG Debugger2

Installation

Installation is via pip:

pip install imwatchingyou

or if you need to upgrade later:

pip install --upgrade --no-cache-dir imwatchingyou

Note that you need to install the debugger using pip rather than downloading. There are some detailed technical reasons for this.

So, don't forget: You must pip install imwatchingyou in order to use it.

Integrating imwatchingyou Into Your Application

There are 3 lines of code to add to a program in order to make it debugger ready - The import, an initialization, a refresh function called periodically.

Copy and paste these lines of code into your code just as you see them written. Don't get clever and rename anything. Don't do an "import as". Just copy the lines of code.

Here is an entire program including this integration code:

import PySimpleGUI as sg
import imwatchingyou
"""
    Demo program that shows you how to integrate the PySimpleGUI Debugger
    into your program.
    There are THREE steps, and they are copy and pastes.
    1. At the top of your app to debug add
            import imwatchingyou
    2. Initialize the debugger by calling:
            imwatchingyou.initialize()
    2. At the top of your app's event loop add
            imwatchingyou.refresh(locals(), globals())
"""

imwatchingyou.initialize()

layout = [
            [sg.T('A typical PSG application')],
            [sg.In(key='_IN_')],
            [sg.T('        ', key='_OUT_')],
            [sg.Radio('a',1, key='_R1_'), sg.Radio('b',1, key='_R2_'), sg.Radio('c',1, key='_R3_')],
            [sg.Combo(['c1', 'c2', 'c3'], size=(6,3), key='_COMBO_')],
            [sg.Output(size=(50,6))],
            [sg.Ok(), sg.Exit()],
        ]


window = sg.Window('This is your Application Window', layout)
window.Element('_OUT_').Update(background_color='red')
# Variables that we'll use to demonstrate the debugger's features
counter = 0
timeout = 100

while True:             # Event Loop
    imwatchingyou.refresh(locals(), globals())            # call the debugger to refresh the items being shown
    event, values = window.Read(timeout=timeout)
    if event in (None, 'Exit'):
        break
    elif event == 'Ok':
        print('You clicked Ok.... this is where print output goes')
    counter += 1
    window.Element('_OUT_').Update(values['_IN_'])

Using imwatchingyou

To use the debugger in your code you will need to add TWO lines of code: The import at the top of your code: import imwatchingyou

You need to "initialize" the imwatchingyou package by calling near the top of your code. This is what creates the debugger window: imwatchingyou.initialize()

This "refresh" call that must be added to your event loop. Your window.Read call should have a timeout value so that it does not block. If you do not have a timeout value, the debugger will not update in realtime.

Add this line to the top of your event loop. imwatchingyou.refresh(locals(), globals())

Using in "when needed" mode

The Demo Program was recently updated so that instead of launching with the Debugger window immediately shown, the program launches with the Debugger not started. With this new code, you can open and close the Debugger as many times as you wish.

Here is the code, based on the code shown previously in this readme, that has a "Debug" button

import PySimpleGUI as sg
import imwatchingyou            # STEP 1

"""
    Demo program that shows you how to integrate the PySimpleGUI Debugger
    into your program.
    In this example, the debugger is not started initiallly. You click the "Debug" button to launch it
    There are THREE steps, and they are copy and pastes.
    1. At the top of your app to debug add
            import imwatchingyou
    2. Initialize the debugger at the start of your program by calling:
            imwatchingyou.initialize()
    3. At the top of your app's Event Loop add:
            imwatchingyou.refresh(locals(), globals())
"""

layout = [
            [sg.T('A typical PSG application')],
            [sg.In(key='_IN_')],
            [sg.T('        ', key='_OUT_')],
            [sg.Radio('a',1, key='_R1_'), sg.Radio('b',1, key='_R2_'), sg.Radio('c',1, key='_R3_')],
            [sg.Combo(['c1', 'c2', 'c3'], size=(6,3), key='_COMBO_')],
            [sg.Output(size=(50,6))],
            [sg.Ok(), sg.Exit(), sg.B('Debug')],
        ]

window = sg.Window('This is your Application Window', layout)

counter = 0
timeout = 100
debug_started = False

while True:             # Your Event Loop
    if debug_started:
        debug_started = imwatchingyou.refresh(locals(), globals())   # STEP 3 - refresh debugger
    event, values = window.Read(timeout=timeout)
    if event in (None, 'Exit'):
        break
    elif event == 'Ok':
        print('You clicked Ok.... this is where print output goes')
    elif event == 'Debug' and not debug_started:
        imwatchingyou.initialize()  # STEP 2
        debug_started = True
    counter += 1
    window.Element('_OUT_').Update(values['_IN_'])
window.Close()

The Future

LOTS of plans for this debugger in the future. One of the immediate things I want to do is to integrate this into the PySimpleGUI.py file itself. To include the debugger with the SDK so that it doesn't have to be installed.

This will enable the use of a "hotkey" or other mechanism to "magically launch" the debugger.

I'll be adding a "Launch debugger" button for sure so that it's trivial for you to add this capability to your code.

Watch this space in the future! COOL SHIT COMING SOON!

Release Notes

imwatchingyou 1.1 26-May-2019

  • Addition of "Code" line so that things like "import os" can be run from the repl

imwatchingyou 1.2.1 27-May-2019

  • Can press ENTER for both REPL fields and it'll execute them! NICE
  • Code cleanup
  • STILL under 200 lines of code! WITH a GUI.

imwatchingyou 1.3.0 27-May-2019

  • New "Auto Watcher" feature
    • New viewing area for these variables
    • Chosen using a page of checkboxes
  • Other cool shit that I can't recall. Was up coding all night
  • Up to 250 lines of code in total, but I've been extremely inefficient. Can be compacted quite a bit. I went for readability for now.
    • Still the only 250 lines of Python code, real-time, GUI, watcher with REPL that you'll find anywhere

imwatchingyou 1.4.1 27-May-2019

  • Forgot release notes

imwatchingyou 1.5.0 28-May-2019

  • Lots of nice code cleanup
  • Rework of auto-watching
    • Clear capability in 2 places
    • Can cancel out of choosing to make changes
    • Confirmation when choosing to clear auto-watches in main interface
    • Choose autowatches now has a "real event loop"... it also means it BLOCKS waiting on your choices
  • Shows non-blocking, "Message" when clearing checkboxes

imwatchingyou 1.6.0 28-May-2019

  • No more globals! Cheating and using a class instead. Same diff
  • Working of all interfaces is the best way to sum it up
  • there are 45 differences that I don't feel like listing
  • lots of shit changed

imwatchingyou 1.7.0 28-May-2019

  • User interface change - expect lots of those ahead. This was a good enough one to make a new release
  • Nice selection interface for auto display
    • Next is to create a tiny version of this output that is a floating, tiny window

Design

Author

Mike B.

License

GNU Lesser General Public License (LGPL 3) +

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

imwatchingyou-1.7.0.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

imwatchingyou-1.7.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file imwatchingyou-1.7.0.tar.gz.

File metadata

  • Download URL: imwatchingyou-1.7.0.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.19.2 CPython/3.6.2

File hashes

Hashes for imwatchingyou-1.7.0.tar.gz
Algorithm Hash digest
SHA256 5904098a8bf79970ae5456bdbc488f5c04858fe550c85cbf0af863f5059c51d6
MD5 79428f0642b9c6ad5347de038ad22ccb
BLAKE2b-256 fe816fa6042f906cb700d8061d480c1a7064f16a046dfb9bc511d1dbb1e6af3b

See more details on using hashes here.

File details

Details for the file imwatchingyou-1.7.0-py3-none-any.whl.

File metadata

  • Download URL: imwatchingyou-1.7.0-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.19.2 CPython/3.6.2

File hashes

Hashes for imwatchingyou-1.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ba9bb0ebe34806ad2c24624b3d4799c298f08430b6bbcb1f5d23d4e6e67d9ed0
MD5 2db2f780e0cc317ead45fbdc3ab9156a
BLAKE2b-256 5a634df9673ad389257507309a1a503246b0075f74ff2d0b31817491097e6fe8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page