There are some applications that display XML structure in multiple views. An excellent example is Visual Studio Xaml ("Design") editor, which display an Object Tree, a rendered, "designer" window with mouse-manipulatable objects, a text editor with XAML content, and a properties window.
I am trying to do such a thing in PyQt to edit geographical maps, using KML as file format, but I would like to allow for direct editing and preservation formatting.
For example, I would like to be able to edit the formatting manually like this:
<Element attribute1="value1"
attribute2="value2"
attribute3="value3"/>
And be sure that attribute order and alignment would be kept intact upon further manipulation via TreeView or PropertiesWindow.
The fact is, a lot of answers say that, since attribute order is not a XML specification (that is, applications using XML should not count on it), the order is not guaranteed by any official library, and any library implementing it "is not doing XML". Specifically, not any Python library has support for this.
On the other hand, XAML editors in Visual Studio do that all the time.
So the question is: if I really, really want this, using Python GUI toolkits as a "support medium" (PyQt and its widgets, in principle), how hard would be the task? Should I expect to use python's XML libs, or would I have to write my own - that is, an overwhelmingly complex task - ?
Related
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.
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.
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.
I'm working on a Python project where there are some blocks of XML defined inside docstrings.
The code contains strings like this
xml_str = """<a>
<b>text</b>
</a>"""
In reality, the blocks of embedded XML are much larger. The problem is this XML becomes difficult to read. Since an IDE renders the XML as a String in one color, the text cannot be visually parsed as easily as if it had normal XML syntax highlighting applied.
I'm looking for an editor which will either natively support syntax highlighting in Strings, or where such a feature can be hacked in easily. This feature would be really cool to have, so I'm prepared to invest some time to make it happen.
I realize there are some arguments for why embedding XML in such a manner would be bad practice. I would agree, except in this situation. I have found a way to solve a problem very effectively by placing XML in a Python file directly instead of into an external resource.
Edit
I normally use PyDev for Eclipse, so I would be biased to solutions using it. Although I am prepared to swtich IDEs for this project if necessary.
Use syntax highlighting plugin http://colorer.sf.net/eclipsecolorer/ for eclipse. It Automatic folding support for mostly all (200+) supported languages.
I'm looking for a python browser widget (along the lines of pyQT4's QTextBrowser class or wxpython's HTML module) that has events for interaction with the DOM. For example, if I highlight an h1 node, the widget class should have a method that notifies me something was highlighted and what dom properties that node had (<h1>, contents of the tag, sibling and parent tags, etc). Ideally the widget module/class would give access to the DOM tree object itself so I can traverse it, modify it, and re-render the new tree.
Does something like this exist? I've tried looking but I'm unfortunately not able to find it. Thanks in advance!
It may not be ideal for your purposes, but you might want to take a look at the Python bindings to KHTML that are part of PyKDE. One place to start looking is the KHTMLPart class:
http://api.kde.org/pykde-4.2-api/khtml/KHTMLPart.html
Since the API for this class is based on the signals and slots paradigm used in Qt, you will need to connect various signals to slots in your own code to find out when parts of a document have been changed. There's also a DOM API, so it should also be possible to access DOM nodes for selected parts of the document.
More information can be found here:
http://api.kde.org/pykde-4.2-api/khtml/index.html
I would also love such a thing. I suspect one with Python bindings does not exist, but would be really happy to be wrong about this.
One option I recently looked at (but never tried) is the Webkit browser. Now this has some bindings for Python, and built against different toolkits (I use GTK). However there are available API for the entire Javascript machine for C++, but no Python bindings and I don't see any reason why these can't be bound for Python. It's a fairly huge task, I know, but it would be a universally useful project, so maybe worth the investment.
If you don't mind being limited to Windows, you can use the IE browser control. From wxPython, it's in wx.lib.iewin.IEHtmlWindow (there's a demo in the wxPython demo). This gives you full access to the DOM and ability to sink events, e.g.
ie.document.body.innerHTML = u"<p>Hello, world</p>"