Skip to content

Instantly share code, notes, and snippets.

@jaap-karssenberg
Created May 9, 2019 18:27
Show Gist options
  • Save jaap-karssenberg/b508c2d747430ebe93bf379f7620b316 to your computer and use it in GitHub Desktop.
Save jaap-karssenberg/b508c2d747430ebe93bf379f7620b316 to your computer and use it in GitHub Desktop.
diff --git a/tests/widgets.py b/tests/widgets.py
index 36dffffd..6b88850e 100644
--- a/tests/widgets.py
+++ b/tests/widgets.py
@@ -12,11 +12,25 @@ from zim.newfs.mock import os_native_path
class TestFunctions(tests.TestCase):
- def runTest(self):
+ def testEncodeDecode(self):
self.assertEqual(encode_markup_text('<foo> &bar'), '&lt;foo&gt; &amp;bar')
self.assertEqual(decode_markup_text('&lt;foo&gt; &amp;bar'), '<foo> &bar')
self.assertEqual(decode_markup_text('&lt;foo&gt; <b>&amp;bar</b>'), '<foo> &bar')
+ # FIXME: Can't run this without pointer over Gtk window
+ #def testGtkMenuPopup(self):
+ # menu = Gtk.Menu()
+ # gtk_popup_at_pointer(menu)
+ # menu.destroy()
+
+ def testGtkMenuPopupBackward(self):
+ from zim.gui.widgets import _gtk_popup_at_pointer_backward, _ref_cache
+ menu = Gtk.Menu()
+ _gtk_popup_at_pointer_backward(menu, None, 3)
+ self.assertIn(id(menu), _ref_cache)
+ menu.destroy()
+ self.assertNotIn(id(menu), _ref_cache)
+
class TestInputEntry(tests.TestCase):
diff --git a/zim/gui/widgets.py b/zim/gui/widgets.py
index ca84c3e9..d15321a8 100644
--- a/zim/gui/widgets.py
+++ b/zim/gui/widgets.py
@@ -312,12 +312,22 @@ def gtk_notebook_get_active_page(nb):
def gtk_popup_at_pointer(menu, event=None, button=3):
- # Introduced in Gtk 3.22, so wrap our own to be compatible for 3.18 and up
+ '''Introduced in Gtk 3.22, so wrap our own to be compatible for 3.18 and up'''
if hasattr(menu, 'popup_at_pointer'):
menu.popup_at_pointer(event)
else:
- time = event.time if event else 0
- menu.popup(None, None, None, None, button, time)
+ _gtk_popup_at_pointer_backward(menu, event, button)
+
+
+_ref_cache = {}
+
+def _gtk_popup_at_pointer_backward(menu, event, button):
+ # Testing shows that Gtk 3.18 does not show the menu if we don't keep a
+ # ref (!?) - see issue #813
+ _ref_cache[id(menu)] = menu
+ menu.connect('destroy', lambda m: _ref_cache.pop(id(m)))
+ time = event.time if event else 0
+ menu.popup(None, None, None, None, button, time)
def rotate_pixbuf(pixbuf):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment