Is there any tkinter widget or window manager to realize internal frame (something like java internal frame)? Have done some search but couldn't see any discussion on python support of internal frame.
No, there is nothing pre-built, but tkinter has all of the fundamental building blocks to implement it. The embedded windows are just frames, and you can place them in a containing frame with place. You can add your own border, and add mouse bindings to allow the user to move the windows around.
For what it's worth, usability experts long ago decided this type of UI isn't very user friendly.
Related
I have a program that has some rather bad window handling. I can provide scripting to the client portion of the application but have no control over the non-client portion, apart from some simple movement/resizing commands (that don't help).
The main problem is that when the windows "maximize" button is pressed the WS_MAXIMIZE style is not set. The window is positioned correctly, and helpfully respects the taskbar settings but the application icon/title and "windows buttons" are misplaced and the borders show up on any other screens.
Using winspy++ I was able to set the WS_MAXIMIZE style fixing these graphical annoyances. but this also led into a secondary issue. The "restore" button also does nothing, when pressed it simply reverts the style and does not take the application back to it's pre-maximized position and size.
I was going to make a launcher for this program in Python anyway, to handle some .ini stuff and alterable executable parameters.
I would like to extend this launcher to silently run behind the application, fixing these issues.
These things were intended to be handled by the operating system and the developers of the application do not seem to be focused on working on these problems, but more on increasing the library of application scripting and porting to other systems.
My assumption is that when the launcher is commanded to run the program it needs to have access to the thread/process so that it can poll the position and size of the application window and set the appropriate style when it is required, and more importantly (I guess), have access to it's memory.
Example: [-8,-8] to [1374,776] on a 1366x768 screen with a minimized taskbar.
If there is an asynchronous method to detect when the window has been moved/resized/windows buttons pressed, that would be preferable to polling every step.
Supplying the window with "restore" information to make use of the restore button seems a bit less trivial. I have been reading as much reference as I can find but have not found anything on this. Where is this memory stored? How do I access it? Is it read-only, and only set by the OS?
I'm new to Python, and SO, so I apologize if my question doesn't fit here, I've tried.
I'm wondering how difficult it will be to use invoke matplotlib from a Tcl interpreter and plot to a Tk canvas created on the Tcl side.
I'm wondering what the best way to do this is.
I'm guessing I'll have to create a python interpreter, pass the canvas handle from the Tcl side to python and make use of the C API in both languages. Or is there a more elegant way?
Getting this integration right won't be easy. However, here's what I'm thinking about:
Connecting Python and Tcl
You can run Python inferior to Tcl apparently. According to this wiki page, there's a package called tclpython which can do the basic integration work for you, and the page linked to appears live. The code appears to be here, though it might need some work to make it build. (I've never tried.)
Connecting matplotlib and Tk
You can make matplotlib draw on a Tkinter window, and as long as you can make that Tkinter window with the right options, it will show up. The key is that the underlying system window IDs can be found out from Tk with winfo id $nameOfTheWindow. If you create a frame with the -container option set to true (which turns off some things and turns on a few others; you'll need to set the size explicitly) then that particular frame will be suitable for use with TkAgg on the python/matplotlib side. The key will be to make a toplevel on that side that has the -use option set to the ID retrieved from winfo id. You probably need to make sure that the python side is running its rendering in a separate thread to the outer Tcl/Tk to make the event handling work right (unless you're keen on doing deep event loop hacking; the situation is that you're actually going to have Tcl/Tk inside Python inside Tcl/Tk, as Tkinter works by delegating to a subordinate Tcl/Tk, and getting all this glued together right will be “a bit tricky”).
If that doesn't work, get matplotlib to render as an image (GIF or PNG; the latter is preferred if you've got Tk 8.6) as you can just show that easily via a photo image. This is definitely going to be possible to do without thread games; it's just passing around pure data. Probably slower and not interactive, but that might not matter for what you're doing, and it is easier in the simple case.
You will probably need the second approach if you're on Windows or OSX, as Tk there doesn't actually use X11. (Unless you're using one of the more perverse configuration options, of course.)
I have been using pyqt and qt designer to make a program. I wanted to custom style the top bar which holds the icon and minimize,resize,close buttons. To do this I started with using the Qt.FramelessWindowHint and making custom buttons and such. This has led to many problems with grabbing corners to resize and also snapping (all the built in windows functions). I was trying to sort through this but found many people talking about the problems that I am having. I was trying to go for the google chrome/maya/photoshop look where the top part is completely customized. A friend pointed out that if any of these programs crash, you can notice the windows bar will show through, which means they are not actually removing it but styling above it or something of that sort. How can I go about doing this so all the functionality is still there but it is styled.
Is there any way I can create a UAC-like environment in Python? I want to basically lock the workstation without actually using the Windows lock screen. The user should not be able to do anything except, say, type a password to unlock the workstation.
You cannot do this without cooperation with operating system. Whatever you do, Ctrl-Alt-Del will allow the user to circumvent your lock.
The API call you're looking for Win32-wise is a combination of CreateDesktop and SetThreadDesktop.
In terms of the internals of Vista+ desktops, MSDN covers this, as does this blog post. This'll give you the requisite background to know what you're doing.
In terms of making it look like the UAC dialog - well, consent.exe actually takes a screenshot of the desktop and copies it to the background of the new desktop; otherwise, the desktop will be empty.
As the other answerer has pointed out - Ctrl+Alt+Delete will still work. There's no way around that - at least, not without replacing the keyboard driver, anyway.
As to how to do this in Python - it looks like pywin32 implements SetThreadDesktop etc. I'm not sure how compatible it is with Win32; if you find it doesn't work as you need, then you might need a python extension to do it. They're not nearly as hard to write as they sound.
You might be able to get the effect you desire using a GUI toolkit that draws a window that covers the entire screen, then do a global grab of the keyboard events. I'm not sure if it will catch something like ctrl-alt-del on windows, however.
For example, with Tkinter you can create a main window, then call the overrideredirect method to turn off all window decorations (the standard window titlebar and window borders, assuming your window manager has such things). You can query the size of the monitor, then set this window to that size. I'm not sure if this will let you overlay the OSX menubar, though. Finally, you can do a grab which will force all input to a specific window.
How effective this is depends on just how "locked out" you want the user to be. On a *nix/X11 system you can pretty much completely lock them out (so make sure you can remotely log in while testing, or you may have to forcibly reboot if your code has a bug). On windows or OSX the effectiveness might be a little less.
I would try with pygame, because it can lock mouse to itself and thus keep all input to itself, but i wouldn't call this secure without much testing, ctr-alt-del probably escape it, can't try on windows right now.
(not very different of Bryan Oakley's answer, except with pygame)
I managed to get it working on Win32 (inheriting from wx.MiniFrame does the trick), on wxGTK (wx.PopupWindow) but whatever I try, when I create a frame on wxMac, my main window loses focus and the new frame gets it.
wxMac does not seem to have a way to interact with the native platform (something like GetHandle() on Win32 and GetGTKWidget() on wxGTK), so I can't hack around it this way.
I managed to get this working in another situation, by creating the frame at startup and moving it outside of the display area, then moving it in a visible position when needed. But right now this would be cumbersome because I don't know in advance how many frames I will need.
So, any simpler way to do this ?
If you want to get native handle to window in Mac you can do
frame.MacGetTopLevelWindowRef()
and may be you can use pyobjc to interact with windows natively, but why don't you set focus on the window you want to after opening mini-frame?