Warm tip: This article is reproduced from serverfault.com, please click

python 3.x-保留停放空间时出现结构错误

(python 3.x - Struct error while reserving space for dock)

发布于 2020-11-29 06:13:38

错误:

    File "/home/zorionten/Programs/Tests/dock/dockspace.py", line 16, in reserve_space
    self._window.change_property(self._display.intern_atom('_NET_WM_STRUT'),
  File "/home/zorionten/.local/lib/python3.8/site-packages/Xlib/xobject/drawable.py", line 430, in change_property
    request.ChangeProperty(display = self.display,
  File "/home/zorionten/.local/lib/python3.8/site-packages/Xlib/protocol/rq.py", line 1347, in __init__
    self._binary = self._request.to_binary(*args, **keys)
  File "/home/zorionten/.local/lib/python3.8/site-packages/Xlib/protocol/rq.py", line 1069, in to_binary
    static_part = struct.pack(self.static_codes, *pack_items)
struct.error: required argument is not an integer

dockspace.py

 from Xlib import display, X
class Window(object):
   
    def __init__(self, windowID):

        self._display = display.Display()
        self._window = self._display.create_resource_object('window', windowID)
    
    def reserve_space(self, left=0, right=0, top=0, bottom=0):

        LEFT    = left
        RIGHT   = right
        TOP     = top
        BOTTOM  = bottom

        self._window.change_property(self._display.intern_atom('_NET_WM_STRUT'),
                                    self._display.intern_atom('CARDINAL'),
                                    32, [LEFT, RIGHT, TOP, BOTTOM])
        self._display.sync()

我正在使用python3建立码头(如木板)。当尝试为扩展坞保留桌面scpave时,问题就来了。如果有另一种选择..我都很高兴

编辑:

经过进一步的实验,我发现错误是在主py文件中检索通过GTK + 3创建的“停靠窗口”的X窗口ID。

import gi

gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, GLib, Gdk, GdkX11
from datetime import datetime
import dockspace

class window(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self,title="Test")
        self.button_exit=Gtk.Button(label="Exit")
        self.button_exit.connect("clicked",self.onClick)    
        self.clock=Gtk.Label()  
        self.addWidgets() 
        GLib.timeout_add(1000, self.updateClock) 
        self.set_resizable(False)
        self.move(0,0)    
        self.set_default_size(1920,24) 
        
    def addWidgets(self):
        self.box=Gtk.Box(spacing=5)
        self.box.pack_start(self.button_exit,False,True,10)
        self.box.pack_start(self.clock,expand=True,fill=False,padding=10)
        
        self.add(self.box)
        
    def onClick(self,widget):
        Gtk.main_quit()      
    
    def updateClock(self):
        self.clock.set_label(datetime.now().strftime("%H:%M:%S %p"))   
        return True 
        
    def fix_window(self):
        set = False
        while set == False:
            try:
                window = dockspace.Window('''window id needed''')
                if window != None:
                    height = 24
                    window.reserve_space(0, 0, height, 0)
                    set = True
                else:
                    self.sleep(1)
            except:
                raise    

wi=window()    
wi.connect("destroy",Gtk.main_quit)
wi.show_all()
wi.fix_window()
Gtk.main()
Questioner
Zorion TheTenth
Viewed
11
Zorion TheTenth 2020-12-02 15:19:04

通过使用wmctrl -lp命令解决了消除了跨平台兼容性,但我无论如何都不打算这样做。