src/eric7/Snapshot/SnapshotWaylandGrabber.py

branch
eric7
changeset 10155
722f018e5c08
parent 9653
e67609152c5e
child 10180
3a595df36c9a
equal deleted inserted replaced
10154:d833c6a8c41f 10155:722f018e5c08
35 35
36 @signal grabbed(QPixmap) emitted after the grab operation is finished 36 @signal grabbed(QPixmap) emitted after the grab operation is finished
37 """ 37 """
38 38
39 grabbed = pyqtSignal(QPixmap) 39 grabbed = pyqtSignal(QPixmap)
40
41 GnomeScreenShotService = "org.gnome.Shell"
42 GnomeScreenShotObjectPath = "/org/gnome/Shell/Screenshot"
43 GnomeScreenShotInterface = "org.gnome.Shell.Screenshot"
44
45 KdeScreenShotService = "org.kde.KWin"
46 KdeScreenShotObjectPath = "/Screenshot"
47 KdeScreenShotInterface = "org.kde.kwin.Screenshot"
40 48
41 def __init__(self, parent=None): 49 def __init__(self, parent=None):
42 """ 50 """
43 Constructor 51 Constructor
44 52
130 """ 138 """
131 snapshot = QPixmap() 139 snapshot = QPixmap()
132 140
133 if DesktopUtilities.isKdeDesktop(): 141 if DesktopUtilities.isKdeDesktop():
134 interface = QDBusInterface( 142 interface = QDBusInterface(
135 "org.kde.KWin", "/Screenshot", "org.kde.kwin.Screenshot" 143 SnapshotWaylandGrabber.KdeScreenShotService,
144 SnapshotWaylandGrabber.KdeScreenShotObjectPath,
145 SnapshotWaylandGrabber.KdeScreenShotInterface,
136 ) 146 )
137 reply = interface.call("screenshotFullscreen", self.__captureCursor) 147 reply = interface.call("screenshotFullscreen", self.__captureCursor)
138 if self.__checkReply(reply, 1): 148 if self.__checkReply(reply, 1):
139 filename = reply.arguments()[0] 149 filename = reply.arguments()[0]
140 if filename: 150 if filename:
142 with contextlib.suppress(OSError): 152 with contextlib.suppress(OSError):
143 os.remove(filename) 153 os.remove(filename)
144 elif DesktopUtilities.isGnomeDesktop(): 154 elif DesktopUtilities.isGnomeDesktop():
145 path = self.__temporaryFilename() 155 path = self.__temporaryFilename()
146 interface = QDBusInterface( 156 interface = QDBusInterface(
147 "org.gnome.Shell", 157 SnapshotWaylandGrabber.GnomeScreenShotService,
148 "/org/gnome/Shell/Screenshot", 158 SnapshotWaylandGrabber.GnomeScreenShotObjectPath,
149 "org.gnome.Shell.Screenshot", 159 SnapshotWaylandGrabber.GnomeScreenShotInterface,
150 ) 160 )
151 reply = interface.call("Screenshot", self.__captureCursor, False, path) 161 reply = interface.call("Screenshot", self.__captureCursor, False, path)
152 if self.__checkReply(reply, 2): 162 if self.__checkReply(reply, 2):
153 filename = reply.arguments()[1] 163 filename = reply.arguments()[1]
154 if filename: 164 if filename:
172 # default to screen 0 182 # default to screen 0
173 screenId = 0 183 screenId = 0
174 184
175 # Step 2: grab the screen 185 # Step 2: grab the screen
176 interface = QDBusInterface( 186 interface = QDBusInterface(
177 "org.kde.KWin", "/Screenshot", "org.kde.kwin.Screenshot" 187 SnapshotWaylandGrabber.KdeScreenShotService,
188 SnapshotWaylandGrabber.KdeScreenShotObjectPath,
189 SnapshotWaylandGrabber.KdeScreenShotInterface,
178 ) 190 )
179 reply = interface.call("screenshotScreen", screenId, self.__captureCursor) 191 reply = interface.call("screenshotScreen", screenId, self.__captureCursor)
180 if self.__checkReply(reply, 1): 192 if self.__checkReply(reply, 1):
181 filename = reply.arguments()[0] 193 filename = reply.arguments()[0]
182 if filename: 194 if filename:
185 os.remove(filename) 197 os.remove(filename)
186 elif DesktopUtilities.isGnomeDesktop(): 198 elif DesktopUtilities.isGnomeDesktop():
187 # Step 1: grab entire desktop 199 # Step 1: grab entire desktop
188 path = self.__temporaryFilename() 200 path = self.__temporaryFilename()
189 interface = QDBusInterface( 201 interface = QDBusInterface(
190 "org.gnome.Shell", 202 SnapshotWaylandGrabber.GnomeScreenShotService,
191 "/org/gnome/Shell/Screenshot", 203 SnapshotWaylandGrabber.GnomeScreenShotObjectPath,
192 "org.gnome.Shell.Screenshot", 204 SnapshotWaylandGrabber.GnomeScreenShotInterface,
193 ) 205 )
194 reply = interface.call( 206 reply = interface.call(
195 "ScreenshotWindow", 207 "ScreenshotWindow",
196 self.__captureDecorations, 208 self.__captureDecorations,
197 self.__captureCursor, 209 self.__captureCursor,
225 if self.__captureDecorations: 237 if self.__captureDecorations:
226 mask |= 1 238 mask |= 1
227 if self.__captureCursor: 239 if self.__captureCursor:
228 mask |= 2 240 mask |= 2
229 interface = QDBusInterface( 241 interface = QDBusInterface(
230 "org.kde.KWin", "/Screenshot", "org.kde.kwin.Screenshot" 242 SnapshotWaylandGrabber.KdeScreenShotService,
243 SnapshotWaylandGrabber.KdeScreenShotObjectPath,
244 SnapshotWaylandGrabber.KdeScreenShotInterface,
231 ) 245 )
232 reply = interface.call("interactive", mask) 246 reply = interface.call("interactive", mask)
233 if self.__checkReply(reply, 1): 247 if self.__checkReply(reply, 1):
234 filename = reply.arguments()[0] 248 filename = reply.arguments()[0]
235 if filename: 249 if filename:
237 with contextlib.suppress(OSError): 251 with contextlib.suppress(OSError):
238 os.remove(filename) 252 os.remove(filename)
239 elif DesktopUtilities.isGnomeDesktop(): 253 elif DesktopUtilities.isGnomeDesktop():
240 path = self.__temporaryFilename() 254 path = self.__temporaryFilename()
241 interface = QDBusInterface( 255 interface = QDBusInterface(
242 "org.gnome.Shell", 256 SnapshotWaylandGrabber.GnomeScreenShotService,
243 "/org/gnome/Shell/Screenshot", 257 SnapshotWaylandGrabber.GnomeScreenShotObjectPath,
244 "org.gnome.Shell.Screenshot", 258 SnapshotWaylandGrabber.GnomeScreenShotInterface,
245 ) 259 )
246 reply = interface.call( 260 reply = interface.call(
247 "ScreenshotWindow", 261 "ScreenshotWindow",
248 self.__captureDecorations, 262 self.__captureDecorations,
249 self.__captureCursor, 263 self.__captureCursor,

eric ide

mercurial