<commit_before>from sugar.canvas.IconItem import IconItem
from sugar.canvas.Grid import Grid

class _MenuShell:
	def __init__(self):
		self._menu_controller = None

	def set_active(self, controller):
		if self._menu_controller:
			self._menu_controller.popdown()
		self._menu_controller = controller

class MenuIcon(IconItem):
	_menu_shell = _MenuShell()

	def __init__(self, grid, **kwargs):
		IconItem.__init__(self, **kwargs)

		self._grid = grid
		self._menu = None
		self._menu_distance = 0
		self._hover_menu = False
		self._popdown_on_leave = False

		self.connect('popup', self._popup_cb)
		self.connect('popdown', self._popdown_cb)

	def set_menu_distance(self, distance):
		self._menu_distance = distance

	def popdown(self):
		if self._menu:
			self._menu.destroy()
			self._menu = None

	def _popup_cb(self, icon, x1, y1, x2, y2):
		self.popdown()

		MenuIcon._menu_shell.set_active(None)

		grid = self._shell.get_grid()
		self._menu = self.create_menu()
		self._menu.connect('enter-notify-event',
						   self._menu_enter_notify_event_cb)
		self._menu.connect('leave-notify-event',
						   self._menu_leave_notify_event_cb)

		distance = self._menu_distance

		[grid_x1, grid_y1] = grid.convert_from_screen(x1, y1)
		[grid_x2, grid_y2] = grid.convert_from_screen(x2, y2)

		grid_x = grid_x2 + distance
		if grid_x + self._menu.get_width() > Grid.ROWS:
			grid_x = grid_x1 - self._menu.get_width() + 1 - distance

		grid_y = grid_y1

		if grid_y < 0:
			grid_y = 0
		if grid_y + self._menu.get_width() > Grid.ROWS:
			grid_y = Grid.ROWS - self._menu.get_width()

		grid.set_constraints(self._menu, grid_x, grid_y,
							 self._menu.get_width(), self._menu.get_height())

		self._menu.show()

		MenuIcon._menu_shell.set_active(self)

	def _popdown_cb(self, friend):
		if not self._hover_menu:
			self.popdown()
		else:
			self._popdown_on_leave = True

	def _menu_enter_notify_event_cb(self, widget, event):<commit_msg>s/rows/cols<commit_after>from sugar.canvas.IconItem import IconItem
from sugar.canvas.Grid import Grid

class _MenuShell:
	def __init__(self):
		self._menu_controller = None

	def set_active(self, controller):
		if self._menu_controller:
			self._menu_controller.popdown()
		self._menu_controller = controller

class MenuIcon(IconItem):
	_menu_shell = _MenuShell()

	def __init__(self, grid, **kwargs):
		IconItem.__init__(self, **kwargs)

		self._grid = grid
		self._menu = None
		self._menu_distance = 0
		self._hover_menu = False
		self._popdown_on_leave = False

		self.connect('popup', self._popup_cb)
		self.connect('popdown', self._popdown_cb)

	def set_menu_distance(self, distance):
		self._menu_distance = distance

	def popdown(self):
		if self._menu:
			self._menu.destroy()
			self._menu = None

	def _popup_cb(self, icon, x1, y1, x2, y2):
		self.popdown()

		MenuIcon._menu_shell.set_active(None)

		grid = self._shell.get_grid()
		self._menu = self.create_menu()
		self._menu.connect('enter-notify-event',
						   self._menu_enter_notify_event_cb)
		self._menu.connect('leave-notify-event',
						   self._menu_leave_notify_event_cb)

		distance = self._menu_distance

		[grid_x1, grid_y1] = grid.convert_from_screen(x1, y1)
		[grid_x2, grid_y2] = grid.convert_from_screen(x2, y2)

		grid_x = grid_x2 + distance
		if grid_x + self._menu.get_width() > Grid.COLS:
			grid_x = grid_x1 - self._menu.get_width() + 1 - distance

		grid_y = grid_y1

		if grid_y < 0:
			grid_y = 0
		if grid_y + self._menu.get_width() > Grid.ROWS:
			grid_y = Grid.ROWS - self._menu.get_width()

		grid.set_constraints(self._menu, grid_x, grid_y,
							 self._menu.get_width(), self._menu.get_height())

		self._menu.show()

		MenuIcon._menu_shell.set_active(self)

	def _popdown_cb(self, friend):
		if not self._hover_menu:
			self.popdown()
		else:
			self._popdown_on_leave = True

	def _menu_enter_notify_event_cb(self, widget, event):
{'fraction_non_alphanumeric': 0.11743404035178479, 'fraction_numerical': 0.00982928091050181, 'mean_word_length': 4.1083223249669745, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '3710206', 'n_tokens_mistral': 1589, 'n_tokens_neox': 1408, 'n_words': 263}