Examples for Python and GtkUnixPrintDialog - python

I am trying to set up a print job in Python under Linux.
Now there is this GtkUnixPrintDialog that basically does what I need it to do, the problem is that I can't find any documentation on how to deal with it. I tried looking at the GTK3 reference docs, but that's all for C, and trying to translate those commands to Python didn't work.
I can easily get the dialog to open by adding it to my .glade file - but I can't find a way in Glade to connect the appropriate signals to it. Nor can I find a way to display it like other dialogs.
Anyone with a working example, to do a print job using the dialog?
Based on my previous question Creating print job in gtk3/python I have the code to set up the page as it has to be.
I am using reportlab libraries to create a pdf file, and that pdf file has to be printed out, preferably with a little control on which printer to use. Of course I could bypass that dialog entirely and dump it on the default printer, but the lack of documentation on that dialog irritates me as well.

It looks like GtkPrintUnixDialog is not included in introspection sources for GTK+. I am not sure if this is an oversight or done on purpose. However, this dialog is used internally by the higher level printing interface anyway which can be invoked with Gtk.PrintOperation.run by passing Gtk.PrintOperationAction.PRINT_DIALOG. There is a complete example in the pygobject sources.

Related

load an already written GTK python codes into a GUI designer

I want to change the interface of a written application. this application is written in python and GTK . I don't want to change the codes manually by myself but although I need an interface designer so I can import this application to it and the graphically apply my intended changes to it . I tried Glade and QTdesigner but they produce .ui file and I couldn't find a tool to convert back a .ui file to python code. plus that the don't open python files directly and didn't have import options.
any solution will be appreciated.
thanks
It really depends on the application.
If the application uses *.glade or *.ui files you can - depending on how well it is designed re-arrange certain elements and swap out container types.
If there are no such files, you are out of luck. Then the ui is "hard"-coded (as hard as python code can get..) and you have to modify the widget hirarchy by modifying python code yourself.
There is no such editor being able to extract a layout/ui file from code itself.
gtkinspector or formerly known as gtkparasite can modify properties of widgets on the fly but nothing that really modifies the python code of the running application. They sneak around the application code and modify the widget tree from back behind through means of the gtk module lib interface (correct me if I am wrong here, not totally sure).
You can't. Glade had code generation features removed years ago, because that leads to unmaintainable code when it's patched by hand after generation, to add the program's internal logic. So either you:
use Glade to generate a ui file, and have to change the python code anyway to use it
or you'll have manually write some code to change the user interface
In either way, you'll have some code to write. If you have lots of changes in the user interface, then convert your program to use Glade ui files. It will take some time, but changes will be easier afterwards. If you only have a couple of changes to do, just do them in the code, it will be faster to do.

QTextEdit Paginating

I'm trying to write simple PyQT report editor and what I need is to exactly know what sizes the page has, MS-Word like.
Today I found the following link:
How to access QTextDocument pages
that shows how to use an QPrinterPreviewDialog, and it seems to be the answer to my question, but I don't know how to transform it to Python. I have no idea how to implement QPrinterPreviewDialog into a QTextEdit. I tried to read the docs but without a example it's very hard to start.

Outputting text to multiple terminals in Python

