I had a python code and I used Pyinstaller to make it a stand-alone .exe executable.
In my code, I use "print" function to output result.
However, if the result is really long, (several screen page long) the result is cut short because the limitation of the console, I can scroll up but I guess the total length of the viewable text region is limited. (I am running my .exe in Windows)
Is there a way to extend the visible range so I can see all my output?
Thanks!
================
update:
I agree with #supremefist that it is the shell that is limit the visible range.
Is there a way to pass parameters to the shell so that when I double click it in Windows, the view range is extended.
Also, if it is possible, I would like to have my executable robust across different OSs. I am trying to write a small program and my target users maybe inexperienced computer users.
================
update2:
Now, I understand that Pyinstaller is only for Windows, previous update for different Oss is completely wrong.
The good news is that I switch to Qt and this problem goes away as I am now displaying my result in a window rather than a shell console.
I don't think the limit is related to PyInstaller, but to the constraints being set on your windows shell. You could try changing your shell settings by doing the following:
Open a windows shell by either running 'cmd' or by finding it under Accessories in your Start Menu.
Right click on the title of the shell window and select Properties.
Increase the screen buffer height setting under the 'Layout' tab to a large number. Something like 9999.
Re-run your program, you should see a much longer history of text.
Related
I want to programmatically create one and only one Terminal.app window that's uniquely identified by a literal Terminal.app window title (let's call it 'MyConsole1') and send bash commands to said window for the life of the Terminal.app process.
Can this be done with Terminal.app, and if so, how?
Details
My program probably needs to check if 'MyConsole1' is already open before I go try to create a new one. And of course, start Terminal.app if it's not already running. I also want the commands issued to and over the life of 'MyConsole1' (by my program) to be bash-command-history retrievable by a human user; ie, the user can interact with 'MyConsole1' if desired. I'm not concerned about user-vs-program "conflicts" that might arise for use of the 'MyConsole1'.
I presume I need AppleScript to do this. I will be running the AppleScript as part of a much-larger Python application, possibly via a method like this, in case that matters.
I see how Terminal.app window/tab title(s) can be set like this, but this solution doesn't work for my requirements above. Further, I only want 1 tab in the window, and the title to apply to the entire window, and not just the tab.
I'm not sure if this is what you mean, but you can try this:
tell app "Terminal"
activate
do script ""
end tell
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
I want to collect data and parse it eventually from an open window in linux.
An example- Suppose a terminal window is open. I need to retrieve all the data that appears on that window. After retrieval, I would parse it to get specific commands entered.
So is it possible to do that? If so, how? I would prefer to use python to code this entire thing.
I am making a guess that first I would have to get some sort of ID for the open window and then use some kind of library to get the content from the window whose ID I have got.
Please help. I am quite a newbie.
You can (ab)use the assistive technologies support (for screen readers and such) that exist in the toolkit libraries. Whether it will work is toolkit specific—Gtk and Qt have this support, but others (like Tk, Fltk, etc.) may or may not.
The Linux Desktop Testing Project is a python toolkit for abusing these interfaces for testing GUI applications, so you can either use it or look how it works and do similar thing.
I think the correct answer may be "with some difficulty". Essentially, the contents of a window is a bitmap. This bitmap is drawn on by a whole slew of primitives (including "display this octet-string, using that encoding and a specific font"), but the window contents is still "just pixels".
Getting the "just pixels" is pretty straight-forward, as these things go. You open a session to the X server and say "given me the contents of window W" and it hands it over.
Doing something useful with it is, unfortunately, a completely different matter, as you'd potentially have to (essentially) OCR the bitmap for what you want.
If you decide to take that route, have a look at the source of xwd, as that does, essentially, that.
Do you have some sort of control over the execution of the terminal? In that case, you can use the script command in the terminal session to log all interaction to a file and then read and parse the file.
$ script myfile
Script started, file is myfile
$ ls
...
$ exit
Script done, file is myfile
$ parse_file.py myfile
If the terminal is running inside of screen, you have other options as well. Screen has logging built in, screen -X sends commands to a running screen session (man screen).
Following the example at http://article.gmane.org/gmane.comp.python.general/541418, I've succeeded in creating a callable class for balloon tooltips, but the greater complexities of that code elude me when it comes to customization. I browsed a bit of how it works through msdn, but being a novice at more windows-esque languagues like c and vb, etc. I was unable to make much sense of it.
So I ask ye snakely academics:
Things I'd like to be able to do with that code aside from the standard icon, title, text:
Perform actions based on clicking the tooltip
Modify the tooltip that pops up over the icon in the system tray after loading it (to reflect changing values)
Multiple lines? (Not sure if this can even be done, really)
More information on other things you could do in a windows 7 environment versus XP (which seems to be what this was written for).
Ideally I'd get some sort of return value or some semblance of an event when the tooltip is clicked so that I could run some code, but currently I'm importing that code as a module and calling at various times, so I'm not sure how to handle clicks outside of the popup code itself...
Information on handling these things with python seems quite scarce. Thanks in advance.
Perform actions based on clicking the tooltip
Whats the problem OnTaskbarNotify? Hock yourself in there.
Modify the tooltip that pops up over the icon in the system tray after loading it (to reflect changing values)
Probably not, I am not sure about the WinAPI here. I haven't seen it in the wild, so...
Multiple lines? (Not sure if this can even be done, really)
With most WinAPI, just insert a \n in the string.
More information on other things you could do in a windows 7 environment versus XP (which seems to be what this was written for).
LOTS... But that is a bit vague... It depends what your needs are. But for kol feturez you need to google on your own...
On Linux and Unix systems I use the notify-send OS already implemented system.
import os
os.system('notify-send "'+title+'" "'+message+'")
Maybe in Windows there is some API32 for this.
Check this https://gist.github.com/wontoncc/1808234
I'm just starting out learning python with GEdit plus various plugins as my IDE.
Visual Studio/F# has a feature which permits the highlighting on a piece of text in the code window which then, on a keypress, gets executed in the F# console.
Is there a similar facility/plugin which would enable this sort of behaviour for GEdit/Python? I do have various execution type plugins (Run In Python,Better Python Console) but they don't give me this particular behaviour - or at least I'm not sure how to configure them to give me this. I find it useful because in learning python, I have some test code I want to execute particular individual lines or small segments of code (rather then a complete file) to try and understand what they are doing (and the copy/paste can get a bit tiresome)
... or perhaps there is a better way to do code exploration?
Many thx
Simon
Yes, you use "external tools plugin"
http://live.gnome.org/Gedit/ToolLauncherPlugin
As an example,
Edit > Preferences
Plugins
Tick "External Tools"
Close the Preferences Window
Tools > Manage External Tools
Click the "Add new too" icon in the bottom left
Name it "Execute Highlighted Python Code"
give it a keyboard shortcut
change the input combo box to : "highlighted selection"
change the output to : "Display in Bottom Pane"
In the editor window for the tool, replace everything with :
.
#!/usr/bin/env python
import sys
result = eval(sys.stdin.read())
print expression, "=>", result, type(result)
.
If you wish to see the result of entire .py file, you can put this code in your new created external tool window
#!/usr/bin/env python
import sys
exec(sys.stdin.read())
and change the Input to Current document.
For python, You can use "external tools plugin":
#!/bin/sh
python3 "$GEDIT_CURRENT_DOCUMENT_PATH"
Option of external tool:
Save: Current Document
Input: Current Document
Output: Display in bottom panel
Language: Python or Python3
Don't forget the quotes around $GEDIT_CURRENT_DOCUMENT_PATH....
To answer your second question, and hopefully guide you in a direction you'll be happier with, I think you ought to consider trying some different editors. There are many with more powerful code exploration features than GEdit has. Check out this post:
What IDE to use for Python?
I installed iPython console in gedit and do most of my simple scripting in it, but gedit is a very simple editor, so it'll not have some advance feature like an IDE
But if you want code exploring, or auto completion, I recommend a real IDE like Eclipse.
If you just want a editor, KomodoEdit is fine.
What I do is keep a file called python_temp.py. I have a shortcut to it in my dock. I use it as a scratch pad. Whenever I want to quickly run some code, I copy the code, click the shortcut in the doc, paste in the text and hit f5 to run. Quick, easy, simple, flexible.
I think what you're looking for is http://live.gnome.org/Gedit/Plugins/BetterPythonConsole.
You hit F5 and it runs the code in your file in a IDLE-like console. I don't know if it can only run selected code. (I don't think it can) but you can always copy the needed code in a new window and run it from there.
Have a look through the plugin list for other interesting stuff: http://live.gnome.org/Gedit/Plugins
The closest to a decent IDE...
Install gedit-developer-plugins (through synaptic || apt-get) and don't forget to enable (what you need) from gEdit's plugins (Edit->Preferences [tab] plugins) and happy coding