I am trying to understand a strange behaviour of the mark-set signal emitted by a Gtk.Textbuffer in a python program.
In fact this signal is emitted (in my case) multiple times for a single user action. This sounds not logical to me and I didn't find any reference to this in the documentation.
Well, the only reference I find is an unresolved question on this website.
The question I'm talking about is this one:
Gtk3 with Python, TextView rising multiple 'mark-set' signals
I'm trying the same code than in this question and get the same result.
Does anyone has an idea about what's going wrong?
Thank you very much for any clue or piece of advice.
PS: Gtk3 is used. I've tried to run this under both Linux and OSX and got the same behavior.
change the test function to:
def test (buffer, location, mark, user_data=None):
print(mark.get_name())
so that you can see the names of the marks, most likely are marks builtin in the buffer itself by GTK
Related
I am making a keylogger, but every source I see needs that function and it is not working properly.
I tried to update the library and it didn't fix the problem.
all the code is working except the part below.
I have no idea what the below means. pls, help me understand.
if you know a similar function pls help.
I am 14 years old so, I am not experienced will enough.
2 years in C Language. and 1-year web programming. and 1-year python pro.
obj = pyHook.HookManager()
obj.KeyDown = keypressed
obj.HookKeyboard()
pythoncom.PumpMessages()
This is not a Python error message. Unless I am mistaken, you are running PyCharm and you are getting a PyCharm popup when you mouse over the highlighted attribute PumpMessages.
This is nothing to worry about. It is happening because PyCharm's analysis doesn't always know how to examine Python extensions in DLLs. As PyCharm itself says,
This inspection detects names that should resolve but don't. Due to dynamic dispatch and duck typing, this is possible in a limited but useful number of cases.
One of the limitations of this inspection is functions in DLLs, which are dynamically dispatched.
If you look in the file pythoncom.py you will see that it doesn't in fact contain a definition of the function PumpMessages, only two lines that import pythoncom3x.dll. The function definition lives in that DLL and PyCharm can't find it there, because it would have to execute the code to establish where to look. The message is a false alarm.
If it bothers you, put the caret on the highlight, hit alt-Enter, click the lightbulb icon, and select one of the options to disable reporting of unresolved references, either for the function or for the entire pythoncom module. Otherwise just ignore it.
To turn it back on, hit ctrl-alt-S (Settings), choose Editor | Inspections | Python | Unresolved references.
So if your program isn't working as expected, look for the cause elsewhere. This warning is not the problem.
I'm writing a python app, whose main purpose is to run a minigame (using the 'pygame' library), whenever I use a hotkey (which currently uses the 'keyboard' library). I want this hotkey to be recognized universally, so I'm packaging the whole thing as a status bar app (using the 'rumps' library).
So far, I can start the whole thing, select Play from the status bar dropdown, and it works! Great.
HOWEVER, if I attempt to use the bound hotkey, to run the same function that Play triggers, I get:
python[58226:599749] pid(58226)/euid(0) is calling TIS/TSM in non-main thread
environment, ERROR : This is NOT allowed. Please call TIS/TSM in main thread!!!
This shows up four times, and is followed up
python[58226:599749] WARNING: nextEventMatchingMask should only be
called from the Main Thread! This will throw an exception in the future.
To check that it wasn't the hotkey itself, I did a test: If I connect the hotkey to a simpler function, like setting an alert, it works fine. It still complains, and gives me the error:
python[60308:620099] -[NSAlert runModal] may only be invoked from the main thread. Behavior on other threads is undefined. (
0 AppKit 0x00007fff2b7f563f -[NSAlert runModal] + 178
1 _objc.cpython-36m-darwin.so 0x000000010c1358c7 ffi_call_unix64 + 79
2 ??? 0x000070000f3b2e50 0x0 + 123145557847632
)
but it does RUN. However if it connects to the Play function, it breaks (and produces the first error, above).
To summarize:
1) Dropdown => run minigame: Success!
2) Hotkey => run minigame: Incomprehensible errors!
I've googled this error, but have only seen explanations that are way over my head; is there a way that I could get around this error, by using different software, or a different approach -- but without having to leave python, or performing some deep and evil hack to an underlying system?
Could I get the hotkey/game to USE the Main Thread environment, somehow? How?
Could I use a vehicle other than a status bar app to listen for the hotkey? (Update: I tried pynput, and got the same non-main thread error.)
Could I do something inside of pygame to not make it as offensive? (At the moment, it's literally just animating a rolling sine wave.)
Could I get the rumps callback function to work? At the moment, it's just not doing ANYTHING, no matter where or how it's called.
(And unfortunately, this on a Mac, because pyhk3 is for windows only, and
wx.Window (which can have hotkeys) is also for windows only)
FURTHER failure: Can't get it to run with Keyboard Maestro either -- I've never used it before, so may well be using it wrong, but it also seems like a VERY simple command, that just flat-out has no response whatsoever.
Aaand ... the Automator script runs, but -- not with the hotkey! (EDIT: The hotkey was apparently taken. But a different one worked! See below.)
This problem is a MacOS 10.13 Sierra error. It is being reported with Processing.org 3d applications, as well as a Program called Synergy.
I'm accepting my own answer because it is the only one so far that solves the problem I was most interested in, i.e. getting the thing to run with a global shortcut, BUT, since I would ideally like to package and distribute this, I would still be very glad to see answers that solved the problem within python, and would gladly award the bounty to any answer that did that.
Finally, finally, made it work with a Service in Automator, and System Preferences > Keyboard > Shortcuts. Along the way, I had to
Explicitly call the python binary I wanted to use, because the bash shell that Automator uses in executing a text script is apparently different from the one in Terminal
Realize that the System Preferences shortcut wasn't working because of the key-combination I first chose, NOT that it was being blocked, because there were no errors or messages when I called it.
Probably all sorts of other things. Good god.
I'm still in the process of learning more about WxPython and I ran into a simple problem.
I like the wx.AboutBox class that manages how credits, licensing and other info is displayed to the user...and I'm not looking forward to building my own from scratch...although I can.
The problem here is that let's say I click on a button which brings up an AboutBox...seems like if you keep on clicking that exact button then multiple instances of the same AboutBox is brought up...and you end up multiple windows that just looks awkward in my opinion. As far as I've looked into it...there's no way to call the ShowModal() function that would allow you to get the ID of the close button in the aboutbox template and do some processing to make sure that only one instance is running.
I want to know how to stop this issue from happening...I want a single instance of wx.AboutBox and if it's not possible with this class due to it's nature/limitations then I'll have to consider building my own as a last resort.
Thanks
Creating your own AboutBox dialog is pretty easy. Here's an article that shows one way to do it: http://www.blog.pythonlibrary.org/2008/06/11/wxpython-creating-an-about-box/ or you could just use a GenericMessageDialog too. See the wxPython demo or http://www.blog.pythonlibrary.org/2010/07/10/the-dialogs-of-wxpython-part-2-of-2/
It seems like you haven't solved this problem yet. In wxPython, there's a class called "SingleInstanceChecker". I think this is what you're looking for.
http://wxpython.org/Phoenix/docs/html/SingleInstanceChecker.html
I'm looking for a Python module/framework/package that will assist me in making a sort of "better" console for my application. As it stands now, STDIN can be "pushed" to new lines by other messages being logged out to the console, therefore making it difficult to read what you are trying to type into a server console if it is a long command, or you are prone to typing errors.
Are there any sort of already existing modules that can help me do this? If it helps, it can be comparable to JLine, (at least I think, I have no first-hand experience with JLine).
Oh, and if you don't understand what I'm talking about, you can check the closest thing I can find of an example here. Basically, that bottom line in the console is where all commands are entered, and it doesnt get pushed back when the server is in use; it is sort of static in a sense.
Any ideas? Thanks!
readline module helps to build a nice prompt with history and auto-completion:
http://docs.python.org/library/readline.html
curses module allows you to separate the console into windows that can be separately scrolled:
http://docs.python.org/library/curses.html
I've created a little screensaver-type program with Python, and I'd like to get it working properly under gnome-screensaver. The documentation is all written for C, and there don't appear to be libraries for Python. Is there any way to get this working?
gnome-screensaver doesn't integrate with the screensavers any more than with a small config file that sets the name, some other properties, and a command to execute to start the screensaver. This is documented in the gnome-screensaver FAQ.
The program that gets started needs to get the Window ID from the environment (XSCREENSAVER_WINDOW), and start displaying on that window. This is the tricky part, as it's not always obvious how to do that. Most toolkits should have methods to get a handle on an already existing window by giving the ID, so search your GUI-toolkit documentation for something like that.