Python Create fixed banner within console / with console - python

I am working on a text-based RPG game, and I need a way of displaying the important figures such as remaining life and level so that it is always available to be checked.
Is there a way of creating a stationary banner within the console to display such figures? If not, do I have to create a GUI with the banner and embed the console?
Any alternative solutions that also work would be appreciated, given that it shows the figures at all times.
Thank you.

I believe you're looking for a TUI layer. You might checkout the curses library,urwid, or even possibly picotui.

Related

Python compile a script within a GUI

I am currently working on the final year project for my degree. I have chosen to research and develop a tool to aid the delivery of the new Computing curriculum that is coming to schools next year.
I am using a Raspberry Pi in my development, and I aim to teach extremely basic Python programming to children between the ages of 8 and 10. They are going to be able to control some hardware attached to the Pi using a simple API that I am going to create.
My question is: I would like to be able to create a GUI for the children to work in, which would allow them to write and compile scripts. This is mainly to get away from the unfamiliar interface of Linux and terminals etc, and put them in a friendly, basic interface which will pretty much just allow them to write their code and click a big red button to compile and run it to interact with the hardware. Is it possible to allow for text to be written in a GUI and then compiled when the button is pressed?
I am pretty new to Python myself so I am not as clued up as I'd like to be about the specifics of it. I know that it is possible to have the output of IDLE inside of a tkinter interface, and that it is possible to have text boxes for user input and stuff, but would it actually be possible to compile a script on button press and then run it? I have been thinking that maybe threading is the answer. Perhaps I could create a new thread to do it when the button is pressed?
My apologies if this is incredibly basic, but I am having no luck finding any answers about how I would do this. I think it's mainly because I am unsure on what exactly to ask for.
I appreciate any feedback/help, thank you very much.
Dell
Have your GUi write the Python code to a file, then dynamically import using the imp module. I actually do something similar :-)
import imp
hest = imp.load_source("Name", Path)

How to advance to a "new page" using pygtk?

I'm new to programming in python, but I've went through tutorials which taught me how to create click-able images and connecting them to trigger a callback function.
I am trying to write a script which will allow me to click an image, and move onto a new window or "page" of different click-able images.
Is there a way for me to do this using pygtk? I thought about creating classes and using an if else statement to poll through classes I wanted to use, but it hasn't worked for me. Or am I suppose to continuously hide and show buttons and images?
Is there a way to modify the sample code I've been using to accomplish my goal?
http://pygtk.org/pygtk2tutorial/examples/images.py
Any help would be appreciated, thanks!
You can use a GtkNotebook and hide its tabs. Whenever you need to change page, just switch the current page of the GtkNotebook.

Formatting Python string output

I'm writing a calculator currently and I'd like to have results displayed in a visually appealing form. The program just has a command line interface for the moment, but I've been trying to find a way to do various things with the results it displays. For example, I'd like to have it display the result in a bigger font size, a different font than system default, and even subscripts and superscripts. From what I could find, the best way to do such things would be if I introduced a GUI and used something like wxPython, and using Unicode code points can only resolve part of the issue. Moreover, for various reasons, I'd just like to have the program in command line for the moment.
I don't think you can accomplish this with the command line, but you might check out curses. I would suggest picking up a GUI for this sort of thing. It's really not too hard to learn and Python's builtin Tkinter is perfectly functional for getting started. There are many good resources for Tkinter. Here are a few I like:
effbot.org
Thinking in Tkinter
An Introduction to Tkinter
WxPython is excellent, but if you are just getting started my suggestion would be to start with Tkinter. Others might disagree...
EDIT
I just remembered running across the console module for Windows. I suspect it won't won't get you what you want, but at least it's out there.
If you're running this on the command line, I'm almost certain that there's nothing you can do to override the font preferences set by the user. In both windows and Linux, the font settings of the command line are user controlled, and I doubt that you can change it without sudo access. Seeing as you're writing a calculator, I don't think a user would want to run it as sudo - I certainly wouldn't want to run something as simple as a calculator with sudo privileges. To require that would make the user think that you are up to something malicious

making a python gui for ffdshow

I was thinking that for a learning project for myself, I would try to make a GUI for ffdshow on linux, using tkinter. Wanted to make sure this project would be feasible first, before I get halfway through and run into something that cant be done in python.
Basic idea is to have a single GUI window with a bunch of drop down boxes that have the various presets (like format or bitrate), as well as a text box where a custom number can be entered if applicable. Then when all the options are selected, the user hits the Start button on the GUI and it shows a progress little bar with a percentage. All the options selected would just send the relevant selections as cli arguments for ffdshow, and begin the conversion progress (essentially turning all the user's input into a single perfect cli command).
Is all this doable with python and tkinter? and is it something that a relative newb with only very basic tkinter experience could pull off with books and other python resources?
Thanks
That is precisely the type of thing that python and Tkinter excel at. And yes, a relative newbie can easily do a task like that.

How to make PowerBuilder UI testing application?

I'm not familiar with PowerBuilder but I have a task to create Automatic UI Test Application for PB. We've decided to do it in Python with pywinauto and iaccesible libraries. The problem is that some UI elements like newly added lists record can not be accesed from it (even inspect32 can't get it).
Any ideas how to reach this elements and make them testable?
I'm experimenting with code for a tool for automating PowerBuilder-based GUIs as well. From what I can see, your best bet would be to use the PowerBuilder Native Interface (PBNI), and call PowerScript code from within your NVO.
If you like, feel free to send me an email (see my profile for my email address), I'd be interested in exchanging ideas about how to do this.
I didn't use PowerBuilder for a while but I guess that the problem that you are trying to solve is similar to the one I am trying to address for people making projects with SCADA systems like Wonderware Intouch.
The problem with such an application is that there is no API to get or set the value of a control. So a pywinauto approach can't work.
I've made a small tool to simulate the user events and to get the results from a screencapture. I am usig PIL and pytesser ORM for the analysis of the screen captures. It is not the easiest way but it works OK.
The tool is open-source and free of charge and can be downloaded from my website (Sorry in french). You just need an account but it's free as well. Just ask.
If you can read french, here is one article about testing Intouch-based applications
Sorry for the self promotion, but I was facing a similar problem with no solution so I've written my own. Anyway, that's free and open-source...
I've seen in AutomatedQa support that they a recipe recommending using msaa and setting some properties on the controls. I do not know if it works.
If you are testing DataWindows (the class is pbdwxxx, e.g. pbdw110) you will have to use a combination of clicking at specific coordinates and sending Tab keys to get to the control you want. Of course you can also send up and down arrow keys to move among rows. The easiest thing to do is to start with a normal control like an SLE and tab into the DataWindow. The problem is that the DataWindow is essentially just an image. There is no control for a given field until you move the focus there by clicking or tabbing. I've also found that the DataWindow's iAccessible interface is a bit strange. If you ask the DataWindow for the object with focus, you don't get the right answer. If you enumerate through all of the children you can find the one that has focus. If you can modify the source I also advise that you set AccessibleName for your DataWindow controls, otherwise you probably won't be able to identify the controls except by position (by DataWindow controls I mean the ones inside the DataWindow, not the DataWindow itself). If it's an MDI application, you may also find it useful to locate the MicroHelp window (class fnhelpxxx, e.g. fnhelp110, find from the main application window) to help determine your current context.
Edited to add:
Sikuli looks very promising for testing PowerBuilder. It works by recognizing objects on the screen from a saved fragment of screenshot. That is, you take a screenshot of the part of the screen you want it to find.

Categories