I am creating some python files with extensions .pyt. Every thing is working fine except syntax highlighting.
My new .pyt files are not syntax highlighted as normal .py files do.
Ofcourse, I can change in
view>Highlight Mode> Script > python
manually for every file, but there are around 1200 files and they keep growing. I really dont want to do this manually for each file for the the first opening.
Is there any way to apply default python syntax highlighting to my new .pyt files.
Any Help will be highly appriciated.
P.S. I have read how to do this for gedit 2.0 in many pages like page1, page2 and many more pages but couldn't find any good working processes for gedit 1.0.
Although you (the OP) wrote that you found pages that were meant for gedit 3, I'm going to suggest that you look at this question.
Basically, even if gedit 1.0 used an older version of gtksourceview, as long as you can find the python.lang file in your system and change it, you can probably make it work. After all, it must have some way of specifying on which files it's used.
For new (Gtksourceview 2.0) lang files, this is done by adding either the mimetypes or globs property within the language's tag. So when you find the python.lang file, look for the *.py extension, and see if you can add *.pyt there, as is detailed in the question I linked above.
Related
I have a Python 3 function named foo. When I right click on this function in my VSCode editor and select Go to Reference it takes over a minute for the reference window to pop up. The Rename Symbol option does not work at all. If I search for foo in the search sidebar opened by Ctrl + Shift + F and search for foo I get a result instantly (without setting any file filters beforehand. The same applies when searching for references of other functions/variables. The problem is specific to only one of my repositories, although it does not contain significant more lines than the others. Does anybody have a guess how to fix this?
VSCode version: July 2021 (version 1.59)
Simple text based search is expected to be quick. However, all other operations require the language server behind the scene to parse all your source files and understand the entire code model.
If you can reliably reproduce the problem, open an issue on GitHub,
https://github.com/microsoft/pylance-release/issues
I've got a kind of weird question--but would be immensely useful if it is possible--in Maya using Python, can I take in several points of user input and have Python create a separate script for me? In this instance, I want to take in controller and locator names and have Python spit out a complete IKFK match script also in Python (it's really just a lot of getAttr and setAttr commands, although with 6 if statements per limb for PV matching.) The only other wrinkle there is that it has to be able to prefix hierarchy names in the script if necessary if the rig is imported into a new scene rather than just opened. There's an expression component to my switches that it would be nice if Python could make for me, too.
Is this possible or am I crazy?
That's no problem. Just write a textfile with a .py extension into a path where maya can find it. Then you have to import it somewhere. Creating expressions is not a problem either.
Maybe it could make sense to think about the approach you choose. Imagine you have written a dozen of these new python files and you discover a problem in the script, you will have to redo it. I'd try to collect all data and only write the required informations into a textfile e.g. in json format. Then you can read the data and rebuild your skeletons.
I often find myself needing to import something, but not quite sure of its fully qualified name. I usually end up opening a browser, performing an internet search like python [target_of_import], and scanning a page or two until I find it.
This works, but causes a relatively long break in my workflow, especially if I have to search for a few in a row. How do other people address this?
Is there something like Haskell's Hoogle for Python?
[Note: I currently use vim, in case anyone suggests an IDE-based solution.]
EDIT: For answers concerning autocomplete, please specify this. In general, autocomplete is probably a non-starter solution since in the particular case I am asking about the leftmost characters of the string to be autocompleted are not known.
EDIT 2: While I will not categorically rule out suggestions concerning switching to/learning a new IDE, I'm pretty unlikely to completely change the way I work to accomplish this (e.g., switching from vim on the command line to something like Eclipse + plugins).
You can do this in vim using the Unite.vim
Enable fuzzy file searching by adding the following to your .vimrc:
call unite#filters#matcher_default#use(['matcher_fuzzy'])
Search for file:
:UniteWithInput file_rec/async:/base/path:!<cr>
Search within files:
:UniteWithInut grep:/base/path<cr>
Search file names and within files
:UniteWithInput file_rec/async:/base/path:! grep:/base/path<cr>
(Use to change between sources)
See also :h :UniteWithCursorWord
This will open a buffer with the file matches. You can open the file by pressing enter but since you only want copy the file name simply use y$ to yank the line, q to close the buffer and the p to paste the yanked line.
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
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.