Skip to content

Instantly share code, notes, and snippets.

@sahib
Last active October 2, 2019 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sahib/5536772 to your computer and use it in GitHub Desktop.
Save sahib/5536772 to your computer and use it in GitHub Desktop.
$ GDK_SYNCHRONIZE="1" gdb --args python swipe.py
(gdb) r
(gdb) bt
#0 0x00007ffff5b3beed in g_logv () from /usr/lib/libglib-2.0.so.0
#1 0x00007ffff5b3c0d2 in g_log () from /usr/lib/libglib-2.0.so.0
#2 0x00007ffff2f46e60 in ?? () from /usr/lib/libgdk-3.so.0
#3 0x00007ffff2f51801 in ?? () from /usr/lib/libgdk-3.so.0
#4 0x00007ffff29fd976 in _XError () from /usr/lib/libX11.so.6
#5 0x00007ffff29fabc1 in ?? () from /usr/lib/libX11.so.6
#6 0x00007ffff29fac05 in ?? () from /usr/lib/libX11.so.6
#7 0x00007ffff29fb495 in _XEventsQueued () from /usr/lib/libX11.so.6
#8 0x00007ffff25a4648 in XFixesCreateRegion () from /usr/lib/libXfixes.so.3
#9 0x00007fffeec3a048 in ?? () from /usr/lib/libGL.so.1
#10 0x00007fffeec3a0e3 in ?? () from /usr/lib/libGL.so.1
#11 0x00007fffe97a365b in ?? () from /usr/lib/libcogl.so.12
#12 0x00007fffe979a271 in cogl_onscreen_swap_region () from /usr/lib/libcogl.so.12
#13 0x00007fffe9c1acd8 in ?? () from /usr/lib/libclutter-1.0.so.0
#14 0x00007fffe9c7fda3 in ?? () from /usr/lib/libclutter-1.0.so.0
#15 0x00007fffe9c66898 in ?? () from /usr/lib/libclutter-1.0.so.0
#16 0x00007ffff5b34f06 in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
#17 0x00007ffff5b35258 in ?? () from /usr/lib/libglib-2.0.so.0
#18 0x00007ffff5b352fc in g_main_context_iteration () from /usr/lib/libglib-2.0.so.0
#19 0x00007ffff5420b34 in g_application_run () from /usr/lib/libgio-2.0.so.0
#20 0x00007ffff5187eb8 in ffi_call_unix64 () from /usr/lib/libffi.so.6
#21 0x00007ffff5187820 in ffi_call () from /usr/lib/libffi.so.6
#22 0x00007ffff6044044 in g_callable_info_invoke () from /usr/lib/libgirepository-1.0.so.1
#23 0x00007ffff60453ab in g_function_info_invoke () from /usr/lib/libgirepository-1.0.so.1
#24 0x00007ffff6280fdf in ?? () from /usr/lib/python3.3/site-packages/gi/_gi.so
#25 0x00007ffff7a76d36 in ext_do_call (nk=<optimized out>, na=<optimized out>, flags=<optimized out>, pp_stack=0x7fffffffdd08, func=0x7fffe7ff6e60) at Python/ceval.c:4374
#26 PyEval_EvalFrameEx (f=f@entry=0x7efb40, throwflag=throwflag@entry=0) at Python/ceval.c:2720
#27 0x00007ffff7a78335 in PyEval_EvalCodeEx (_co=_co@entry=0x7ffff3de9e40, globals=<optimized out>, locals=locals@entry=0x0, args=<optimized out>, argcount=argcount@entry=2, kws=0x97f8d8,
kwcount=0, defs=0x0, defcount=0, kwdefs=0x0, closure=0x7fffe9fdac50) at Python/ceval.c:3433
#28 0x00007ffff7a760d4 in fast_function (nk=<optimized out>, na=2, n=<optimized out>, pp_stack=0x7fffffffdf20, func=<optimized out>) at Python/ceval.c:4160
#29 call_function (oparg=<optimized out>, pp_stack=0x7fffffffdf20) at Python/ceval.c:4083
#30 PyEval_EvalFrameEx (f=f@entry=0x97f740, throwflag=throwflag@entry=0) at Python/ceval.c:2679
#31 0x00007ffff7a763c5 in fast_function (nk=<optimized out>, na=1, n=1, pp_stack=0x7fffffffe080, func=<optimized out>) at Python/ceval.c:4150
#32 call_function (oparg=<optimized out>, pp_stack=0x7fffffffe080) at Python/ceval.c:4083
#33 PyEval_EvalFrameEx (f=f@entry=0x69c490, throwflag=throwflag@entry=0) at Python/ceval.c:2679
#34 0x00007ffff7a78335 in PyEval_EvalCodeEx (_co=_co@entry=0x7ffff674d810, globals=globals@entry
=0x7ffff7f0a7a0, locals=locals@entry=0x7ffff7f0a7a0, args=args@entry=0x0,
argcount=argcount@entry=0, kws=kws@entry=0x0, kwcount=kwcount@entry=0, defs=defs@entry=0x0, defcount=defcount@entry=0, kwdefs=kwdefs@entry=0x0, closure=closure@entry=0x0)
at Python/ceval.c:3433
#35 0x00007ffff7a7840b in PyEval_EvalCode (co=co@entry=0x7ffff674d810, globals=globals@entry=0x7ffff7f0a7a0, locals=locals@entry=0x7ffff7f0a7a0) at Python/ceval.c:771
#36 0x00007ffff7a91a64 in run_mod (mod=<optimized out>, filename=filename@entry=0x7ffff7f2c7a0 "src/gui.py", globals=globals@entry=0x7ffff7f0a7a0, locals=locals@entry=0x7ffff7f0a7a0,
flags=flags@entry=0x7fffffffe340, arena=arena@entry=0x6c4d70) at Python/pythonrun.c:1982
#37 0x00007ffff7a93728 in PyRun_FileExFlags (fp=fp@entry=0x6d7590, filename=filename@entry=0x7ffff7f2c7a0 "src/gui.py", start=start@entry=257, globals=globals@entry=0x7ffff7f0a7a0,
locals=locals@entry=0x7ffff7f0a7a0, closeit=closeit@entry=1, flags=flags@entry=0x7fffffffe340) at Python/pythonrun.c:1938
#38 0x00007ffff7a94451 in PyRun_SimpleFileExFlags (fp=fp@entry=0x6d7590, filename=<optimized out>, closeit=closeit@entry=1, flags=flags@entry=0x7fffffffe340) at Python/pythonrun.c:1448
#39 0x00007ffff7a95253 in PyRun_AnyFileExFlags (fp=fp@entry=0x6d7590, filename=<optimized out>, closeit=closeit@entry=1, flags=flags@entry=0x7fffffffe340) at Python/pythonrun.c:1169
#40 0x00007ffff7aa8c27 in run_file (p_cf=0x7fffffffe340, filename=0x62a000 L"src/gui.py", fp=0x6d7590) at Modules/main.c:306
#41 Py_Main (argc=<optimized out>, argv=<optimized out>) at Modules/main.c:743
---Type <return> to continue, or q <return> to quit---
#42 0x0000000000400b29 in main ()
(gui.py:2772): Gdk-ERROR **: The program 'swipe.py' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadDrawable (invalid Pixmap or Window parameter)'.
(Details: serial 1272 error_code 9 request_code 152 minor_code 9)
(Note to programmers: normally, X errors are reported asynchronously;
that is, you will receive the error a while after causing it.
To debug your program, run it with the GDK_SYNCHRONIZE environment
variable to change this behavior. You can then get a meaningful
backtrace from your debugger if you break on the gdk_x_error() function.)
[1] 2772 trace trap (core dumped) python swipe.py
import sys
from gi.repository import GLib, Gdk, Gtk, GtkClutter, Clutter
def _render_pixbuf(widget, width, height):
# Use an OffscreenWindow to render the widget
off_win = Gtk.OffscreenWindow()
off_win.add(widget)
off_win.set_size_request(width, height)
off_win.show_all()
# this is needed, otherwise the screenshot is black
while Gtk.events_pending():
Gtk.main_iteration()
# Render the widget to a GdkPixbuf
widget_pix = off_win.get_pixbuf()
# Remove the widget again (so we can reparent it later)
off_win.remove(widget)
return widget_pix
def _create_texture(pixbuf, width, height, x_off=0, y_off=0):
# Create a Clutter Texture from it
ctex = GtkClutter.Texture()
if pixbuf is not None:
ctex.set_from_pixbuf(pixbuf)
# Set some dimensions
if x_off is not 0:
ctex.set_x(x_off)
if y_off is not 0:
ctex.set_y(y_off)
ctex.set_width(width)
ctex.set_height(height)
return ctex
def swipe(parent, old_widget, new_widget, right=True, time_ms=400):
# Allocation of the old widget.
# This is also used to determine the size of the new_widget
alloc = old_widget.get_allocation()
width, height = alloc.width, alloc.height
# Get the Imagedate of the old widget
old_pixbuf = Gdk.pixbuf_get_from_window(
old_widget.get_window(), 0, 0, width, height
)
# Render the new image (which is not displayed yet)
new_pixbuf = _render_pixbuf(
new_widget, width, height
)
# Toplevel container inside the stage
container = Clutter.Actor()
# Left-Side Image
container.add_child(_create_texture(
old_pixbuf, width, height, x_off=0)
)
# Right-Side Image
container.add_child(_create_texture(
new_pixbuf, width, height, x_off=-width if not right else +width)
)
# Shuffle widgets around
embed = GtkClutter.Embed()
embed.get_stage().add_child(container)
parent.remove(old_widget)
parent.add(embed)
parent.show_all()
# Actual animation:
transition = Clutter.PropertyTransition()
transition.set_property_name('x')
transition.set_duration(time_ms)
transition.set_from(0)
if right:
transition.set_to(-width)
else:
transition.set_to(+width)
# Now go back to normal and swap clutter with the new widget
def restore_widget(*args):
parent.remove(embed)
parent.add(new_widget)
parent.show_all()
# Be notified when animation ends
transition.connect('completed', restore_widget)
# Play the animation
container.add_transition('animate-x', transition)
# Initialization that has to been done always
GtkClutter.init(sys.argv)
if __name__ == '__main__':
class SwipeWin(Gtk.ApplicationWindow):
def __init__(self, app):
Gtk.ApplicationWindow.__init__(self, title='Swipe', application=app)
self.l_butt = Gtk.Button('<i><b>Go Right →</b></i>')
self.r_butt = Gtk.Button('<i><b>← Go Left</b></i>')
self.l_butt.get_child().set_use_markup(True)
self.r_butt.get_child().set_use_markup(True)
self.l_butt.connect('clicked', self.on_left_button_clicked)
self.r_butt.connect('clicked', self.on_right_button_clicked)
self.add(self.l_butt)
def on_left_button_clicked(self, button):
swipe(self, self.l_butt, self.r_butt, right=True, time_ms=200)
return True
def on_right_button_clicked(self, button):
swipe(self, self.r_butt, self.l_butt, right=False, time_ms=1000)
return True
class SwipeApp(Gtk.Application):
def __init__(self):
Gtk.Application.__init__(self)
def do_activate(self):
win = SwipeWin(self)
win.show_all()
def do_startup(self):
Gtk.Application.do_startup(self)
app = SwipeApp()
app.run(sys.argv)
$ pacman -Qs clutter
local/clutter 1.14.2-2
A GObject based library for creating fast, visually rich graphical user interfaces
local/clutter-gtk 1.4.4-1
GTK clutter widget
$ pacman -Qs gtk3
local/gtk3 3.8.1-1
GObject-based multi-platform GUI toolkit (v3)
$ pacman -Qs nvidia
local/nvidia 313.30-5
NVIDIA drivers for linux
@LutzLue
Copy link

LutzLue commented Oct 2, 2019

Hey man, did you resolve that issue? 💃

@sahib
Copy link
Author

sahib commented Oct 2, 2019

Hello @LutzLue, no I did not. This was more of a experiment anyways, just use a GtkStack for a stable implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment