QtRuby on OSX restore minimized window on timer - macos

I'm writing a time logging application using QtRuby on OSX. It is important that it periodically reminds users (my team) to log their time, preferably by coming to the foreground (unminimizing, if necessary). This is very un-mac-like, so I would accept a bouncing task tray icon. I can't get either to work.
Anyway, I've tried the following
self.show()
self.showNormal()
self.raise()
self.activateWindow()
self.maximize()
self.setWindowState(Qt::WindowActive)
self.setWindowState(Qt::WindowMaximized)
# Must execute this with GUI thread
msgbox = Qt::MessageBox.new()
msgbox.setText('LOG YOUR TIME!')
msgbox.exec()
All these commands seem to be ignored once minimised or in the background. When trying to popup the messagebox, I worked around the "Cannot create children for a parent that is in a different thread." error by emitting a signal, but events don't seem to be processed until the user activates the window.
Does anyone know how to pop-up a minimised window with QTRuby or even QT & C++ on OSX?
TIA
Luke

I used Qt's threads rather than ruby threads and everything is lovely now. Maybe be something to do with the global interpreter lock.
I replaced
Thread.new { loop { every_minute_do_on_diff_thread; sleep 60 } }
connect(self, SIGNAL('every_minute_do_signal()'), self, SLOT('every_minute_do()'))
def every_minute_do_on_diff_thread
emit(every_minute_do_signal())
end
with
timer = Qt::Timer.new(self);
connect(timer, SIGNAL('timeout()'), self, SLOT('every_minute_do()'))
timer.start(60000)

Related

Run "Shoes::Every" in background of a Shoes::App (Ruby)

I have been working on a makeshift RPG, and the Regenerate function, is supposed to be called every 3 seconds, NO MATTER WHAT THE PLAYER's STATUS IS
For Example:
Shoes.app do
# Display on main screen
animate do
# Set para(s) to current values of health and other stats
end
every 3 do
RegenerateVitals
end
end
But at times, the user will click on buttons that will trigger functions and new windows (the base window will keep opened in the background at all times.)
Do the every function really runs behind the scenes every 3 seconds no matter what menu the player is on? Or do I need to do something else for that?
Thanks.
Yes, the specification is that every calls the block no matter what (as long as the main windows stays open). I looked up the implementation of shoes4 and that one definitely does it (using the SWT scheduler) but other implementations such as Shoes 3.1, 3.2 and green shoes should do the same.

Execute a MEL command after a window has opened

I'm writing a MEL script which involves opening the grease pencil UI toolbar. I want to remove the close button on that toolbar. I tried doing
GreasePencilTool;
window -edit -tbm 0 greasePencilFloatingWindow;
but get Error: line 2: window: Object 'greasePencilFloatingWindow' not found.
Further tests reveal that running
GreasePencilTool;
window -q -exists greasePencilFloatingWindow;
will return a result of 0.
Running GreasePencilTool; and then window -edit -tbm 0 greasePencilFloatingWindow; at separate times works as expected, as does running window -edit -tbm 0 greasePencilFloatingWindow; when the toolbar is already open.
However, I need to be able to remove the close button immediately when the toolbar opens.
The closest thing I can think of that illustrates what I want to do are Javascript callback functions, where another function can be executed once the current function is finished... but is there a way to do something like that in MEL?
I've also tried using the evalDeferred command without success.
The grease pencil tool is launched asynchronously so the window will not be present for some unknown length of time. This means the best you could do is trigger a function which would check periodically and do it the next time you find the correctly named window; you could attach this to an idle time script job.
It's ugly. But it is probably the only way since there's no event that will notify when thje window arrives. If you do that, make the script job suicide after it fires so it's not sitting there on every idle check till the end of time.

System notification window stuck causes the program to get stuck[Cocoa][Mac OSX]?

I am trying to show a notification window in a Mac application.Something that would come up in the trial version of the application.The window would be unmovable for 30 seconds(and it would have a counter counting down to 0).After 30 seconds it would continue execution.
Here is the code.
_systemNotificationWindow = [[SystemNotificationWindow alloc]initWithWindowNibName:#"SystemNotificationWindow"];
NSLog(#"1111");
[self.systemNotificationWindow setActionDelegate:self];
[self.systemNotificationWindow startTimer:30];
NSLog(#"2222");
[self.systemNotificationWindow showWindow:self];
NSLog(#"3333");
NSLog(#"4444");
The code is stuck at this line
[self.systemNotificationWindow showWindow:self];
It shows the window but neither the timer is working nor the window is going away after 30 seconds.Alsoo 3333 and 4444 are not being printed.
It sounds like you're missing an event loop to control the timer, so I'm guessing that you're displaying the window before an event loop has been created.
You can read more about events here and run loops here.

SIGWINCH equivalent on Windows?

This could very well be another silly question, but I can't seem to find the answer (or any for that matter), so here goes.
I have a command line program that uses SIGWINCH on Linux to detect the window size change, and I apparently have a user who is using the program on Windows. The problem, is that the program uses SIGWINCH to detect changes in the window size and this signal is unsupported on Windows. I've tried Googling for every combination of search terms I can think of, but due to the relationship between SIGWINCH and changes in the size of the window, I'm having trouble finding any useful results. I'm looking for a Windows equivalent, or the method most often used to detect changes in the window size on Windows computers.
How do you detect changes in window size on Windows?
Since I don't think you can subclass console windows (and thus catch WM_SIZE messages), you may just have to poll GetConsoleScreenBufferInfo.
EDIT: Upon further investigation (not tested!), it might also be doable without polling using ReadConsoleInput. Summary: Call SetConsoleMode to turn on window input events. From a different thread, wait for the console input handle to become signaled using WaitForSingleObject or a similar function. Read all pending console events; the presence of window buffer size events means something's resized your console window.

wxPython - Trapping Mouse & Keyboard Events without window Focus

I am attempting to write a time management tool with wxPython that is ideally non-obtrusive and very much out of the way. The app so far can be used normally and minimized to the system tray for the duration of its use.
However, I notice that once the frame is not in focus, as it is when its 'Iconized', the mouse and keyboard trapping that normally works when the frame/app is in focus no longer works.
I am aware that I could write a C++ program to create a Message Queue Hook and trap all mouse and keyboard events at the OS level, but Id rather not roll up my sleeves that far. After all trying to avoid getting my hands that dirty is why I am writing the UI in wxPython in the first place :)
Do you really need mouse and keyboard events or would it be sufficient to just know if the user has been idle? (You mentioned a time management app, so this seems feasible.)
This code will work on Windows and returns the idle time in seconds.
from ctypes import Structure, windll, c_uint, sizeof, byref
class LASTINPUTINFO(Structure):
_fields_ = [
('cbSize', c_uint),
('dwTime', c_uint),
]
def get_idle_duration():
lastInputInfo = LASTINPUTINFO()
lastInputInfo.cbSize = sizeof(lastInputInfo)
windll.user32.GetLastInputInfo(byref(lastInputInfo))
millis = windll.kernel32.GetTickCount() - lastInputInfo.dwTime
return millis / 1000.0

Resources