<TL;DR>
It's used for internationalization in the GTK+, GIMP's GUI Toolkit. The link to the documentation is: N_()
</TL;DR>
I'm working on Python-Fu and frequently see strings surrounded by N_(), as in: N_("Some random string").
Yet in another plug-in, the N_() wont be there and "Some random string" works just fine.
So what gives? I've searched around but didn't really find anything on this. A little help from a python expert would be greatly appreciated as I'm fairly new to it. Thanks!
<< Edit >>
This is a python plug-in registration function call for GIMP 2.8. It is required in each plugin and it registers the plugin with the GUI, showing up in the menuing system where you dictate in the 12th argument.
This is not to be confused with an earlier version of GIMP's parameter order, or Script-Fu, which is based on Scheme and so is unfortunately ugly as sin.
register(
"omnicyde_btn_metal_ring",
N_("Badass Glossy Metal Ring Button"),
"This is going to be so incredibly sweet",
"Omnicyde",
"Omnicyde",
"2014",
"_BtnMetalRing",
"",
[],
[],
btn_metal_ring,
menu="<Toolbox>/Omnicyde/Buttons",
domain=("gimp20-python", gimp.locale_directory)
)
So, in some plugins there will be a N_() wrapping a string, and in some there won't for the same string in the argument list. Both versions work..
I figured it was a python core construct or something, as I'm kinda new to it. Then again, I'm new to Python-Fu as well. It's equally possible this is some GIMP thing, or even Python-Fu..
It is as hinted in the comments. N_ is an i10n macro defined in gi18n.h. gi18n uses the gettext library.
http://opensource.apple.com/source/ChatServer/ChatServer-37.1/libraries/glib-2.4.5/glib/gi18n.h
As for the gettext_noop you can see its uses at
http://www.gnu.org/software/gettext/manual/html_node/Special-cases.html
Related
How can I call a python function from an advanced scripting voice command in Dragon NaturallySpeaking?
I don't want to use a third-party application such as dragonfly or NatLink (paper).
So, one way is to compile it. You can put a bunch of functions that do different things all into the same program and pass along appropriate arguments to select the function you want, and pass the parameters along. Returning the result can be tricky, though, but I usually use the Clipboard (so copy the py output to clip and read from clip in Dragon). Multi-word params need to have spaces escaped (%20) and process it inside your py.
Something like this:
ShellExecute "path\program.exe myFunc myPar1, my%20Par%202", 6 ' 6 runs minimized
Wait 1
myVar = Clipboard
Hth,
Warning: This is not an answer. I am not a programmer. I don't know any Python and have no way of testing it.
This is just a suggestion on how to solve this problem. I don't know where else to put this. I'd put it in a comment, but it allows no screenshots. Please edit and suggest as you wish.
There is answer on SO that deals with calling Python from Excel, which is a similar concept: https://stackoverflow.com/a/3569988/2101890. I am trying to use that here but don't know how.
When using commands in another programming language, you can sometimes add them by adding a reference in the MyCommands Editor. You can reference DLLs and other "stuff". Some references to libraries appear automatically. I've installed Python and hoped to find Python in the References, but no such luck:
There is no Python entry here that I can find. You may have better luck. If you do find something, check the box and see if you can add python commands without causing an error when saving the command.
Maybe you can browse to %localappdata%\Programs\Python\Python36\ and add some of the DLLs from there and call Python commands from there. Or try getting it to work in the way described under 1.
My end goal is to enable people that know the language Urdu and not English to be able to program in a Python environment.
Urdu is written left to right. I imagine having Urdu versions of all python keywords and using Urdu characters to define variable/function/class names.
Is this goal possible? If yes, then what all will need to be done?
I can already see one issue where the standard library functions would still be in English.
Update:
Whether this should be done or not is certainly a very interesting debate topic, which I'd love to talk about. However, is it actually possible and how?
I love Python and I know a lot of intelligent people that might never be taught English properly, only Urdu, hence the thought.
Chinese Python used to allow programmers to write source code entirely in Chinese, including translated module names, function names, and all keywords. Here's a code example from their website:
載入 系統 # import sys
文件名 = 系統.參數[1:] # filenames = sys.argv[1:]
定義 修正行尾(文件): # def fixline(file):
內文 = 打開(文件).讀入() # text = open(file).read()
內文 = 內文.替換('\n\r','\n') # text = text.replace('\n\r', '\n')
傳回 內文 # return text
取 文件 自 文件名: # for file in filenames:
寫 修正行尾(文件) # print fixline(file)
Sadly, it is no longer an active project, but you can get the source and find out what they changed to get an idea for your own implementation. (Learning why they failed may also help you understand what challenges you will have in making such a system successful).
You can use the ideas project to transform keywords,
it has an example for making a kind of French Python.
It's based on python import-hook so it runs in normal python3.
I built a python in Hebrew (that also uses the python builtins and not just keywords ) using this project ,that looks more like a normal python
Yes, it is possible. But it requires you to download Python from source, and change the source code and compile it. If I remember correctly from another discussion on the same topic, changing the grammar and regenerating some files is all it takes, except for when you are doing advanced stuff like meta-programming and things.
WHAT HAVE YOU TRIED? Python 3 allows you to use Unicode for all your function, class and variable names. Check it out, you just need to make sure you're using utf-8 for your script-- it's primarily a matter for your editor. Dealing gracefully with the mixed RTL/LTR issues is also your editor's problem. (The feature is discussed in PEP 3131)
The python language does not have "dialects", i.e., alternative sets of keywords. If you are not satisfied with Urdu identifiers and you are determined to have a completely Urdu-language experience, you could write a preprocessor that maps Urdu "keywords" to the corresponding (English) python keyword.
It shouldn't be too hard to wrap this kind of preprocessor around the interactive console and import modules, so that it works transparently to the user (and without recompiling python from source). If you can program and want to try this on for size, check out python's code module. It's designed to read python source and send it on to be compiled and executed. You just step in and add a preprocessing step.
I'd use a preprocessor for keywords and built-ins. But providing localized wrappers for your choice of common modules is even easier, actually. Let's demonstrate with a wrapper module RE.py that contains all exported identifiers of regular re, but renamed to upper case:
import re as _re
for name in _re.__all__:
locals()[name.upper()] = _re.__dict__[name]
That was it! You can now import this module and use it:
import RE
docs = RE.SUB(r"\bEnglish\b", r"Urdu", docs)
Use Urdu words instead of uppercase (of course you need to specify each one individually) and you're on your way. As you say, whether all this is a good idea is a different question.
I want to focus a windows when it is blinking/flashing. The more common case is when someone sends some text by a chat software (for example MSN). In this case the windows bar is going to start blink in the start bar. I don't know if i am explaining myself. I want to get the HWND of the blinking windows. If more info is necesary to understand it, I will try to explain me better.
I have already searched info about this case but I find nothing. Maybe it can be resolver using "win32gui" library.
Thank you for your help!!!
First, most programs flash their windows by calling FlashWindowEx (or some higher-level function that wraps it). But there are a few apps—mostly from Microsoft—that do some custom stuff instead that looks like window-flashing to the end user, but may not look the same under the covers. Hopefully, you don't care about any such custom apps.
Anyway, the easiest way to capture that information is to install a shell hook with SetWindowsHookEx or RegisterShellHookWindow. (You could instead explicitly inject code in front of user32.dll… but you don't want to try that from Python.) When you do this, Windows will treat your window as if it were part of Explorer (the "shell") and send it special messages about what other programs are doing—in particular, WM_SHELLHOOKMESSAGE.
As forivall pointed out, this might be easier to do from AutoHotkey—this answer in the forums shows how to do it. It might also be easier to do from VB, or even C++. Yes, those languages are generally more difficult than Python, but the actual logic in your code is pretty trivial, and the only hard part is getting the shell hook messages, and that part will be easier in those languages. Another alternative is to use IronPython and do it via .NET.
But you asked if it's possible to do it from Python, and… yes, it is. I believe the relevant functions are not wrapped up by win32gui, so you'll have to use ctypes to do it from Python. See this SO question for a possible example, and look at some of the Related questions on the side and the ctypes docs for other examples of using ctypes to call different functions out of user.dll.
If you want to set a windows hook, the key function will look something like this (see ShellProc for details):
HSHELL_REDRAW=6
WM_SHELL=10
def my_callback(nCode, wParam, lParam):
if nCode == HSHELL_REDRAW and lParam:
got_flashing_window_with_hwnd(wParam)
hook = user32.SetWindowsHookEx(WM_SHELL, my_callback, None, 0)
But you need to set the types and push the callback through ctypes.
If you already have a window that you're managing from Python, it's probably easier to set yourself up as a shell hook window instead:
user32.RegisterShellHookWindow(my_hwnd)
Then, in your window proc:
WM_SHELLHOOKMESSAGE = None
def wndproc(hWnd, uMsg, lParam, wParam):
if WM_SHELLHOOKMESSAGE is None:
WM_SHELLHOOKMESSAGE = user32.RegisterWindowMessage('SHELLHOOK')
if uMsg == WM_SHELLHOOKMESSAGE and wParam == HSHELL_FLASH:
got_flashing_window_with_hwnd(lParam)
I'm not sure whether you need elevated privileges for either of these, but I would suspect you do.
I'm looking for an extension which will help in Python's auto complete feature in Python.
If I type the following code:
a = [4,5,6]
a.p
Then I expect it would give me a suggestion for pop as it is one of the method of Python list. Is this thing achievable in Emacs?
I tried installing Rope, Rope mode, Ropemacs and Pymacs. The auto-complete suggestion, I get from that aren't the methods of list. But it suggests me something like print etc. Am I doing something wrong ?
Try Jedi.el. AFAIK, it should support your example.
Because Python variables don't have types, it is difficult to know what class of object a variable would contain at a given point in your code. Imagine if your code later did a = 1. Emacs would have to know when the variable a refers to a list and when it refers to a number in order to offer the correct completion. Generally this is not possible without actually running the code.
Works for me with vimrope from https://github.com/python-rope/ropevim/ (now, the official home of all rope projects)
I'm noticing that even for system modules, code completion doesn't work too well.
For example, if I have a simple file that does:
import re
p = re.compile(pattern)
m = p.search(line)
If I type p., I don't get completion for methods I'd expect to see (I don't see search() for example, but I do see others, such as func_closure(), func_code()).
If I type m., I don't get any completion what so ever (I'd expect .groups(), in this case).
This doesn't seem to affect all modules.. Has any one seen this behaviour and knows how to correct it?
I'm running Vim 7.2 on WinXP, with the latest pythoncomplete.vim from vim.org (0.9), running python 2.6.2.
Completion for this kind of things is tricky, because it would need to execute the actual code to work.
For example p.search() could return None or a MatchObject, depending on the data that is passed to it.
This is why omni-completion does not work here, and probably never will. It works for things that can be statically determined, for example a module's contents.
I never got the builtin omnicomplete to work for any languages. I had the most success with pysmell (which seems to have been updated slightly more recently on github than in the official repo). I still didn't find it to be reliable enough to use consistently but I can't remember exactly why.
I've resorted to building an extensive set of snipMate snippets for my primary libraries and using the default tab completion to supplement.