QScintilla in PySide - python

I like PySide, and have used it for a while now, but in the program I am working on at the moment, I need an advanced code editor.
I have found QScintilla, but that is for PyQt. Is that compatible with PySide and if so, how would I go about using it?
I have also looked at PySide-QScintilla, but all that is is a couple of .h files and an __init.py__ and the __init__.py doesn't even have anything relating to the .h files! Has anyone used that? How do you include it in a program?
I also saw qutepart but it seems to be mush too basic for what I need.
I would accept solutions other than QScintilla, but they have to have:
Error Highlighting
Syntax Highlighting
Code Suggestion (a drop down menu while typing)
Line Numbers
Custom Colors
Must be at least GPL (LGPL would be nice)
Any other features are great.

Doing a quick Google search brought up the following:
http://gitorious.org/pyside-qscintilla
https://github.com/LuaDist/scintilla/tree/master/qt/ScintillaEditPy
I suspect the first one is a direct port, whereas the second is some kind of Scintilla wrapper instead of a QScintilla port.

Related

Convert AsciiMath/MathML to SVG/PNG

I'm looking for a way to convert my AsciiMath (or MathML) sources to SVG and/or PNG. I've found a nodeJS library for SVG conversion but calling that from Python is not very convenient and the output is not entirely satisfying.
Taking the fact I'd like to render mathematical formulas to svg/png it seems logical to look for a solution in math libraries (NumPy, SciPy, Pandas, Matplotlib, Sympy, etc...) but to no avail. All my google results combining all possible permutations of asciimath+mathml+svg+png lead to nothing which is strange.
Please recommend me either search patterns to find a solution or share your experiences/ideas to get this seemingly simple job done in Python.
All help would be highly appreciated!
I just created ziamath for exactly this purpose. It comes bundled with the STIX math font, so no setup is required beyond the pip install, but it should also work with other math-enabled fonts. Pure-Python, so it does not need a Latex installation or anything else to work. This first version doesn't quite cover the full MathML specification, but the most useful parts are in there.
To bundle it into an app with something like PyInstaller, you'll need to make sure the STIX font gets included, but that should just be one line in the PyInstaller config.
I have used this for years without issues. It is written in python.
https://sourceforge.net/projects/svgmath/files/svgmath/0.3.3/

PyQT - How to implement Syntax Highlighting?

I want to write a little IDE for Cython using PyQT, but I don't have any idea how to implement Syntax Highlighting.
I know how to parse the Python-source, but I don't know how I can set the color for different words within the Textfield in PyQT.
I could use HTML for this, but how does it work in realtime ? I mean when the user edits the text I need to be able to immediately change the text's format, etc.
Do you know how I can achieve this ?
Have you considered using QScintilla?
"As well as features found in standard text editing components, QScintilla includes features especially useful when editing and debugging source code. These include support for syntax styling, error indicators, code completion and call tips."
I would recommend checking out the code in KhtEditor which is written in Python using PyQt. I believe the author is also working on a port from QWidget to QML.

Trying to write Python script to remove duplicate fonts Mac OSX

I am trying to write a utility to check through the fonts on OSX and remove duplicates - so far I've had success iterating through the folder structure and writing out an xml file containing fonts and paths. The drawback is that this doesn't find duplicates as the same font can be installed twice in different locations but with a different file name; font family information is internal to the font file.
I have found this: List of installed fonts OS X / C
import Cocoa
manager = Cocoa.NSFontManager.sharedFontManager()
font_families = list(manager.availableFontFamilies())
Which uses PyObjC to list installed fonts. This looks like a possible solution but I'm not a heavy weight coder and know nothing about PyObjC! I did have a play around in a terminal with dir(manager)and dir(NSFontManager)to see if I could find a method that returned the file paths of installed fonts but to no avail.
Any help gratefully received.
Best wishes
//Simon
Install the fonttools package and take a look at this blog post. There's a script there that gives the font name of its first argument and I'm sure you could adapt it to your use case.
Thanks once again for the replies - I just wanted to update this in the hope it helps. I'm looking at fontTools now, but admit I am having trouble finding documentation. According to the developer's page there are libraries to handle other fonts apart from ttf, but I'm still looking with little success just yet!
In the mean time, I did turn up this page on Using Apple Font tools, which seems get half way to what I need - ie listing installed fonts and locations. It looks like the ftxinstalledfonts command will accept a pipe so in theory I could pipe the output to my existing python script that builds an xml database. I'm assuming I can do this by calling ftxinstalledfonts via the sys module but am not clear as to how to get the output... I'll go and plunder the python docs but if there's no luck and someone has 10 secs to give a pointer I'd be grateful.
As a quick aside, the Font Geek site above has some very useful stuff about TTX as well.
Best wishes
//Simon

