FlexGUI + Python + Notepad++

rjo__rjo__ Posts: 2,076
edited 2019-11-30 - 23:47:04 in Propeller 2
A python program, "py2flexgui.py," sits between Notepad++ and FlexGui.

Windows only.

I am not going to go over Notepad++ features... they are fantastic. If you haven't thought about Notepad++ for a while, take a look. Color coding, Code Folding, multiple windows open side by side etc. etc.

I previously created a program, "py2pnut," to do the same using PNut. I have made some improvements and you can find both programs attached. I have a dual P2 set-up. The plan is to use PNut to program one board and FlexGui for the other. With Notepad++, I can have both programs open side by side and edit them interactively and then run them using two hotkey's

In order to use it you have to:

1. Go into the code and at the beginning will you see three directory paths to Notepad++, flexgui.exe, and the program you are going to work on. Most importantly, you have to pick which P2 file you want to work on and put that directory path.

2. Next open up Command Prompt... then go back to File Explorer and drag the python executable over onto the Command Prompt. Hit the space bar. Now go to where you put py2FlexGui.py and drag that over and drop it on Command Prompt.

Copy the line... but only the text after the ">".

3. Open Notepad++ and you will find a menu called "RUN". Select the first menu item "Run..." A dialog will open.
Type ctrl-v. Then push the "Run" button. What should happen is that your program should load into NotePad++. FlexGui should open and run your program and then exit.

4. Create the hotkey. With the Run dialog still open. Hit the save button. Now, you do three things... enter a name for your command. I just use py2FlexGUI. Choose a key combination as you "hotkeys" I use "Shift" and "F5" since they aren't used by default. Close it all up and you should be good to go.
Getting the hotkey registered is the fiddliest part and I frequently get it wrong.

PYTHON

1. I'm using 2.7. I suspect this doesn't work in other versions. No problem. Just install 2.7 and set the path to THAT python.exe.
2. Modules: you have to import them so that means you have to download them unless you already have:

import pyautogui
import time
import subprocess
import os
from os import system
import pywinauto
from pywinauto.findwindows import find_window
from pywinauto.win32functions import SetForegroundWindow

IF YOU DON"T KNOW HOW TO IMPORT MODULES:
Download JetBrains PyCharm Community Edition... you will have to google it:)
This is a complete Python working environment and at the time I was looking it seemed like the most complete and easy to use.
Play with PyCharm until you are comfortable.

Remember... if you change any of the working directories used in the program...you have to delete your hotkey and redo it.

With both py2flexgui.py and py2pnut.py any changes saved in either FlexGui or PNut are automatically updated by NotePad++

OOOh one last thing

In FlexGUI there is a "Commands" menu. The last item is "Configure Commands" You have to have the option set to p2b.

Attached is a simple script just to make sure everything is working... it lights up pin #56

MicroPython

Your hotkey should be created for py2upy.py as above. py2upy.py is attached below. The sample program is "blinker.py" also attached.
This works a little differently. Whatever file you have open as active in Notepad++ will be run. All editing is done in Notepad++.
To work, start FlexGUI, from the "Specials" menu select "Run Micropython on P2" Now go into NotePad++ program your hotkey and open the file "blinker.py"
py2upy.py will close the FlexGui editor but leave the Propeller Output window for MicroPython to use. Hit your hotkey and you should see a couple of blinks on pin #56

After MicroPython gets started, you will be returned to Notepad++. Rinse and repeat.

Comments

  • Hi,
    wanted to try that. Didn't work, so I opened the py2flexgui.py in IDLE to run it and see the error messages

    Had to install pyautogui, pywinauto.
    Then there was some error about win32... (don't remember, maybe 'ImportError: no module named win32api').
    I had to install pypiwin32. After a restart of IDLE the win32... Error was gone.
    Now I get: ...line 8, in <module>from pywinauto.win32functions import SetForegroundWindow
    ImportError: cannot import name 'SetForegroundWindow' from 'pywinauto.win32functions' (E:\Programme\Python\Python37\lib\site-packages\pywinauto\win32functions.py).

    I use Python 3.7.4.


    οἶδα οὐκ εἰδώς
  • Yes... never as easy as it sounds. Python 2.7 and you have to download everything imported if you haven't already.

    You need:

    import pyautogui
    import time
    import subprocess
    import os
    from os import system
    import pywinauto
    from pywinauto.findwindows import find_window
    from pywinauto.win32functions import SetForegroundWindow

    it is worth the effort. I have only used it to run PASM and Spin 1.5 code. Doesn't work for Micropython yet. Haven't tried Basic .
  • Look at: https://github.com/pywinauto/pywinauto/issues/785

    You have to install pywinauto==0.6.6
    οἶδα οὐκ εἰδώς
  • ALSO in FlexGUI there is a "Commands" menu. The last item is "Configure Commands" You have to have the option set to p2b.

    Attached is a simple script just to make sure everything is working... it lights up pin #56
  • I have corrected my first post to reflect the conversation. I will try to keep it updated to minimize the effort required to get going.

    Thanks guys
  • py2upy.py now included in first post.

    Thank you ersmith
Sign In or Register to comment.