r0x0r / pywebview

Build GUI for your Python program with JavaScript, HTML, and CSS
https://pywebview.flowrl.com
BSD 3-Clause "New" or "Revised" License
4.74k stars 554 forks source link

Is it possible to fix the top/left position of the pywebview window ? #129

Closed gdelpierre57 closed 7 years ago

gdelpierre57 commented 7 years ago

is it possible to define the top / left position of the webview window (i do not talk about the html content of the webview)

specify on the webview constructor the top/ left position on top of the width/height should be great or how can I achieve that , using another library ?

gdelpierre57 commented 7 years ago

to start, thanks for your very interesting development, to respond to my question, I just need to implement a new function to your gtk window object in order to move it to x,y coordinate. but it still be interesting to have that as parameters on the create_window contructor, I think .... :)

I found the answer here : http://pygtk.org/pygtk2reference/class-gtkwindow.html#method-gtkwindow--move

gtk.Window.move def move(x, y) x : the X coordinate to move window to

y : the Y coordinate to move window to

The move() method asks the window manager to move the window to the position specified by x and y. Window managers are free to ignore this. In fact, most window managers ignore requests for initial window positions (instead using a user-defined placement algorithm) and honor requests after the window has already been shown.

The position is the position of the gravity-determined reference point for the window. The gravity determines two things: first, the location of the reference point in root window coordinates; and second, which point on the window is positioned at the reference point. By default the gravity is gtk.gdk.GRAVITY_NORTH_WEST, so the reference point is simply the x, y supplied to the move() method. The top-left corner of the window decorations (aka window frame or border) will be placed at x, y. Therefore, to position a window at the top left of the screen, you want to use the default gravity (which is gtk.gdk.GRAVITY_NORTH_WEST) and move the window to 0,0.

To position a window at the bottom right corner of the screen, you would set gtk.gdk.GRAVITY_SOUTH_EAST, which means that the reference point is at x + the window width and y + the window height, and the bottom-right corner of the window border will be placed at that reference point. So, to place a window in the bottom right corner you would first set gravity to south east, then move the window: window.set_gravity(gtk.gdk.GRAVITY_SOUTH_EAST) width, height = window.get_size() window.move(gtk.gdk.screen_width() - width, gtk.gdk.screen_height() - height)

The Extended Window Manager Hints specification has a nice table of gravities in the "implementation notes" section. The get_position() method documentation may also be relevant.

shivaprsd commented 7 years ago

Thanks for the suggestion and the info, but is this really a common requirement? One rarely needs to pin-point window placement. And this varies with platform, as you said, GTK makes it clear that window managers are free to ignore such requests. Moving them afterwards is also not good for UX..

Axel-Erfurt commented 3 years ago

It's an old post, but I was just faced with this question. In Linux Mint I can simply enter a value that is larger than my screen and the window is placed in the lower right corner.

import webview
from sys import argv

if __name__ == '__main__':
    movie = argv[1]
    window = webview.create_window('Movie', 
                                    movie, 
                                    width = 500, 
                                    height = 280, 
                                    x = 1200, 
                                    y = 1200, 
                                    frameless = True, 
                                    on_top = True)
    webview.start()