Skip to content

Instantly share code, notes, and snippets.

@MatthieuDartiailh
Created December 13, 2016 17:36
Show Gist options
  • Save MatthieuDartiailh/e44b22316b582f3242f27b910a74be96 to your computer and use it in GitHub Desktop.
Save MatthieuDartiailh/e44b22316b582f3242f27b910a74be96 to your computer and use it in GitHub Desktop.
Demonstrate the SystemError bug appearing on Python 3 when an exception is cleared for unknown reasons
"""Gist demonstarting the SystemError bug on python 3
"""
#-------------------------------------------------------------------------------
# Imports:
#-------------------------------------------------------------------------------
from atom.api import List, observe
from enaml.widgets.api import RawWidget
from enaml.core.declarative import d_
from enaml.qt.QtGui import QListWidget, QListWidgetItem
from enaml.qt.QtCore import Qt
class QtListStrWidget(RawWidget):
""" A Qt4 implementation of an Enaml ProxyListStrView.
"""
__slots__ = '__weakref__'
#: The list of (str, enabled) tuples being viewed
items = d_(List() )
#--------------------------------------------------------------------------
# Initialization API
#--------------------------------------------------------------------------
def create_widget(self, parent):
"""
Create the QListWidget widget.
"""
# Create the list model and accompanying controls:
widget = QListWidget(parent)
for item, checked in self.items:
self.add_item(widget, item, checked)
return widget
def add_item(self, widget, item, checked=True):
itemWidget = QListWidgetItem(item)
widget.addItem(itemWidget)
#--------------------------------------------------------------------------
# Observers
#--------------------------------------------------------------------------
@observe('items')
def _update_items(self, change):
""" An observer which sends state change to the proxy. """
#this callback may be called before the widget is initialized
widget = self.get_widget()
if widget == None:
return
raise RuntimeError()
from enaml.widgets.api import Window, Container, PushButton
enamldef Main(Window): main:
attr items = []
Container:
QtListStrWidget:
items << main.items
PushButton:
text= 'Add'
clicked::
l = main.items[:]
l.append('e')
main.items = l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment