How can I make a Python shell-like GUI using Tkinter? - python

I need to make a program that uses as its interface a shell window, like the one the python IDLE uses, this window has to be made. What widgets can I use to perform this. I've heard that the Python IDLE was made using tkinter, if that`s the case, then what widget did they used.
Pd. I've tried using the 'text' widget, but it doesn't freezes commands that have already been processed. Is there a way to freeze the commands that have already been processed,but keep text entry activated.

You should take a look at PyQt. Specifically the QTextEdit. They also have the QScintilla library that does code highlighting and formatting.
If you're not opposed to using other peoples' code, Blur Studio has open sourced much of their code, and they have a widget that is pretty similar. Once you install the blurdev library, it's at blurdev.gui.windows.loggerwindow

Related

How to embed shell in my Python curses application?

I am creating a TUI application using Python and curses. And I want to embed/integrate the shell, like you have in VS Code, etc. How can I do this?
I don't just want to capture input and execute it using bash, I want the real shell. E.g. in VS Code you see the real shell prompt (as defined in bashrc) and also you can run a whole application (e.g. vim) from inside the VS code terminal.
I have looked at pty module: not sure if it can help here. I want to basically have a library function like invoke_shell() to which I just pass a reference to a curses window (inside of which I want to show the shell). I do not need to interact with the shell in any other way, except to: (1) close it, (2) capture a keystroke for my application to move focus away from the shell window to another curses window in my application (and move focus back to it when I need it). Is there any such library?
Any help is greatly appreciated! Thanks in advance.

Repeated calls to ArcMap Python Add-In with wxPython fail after one successful call

I have written a Python Add-In for ArcGIS program ArcMap that uses the wxPython package to generate a wx.Frame window with multiple controls, including an Exit button that closes the window.
The Add-in works as intended the first time I run it, and I can close the wx.Frame window using the button without any errors. However, after a variable number of times running the Add-in, I get a fatal error on running the Add-In again. (Sometimes it fails the second time I run it. Sometimes I can run it multiple times before it fails.) The error window asks to send the report to ESRI, but unfortunately, the only output that ArcMap generates in this case is a .DMP file, which I assume is simply a memory dump. I don't know how to interpret it.
The Python script that is wrapped in the Add-In works fine from the Python command line in ArcMap (with suitable modifications), but running it from a button on an ArcMap user toolbar is more convenient.
Is there any way to generate a trace of what exactly was happening when it encountered the fatal error? There is no error message sent to the Python command line window when it fails.
I was able to find an answer to this problem from a link in a posting on the ESRI GeoNet Community forum:
https://community.esri.com/thread/99532
(You need to logon to a free account on the forum to read the postings.) The original link was to a presentation by Mark Cederholm at the ESRI Developer summit 2010. The link in the forum post was obsolete, but I found another link to it:
https://www.esri.com/videos/watch?videoid=1229&isLegacy=true
that worked. The presentation shows how to build an ArcMap Extension which contains a toolbar and a button that loads when ArcMap starts. Instead of using wx.Close() or wx.Destroy to close the windows, it simply hides them using wx.Show(False). This approach allows using wxPython GUI interfaces on dialog boxes that can be opened, closed, and reopened repeatedly without crashing ArcMap.
I thought that this would be useful for other people using Python to build Add-Ins for ArcMap that make use of wxPython. Next, I will be converting another ArcMap Add-In that I currently use that was written in VB.NET in Visual Studio to Python using wxPython to build the GUI interface.

How can I run a Python 3 program if a folder is selected

Say I have a folder called "Family Photos" and I want to automatically run a python program if that folder is selected. How would I go about doing that? Would I just put the code in the folder and it runs automatically?
Edit: I'm on Windows 10
You can use tkinter in python.
Tkinter is Python's de-facto standard GUI (Graphical User Interface) package. It is a thin object-oriented layer on top of Tcl/Tk.Tkinter is not the only GuiProgramming toolkit for Python. It is however the most commonly used one
You can use other GuiProgramming toolkits as well. Follow this_link to know about other gui frameworks.
For how part in Tkinter .Follow this_link
Some unix/linux systems are open source so you could modify the OS behavior to do that, i don't believe windows offer this feature, you probably should create an APP for that
The best solution would be a python scripts that run it self each hour and check if this folder is modified and do something if its, and it will run each time you turn on the computer once

When the console is selected, how do I get the main window to come to the front?

I have no idea if this problem has the solution I want but here goes.
I'm making a PyQt4 program that apparently needs the console window to run properly. However, whenever I activate another window, sending the program I'm working on to the back, the only way I can get back to it is by closing all the windows in front of said window. I can't just click on the taskbar because the only thing that comes back is the console window.
I'm curious. Is there a way to have the GUI window activate along with, or independent of, the console window without having to go through the annoying process of closing (minimizing) potentially all the rest of your windows?
Edit: I just realized my question is pretty vague. Let me elaborate.
I'm compiling said program using pyinstaller.
The reason it needs the console window to work properly (I have tried using the .pyw file as well, to no avail) is because there's another program that's the core of this one that prints out to it in a way I can only describe as violently.
Apparently it won't be happy unless it has the console to record it's outbursts.
That being said, I need the console window. However, as I mentioned before, that is the only thing that comes up when the pyinstaller icon is clicked.
There is a gui attached to the console, but there's no way to get it back even after the user would minimize it because the pyinstaller icon insists it doesn't exist.
Maybe it has something to do with how I defined the window while programming it, but I don't see why that would be the case. Is there something in particular pyinstaller doesn't like that would make it act like this?
How are you launching the PyQt application?
If you're launching it with the python executable, it will create a console.
python my_application.py
Instead, launch it with the GUI version of python -- pythonw:
pythonw my_application.py
If the python path isn't in the system path, you may need to specify the whole path to the executable:
C:\python27\pythonw.exe C:\path\to\my_application.py

Integrating CMD Module with PYQT

I am developing a texteditor using PYQT, the text editor is used for processing a DSL, one that I am making up. Now I would really like to have the ability to click on on an ICON, say a console icon in my gui toolbar that will launch a console, from the console I could run my custom commands that allow me to do things like manipulate my SQLITE database directly.
I am somewhat familiar with the CMD Module which allows me to create simple commands that do the things that I want, but how can I integrate my gui texteditor and a CMD module console?
A similar idea can be found in
Integration of Python console into a GUI C++ application
only difference is that I don't want a full python interpreter,and i'm not using C++
Any suggestions
After much searching I found
http://obswww.unige.ch/~revaz/git/old.glups-4.0/glups/pycutext.py
This module implements a QT4 python interpreter widget.
It is inspired bu PyCute : http://gerard.vermeulen.free.fr
I cannot take credit for the solution, but it effectively redirects all python stdin,stdout and even stderr to the pyQt Widget. Its exactly what I was looking for.

Categories

Resources