<commit_before># --------------------------------------------------------------------

import sys, os
import wx
import dmi
import Image

# --------------------------------------------------------------------

class IconView(wx.ListCtrl):
	def __init__(self, root):
		wx.ListCtrl.__init__(self, root, style = wx.LC_ICON | wx.LC_VIRTUAL | wx.LC_EDIT_LABELS)

		self.initAll()
		self.initBinds()

	def initAll(self):
		self.last_pos = -1
		self.icons = None
		self.images = None
		self.image_list = None

	def initBinds(self):
		self.Bind(wx.EVT_SIZE, self.OnSize)
		self.Bind(wx.EVT_LIST_END_LABEL_EDIT, self.OnIconStateEdit)
		self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnIconSelect)

	def OnGetItemText(self, index, col):
		try:
			return self.icons[index].state
		except IndexError:
			return 'IndexError'

	def OnGetItemImage(self, index):
		try:
			return self.images[index]
		except IndexError:
			return 'IndexError'

	def OnGetItemAttr(self, index):
		return None

	def OnSize(self, event):
		# List won't refresh itself
		event.Skip()
		last_pos = self.GetItemRect(self.GetItemCount() - 1)
		if self.last_pos != last_pos:
			self.last_pos = last_pos
			self.Refresh(False)

	def OnIconStateEdit(self, event):
		state, index = event.GetText(), event.GetIndex()

		self.icons[index].state = state
		self.RefreshItem(index)

	def OnIconSelect(self, event):
		index = event.GetIndex()

		self.GetParent().icon_preview.previewIcon(self.icons[index])

	def loadDMI(self, DMI):
		self.icons = dmi.DMIREAD(DMI)
		self.images = []<commit_msg>Icon states no longer change when the edit is cancelled.<commit_after># --------------------------------------------------------------------

import sys, os
import wx
import dmi
import Image

# --------------------------------------------------------------------

class IconView(wx.ListCtrl):
	def __init__(self, root):
		wx.ListCtrl.__init__(self, root, style = wx.LC_ICON | wx.LC_VIRTUAL | wx.LC_EDIT_LABELS)

		self.initAll()
		self.initBinds()

	def initAll(self):
		self.last_pos = -1
		self.icons = None
		self.images = None
		self.image_list = None

	def initBinds(self):
		self.Bind(wx.EVT_SIZE, self.OnSize)
		self.Bind(wx.EVT_LIST_END_LABEL_EDIT, self.OnIconStateEdit)
		self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnIconSelect)

	def OnGetItemText(self, index, col):
		try:
			return self.icons[index].state
		except IndexError:
			return 'IndexError'

	def OnGetItemImage(self, index):
		try:
			return self.images[index]
		except IndexError:
			return 'IndexError'

	def OnGetItemAttr(self, index):
		return None

	def OnSize(self, event):
		# List won't refresh itself
		event.Skip()
		last_pos = self.GetItemRect(self.GetItemCount() - 1)
		if self.last_pos != last_pos:
			self.last_pos = last_pos
			self.Refresh(False)

	def OnIconStateEdit(self, event):
		if event.IsEditCancelled():
			event.Veto()
			return

		state, index = event.GetText(), event.GetIndex()

		self.icons[index].state = state
		self.RefreshItem(index)
		self.OnIconSelect(event)

	def OnIconSelect(self, event):
		index = event.GetIndex()

		self.GetParent().icon_preview.previewIcon(self.icons[index])

	def loadDMI(self, DMI):
		self.icons = dmi.DMIREAD(DMI)
		self.images = []
{'fraction_non_alphanumeric': 0.19500780031201248, 'fraction_numerical': 0.0012480499219968799, 'mean_word_length': 2.8441247002398082, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4517704', 'n_tokens_mistral': 1190, 'n_tokens_neox': 1080, 'n_words': 226}