(I am using Python and ArchLinux)
I am writing a simple AI in Python as a school project. Because it is a school project, and I would like to visibly demonstrate what it is doing, my intention is to have a different terminal window displaying printed output from each subprocess- one terminal showing how sentences are being parsed, one showing what pyDatalog is doing, one for the actual input-output chat, etc, possibly on two monitors.
From what I know, which is not much, a couple of feasible ways to go about this are threading each subprocess and figuring out display from there, or writing/using a library which allows me to make and configure my own windows.
My question is, then, are those the best ways, or is there an easy way to output to multiple terminals simultaneously. Also, if making my own windows (and I'm sorry if my terminology is wrong when I say 'making my own windows'. I mean building my own output areas in Python) is the best option, I'm looking for which library I should use for that.
So you could go in multiple directions with this. You could create a Tkinter (or GUI library of your choice) output text box and write to that. This option would give you the most control over how to display your data.
Another option is to access multiple terminals via named pipes. This involves spawning an xterm with a pipe and pumping output to it to be written on screen. See this question for and example:
Using Python's Subprocess to Display Output in New Xterm Window
I like #ebarr's answer, but a quick and dirty way to do it is to write to several files. You can then open multiple terminals and tail the files.

Using Tkinter in python can we highLight given string or text in LibreOffice , Gedit or in FireFox?

I am trying to highlight particular line or text in LibreOffice, So for that can I use Tkinter in python for highlighting particular Line in LibreOffice , or in Gedit . For Highlighting text of LibreOffice what can I do? Please guide me.
Programmatically manipulating another program's canvas is only possible if that program exposes an API for that. You would be targeting each specific API, not Tkinter.
As far as I know, none of the programs you discuss have Python bindings for anything like this. All of them have a plugin architecture, though, so it's not impossible, but you would have to be very lucky to find something beginner-friendly.
Update: LibreOffice does, in fact, have Python support: https://wiki.openoffice.org/wiki/Python_as_a_macro_language -- see also http://api.libreoffice.org/examples/examples.html#python_examples which has a Python example quite distinct from yours. There is a regex highlighting example for LibreOffice Basic which should be useful for showing you the names of the SDK functions you need.
Tkinter is primarily a GUI (graphical user interface) tool, so while you could use it to create the GUI for a program that would highlight text, it probably isn't really what you're looking for.
It probably would help if you were a little more specific with what exactly you needed to do. Such as: are you trying to highlight a specific line every time it appears in a file (usually the find function in a complex word processor can do this see here, page 70), are you trying to search closed files and highlight a specific line in a closed file (probably more along the lines of something Python would be useful for), or what have you. As it is your question is a little vague.

NPAPI for Python - Chrome Extension

I am trying to develop a chrome extension in which i have coded all my
logic in 'python' . Now on browser action i want to pass parameters
and execute that .py file and return results to popup which will open
on browser action. To call a .py file from JavaScript i know i will
need to code a NPAPI plugin. But am confused between which approach i
should take. I have come across few options and am trying to choose
the easiest way to do it ..
Pyjamas Python Javascript Compiler : is a Python-to-Javascript
compiler which works as a language translator but on FAQ's of there
site last question suggest it will not run on Chrome. ( http://pyjs.org/)
FireBreath : FireBreath is a framework that allows easy creation of
powerful browser plugins. ( http://www.firebreath.org )
pyplugin - Python NPAPI plugin for XULRunner : It allows you to
build cross-platform graphical user interfaces using XUL and Python.
( http://pyplugin.com )
Plz Guide me to easiest way which will allow me to pass parameters and
execute that .py file and receive returned results from .py.
Thanx
Well, Pyjamas Python Javascript Compiler will not be complete -- not all python features are available in javascript, so it's impossible to convert all python to javascript. This may or may not do what you want, but I don't think it happens "on the fly", I think you have to write things on the desktop and run it through the "compiler" to get javascript out the other side.
FireBreath is the most awesomely amazing thing to ever hit the Internet -- I should know since I wrote it -- and it will absolutely allow you to do what you want, but you'll have to know how to tie into Python with C++ in order to do what you want. That said, you could probably use boost.python, which is included in the subset of boost that comes with FireBreath, but I've never used it so I don't know. You can pretty much do anything you want with an NPAPI plugin but you'll want to be real careful of security concerns.
A quick glance at pyplugin makes it look like pyplugin is basically what you'd be writing in FireBreath, but just a raw npapi plugin. If this will do what you want, it's probably the easiest way to go. It's designed to be used with XUL, which may be a problem since Chrome doesn't support XUL. You might also be able to modify it (since it's GPL) to do what you want. Of course, if you weren't planning to release your source, that could also be a problem.
The quickest way to solve your problem? Well, you'll have to decide; it'll take some more research, but I hope this is enough to at least get you started. Good luck!

Categories