如何改变GTK的位置windows

How to change the position of GTK windows

我试图在 Ubuntu 20.04I got the working code from NOrbert answer 中将 html 文件显示为桌面小部件,但问题是左对齐(见附图)

工作python代码

import gi
gi.require_version('Gtk', '3.0')
gi.require_version('WebKit2', '4.0')
from gi.repository import WebKit2, Gtk, Gdk, Gio, GLib
import signal, os

document="file:///home/sai/Downloads/Compressed/JS-Calendar-master/calendar.html"

class MainWin(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self, skip_pager_hint=True, skip_taskbar_hint=True)
        self.set_wmclass("sildesktopwidget","sildesktopwidget")
        self.set_type_hint(Gdk.WindowTypeHint.DOCK)
        self.set_size_request(500,400)
        self.set_keep_below(True)



        #Set transparency
        screen = self.get_screen()
        rgba = screen.get_rgba_visual()
        self.set_visual(rgba)
        self.override_background_color(Gtk.StateFlags.NORMAL, Gdk.RGBA(0,0,0,0))

 
        #Add all the parts
        self.view = WebKit2.WebView()
        #self.view.set_transparent(True)
        self.view.override_background_color(Gtk.StateFlags.NORMAL, Gdk.RGBA(0,0,0,0))
        #self.view.props.settings.props.enable_default_context_menu = False
        # configure transparency as in https://github.com/LTSchmiddy/dungeon-commander/blob/8d5c58ca321a05519c8cb1c5afdebba4954cbfca/src/webview/platforms/gtk.py#L132
        configure_transparency(self)
        configure_transparency(self.view)
        wvbg = self.view.get_background_color()
        wvbg.alpha = 0.0
        self.view.set_background_color(wvbg)

        self.view.load_uri("file://"+document)

        box = Gtk.Box()
        self.add(box)
        box.pack_start(self.view, True, True, 0)
        self.set_decorated(False)
        self.connect("destroy", lambda q: Gtk.main_quit())

        #Show all the parts
        self.show_all()
        self.move(100,100)


def refresh_file(*args):
    print args
    mainwin.view.reload()

def file_changed(monitor, file, unknown, event):
    # reload
    GLib.timeout_add_seconds(2, refresh_file)

# configure transparency as in https://github.com/LTSchmiddy/dungeon-commander/blob/8d5c58ca321a05519c8cb1c5afdebba4954cbfca/src/webview/platforms/gtk.py#L549
def configure_transparency(c):
    c.set_visual(c.get_screen().get_rgba_visual())
    c.override_background_color(Gtk.StateFlags.ACTIVE, Gdk.RGBA(0, 0, 0, 0))
    c.override_background_color(Gtk.StateFlags.BACKDROP, Gdk.RGBA(0, 0, 0, 0))
    c.override_background_color(Gtk.StateFlags.DIR_LTR, Gdk.RGBA(0, 0, 0, 0))
    c.override_background_color(Gtk.StateFlags.DIR_RTL, Gdk.RGBA(0, 0, 0, 0))
    c.override_background_color(Gtk.StateFlags.FOCUSED, Gdk.RGBA(0, 0, 0, 0))
    c.override_background_color(Gtk.StateFlags.INCONSISTENT, Gdk.RGBA(0, 0, 0, 0))
    c.override_background_color(Gtk.StateFlags.INSENSITIVE, Gdk.RGBA(0, 0, 0, 0))
    c.override_background_color(Gtk.StateFlags.NORMAL, Gdk.RGBA(0, 0, 0, 0))
    c.override_background_color(Gtk.StateFlags.PRELIGHT, Gdk.RGBA(0, 0, 0, 0))
    c.override_background_color(Gtk.StateFlags.SELECTED, Gdk.RGBA(0, 0, 0, 0))
    transparentWindowStyleProvider = Gtk.CssProvider()
    transparentWindowStyleProvider.load_from_data(b"""
        GtkWindow {
            background-color:rgba(0,0,0,0);
            background-image:none;
        }""")
    c.get_style_context().add_provider(transparentWindowStyleProvider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)


if __name__ == '__main__':
    gio_file = Gio.File.new_for_path(document)
    monitor = gio_file.monitor_file(Gio.FileMonitorFlags.NONE, None)
    monitor.connect("changed", file_changed)

    mainwin = MainWin()
    signal.signal(signal.SIGINT, signal.SIG_DFL) # make ^c work
    Gtk.main()

尝试过的解决方案

self.set_position(Gtk.WindowPosition.CENTER)
  or 
self.set_position(Gtk.WindowPosition.MOUSE) 

above solutions is working in this example but not in my code

请帮助我改变类似于 self.set_position(x,y) 的位置,这对我改变 x 和 y 值非常方便。

在上面的代码中#Show all the parts

#Show all the parts
        self.show_all()
        self.move(100,100)   ------> by changing this we can change the position