Skip to content

Commit ba2ce85

Browse files
authored
made the changes as suggested in the review
1 parent 90f2024 commit ba2ce85

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

examples/xdamage.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# examples/xdamage.py -- demonstrate damage extension
44
#
5-
# Copyright (C) 2002 Peter Liljenberg <petli@ctrl-c.liu.se>
5+
# Copyright (C) 2019 Mohit Garg <mrmohitgarg1990@gmail.com>
66
#
77
# This library is free software; you can redistribute it and/or
88
# modify it under the terms of the GNU Lesser General Public License
@@ -36,6 +36,7 @@
3636
import thread
3737
from Xlib.ext import damage
3838
from PIL import Image, ImageTk
39+
import traceback
3940

4041
def redraw(win, gc):
4142
# win.clear_area()
@@ -50,14 +51,14 @@ def blink(display, win, gc, cols):
5051
redraw(win, gc)
5152
display.flush()
5253

53-
def getImageFromWin(win,ptW,ptH,ptX=0,ptY=0):
54+
def get_image_from_win(win, pt_w, pt_h, pt_x=0, pt_y=0):
5455
try:
5556
raw = win.get_image(ptX,ptY, ptW,ptH, X.ZPixmap, 0xffffffff)
5657
image = Image.frombytes("RGB", (ptW, ptH), raw.data, "raw", "BGRX")
5758
return image
5859

5960
except Exception:
60-
print("exception thrown in getImageFromWin")
61+
traceback.print_exc()
6162

6263
def checkExt(disp):
6364
# Check for extension
@@ -69,7 +70,7 @@ def checkExt(disp):
6970
sys.exit(1)
7071
else:
7172
r = disp.damage_query_version()
72-
print('DAMAGE version %d.%d' % (r.major_version, r.minor_version))
73+
print('DAMAGE version %d.%d'.format(r.major_version, r.minor_version))
7374

7475
def main():
7576
d = display.Display()
@@ -120,14 +121,14 @@ def main():
120121
if event.count == 0:
121122
redraw(window1, gc)
122123
elif event.type == d.extension_event.DamageNotify:
123-
image = getImageFromWin(window1, event.area.width, event.area.height, event.area.x, event.area.y)
124-
bgpm = window2.create_pixmap(image.width,image.height,d.screen().root_depth)
125-
bggc = window2.create_gc(foreground=0,background=0)
124+
image = get_image_from_win(window1, event.area.width, event.area.height, event.area.x, event.area.y)
125+
bgpm = window2.create_pixmap(image.width, image.height, d.screen().root_depth)
126+
bggc = window2.create_gc(foreground=0, background=0)
126127
bgpm.put_pil_image(bggc, 0, 0, image)
127128
window2.copy_area(bggc, bgpm, 0, 0, image.width, image.height, 0, 0)
128129
# bggc.free()
129130
elif event.type == X.DestroyNotify:
130131
sys.exit(0)
131132

132133
if __name__ == "__main__":
133-
main()
134+
main()

0 commit comments

Comments
 (0)