Python/C "defs" file - what is it?

In the nautilus-python bindings, there is a file "nautilus.defs". It contains stanzas like
(define-interface MenuProvider
(in-module "Nautilus")
(c-name "NautilusMenuProvider")
(gtype-id "NAUTILUS_TYPE_MENU_PROVIDER")
)
or
(define-method get_mime_type
(of-object "NautilusFileInfo")
(c-name "nautilus_file_info_get_mime_type")
(return-type "char*")
)
Now I can see what most of these do (eg. that last one means that I can call the method "get_mime_type" on a "FileInfo" object). But I'd like to know: what is this file, exactly (ie. what do I search the web for to find out more info)? Is it a common thing to find in Python/C bindings? What is the format, and where is it documented? What program actually processes it?
(So far, I've managed to glean that it gets transformed into a C source file, and it looks a bit like lisp to me.)
To answer your "What program actually processes it?" question:
From Makefile.in in the src directory, the command that translates the .defs file into C is PYGTK_CODEGEN. To find out what PYGTK_CODEGEN is, look in the top-level configure.in file, which contains these lines:
AC_MSG_CHECKING(for pygtk codegen)
PYGTK_CODEGEN="$PYTHON `$PKG_CONFIG --variable=codegendir pygtk-2.0`/codegen.py"
AC_SUBST(PYGTK_CODEGEN)
AC_MSG_RESULT($PYGTK_CODEGEN)
So the program that processes it is a Python script called codegen.py, that apparently has some link with PyGTK. Now a Google search for PyGTK codegen gives me this link as the first hit, which says:
"PyGTK-Codegen is a system for automatically generating wrappers for interfacing GTK code with Python."
and also gives some examples.
As for: "What is the format, and where is it documented?". As others have said, the code looks a lot like simple Scheme. I couldn't find any documentation at all on codegen on the PyGTK site; this looks like one of those many dark corners of open source that isn't well documented. Your best bet would probably be to download a recent tarball for PyGTK, look through the sources for the codegen.py file and see if the file itself contains sufficient documentation.
All you need to create Python bindings for C code is to use the Python / C API. However, the API can be somewhat repetitive and redundant, and so various forms of automation may be used to create them. For example, you may have heard of swig. The LISP-like (Scheme) code that you see is simply a configuration file for PyGTK-Codegen, which is a similar automation program for creating bindings to Python.

How can I get Geany to show me the methods a library has when I press the '.' key?

In visual studio, I could just press ctrl+spacekey and the methods appeared. In Geany is there a way for me to get this functionality?
No, because is Python is dynamically typed language and quite hard to achieve that. Python plugins for netbeans do that partially, but I believe such plugin is not in geany developers plans. There are different things to be done ;-)
However, geany provides some completions support. First, it analyzes your imports in a file and uses it in completions; furthermore it completes functions from the std library. It also analyzes all you open files for suggestions, although you may need to apply it in preferences. Also you can get call tips, when you hit Ctrl+Shift+Space, which not everyone know about. They are quite good, because they appear in form <Class>.<method>(<args>), which is very helpful.
shortcut ctrl+space works for me. also, you can setup autocomplete suggestion length (ie how many letters you must type before the autocomplete tooltip pops up automatically - http://www.geany.org/manual/current/#editor-completions-preferences ).
this works only for method names. if i want to see the options for method parameters, i must type bracket ( after the method full name.

Categories

Resources