Beispiel #1
0
	def _update_peripherals(self):
		"""
		Update the peripheral viewers.
		"""
		# Get the periph list in another thread
		periph_ids = self.system.get_peripheral_ids()
		
		# Return to the GTK thread
		yield
		
		# A list of periph_id/periph_sub_id pairs in the same order as the list of
		# periph_viewers for lookups. Entries which have been updated are replaced
		# with None to flag them as being up-to-date.
		cur_periph_ids = [(p.periph_id, p.periph_sub_id) for p in self.periph_viewers]
		
		for periph_num, (periph_id, periph_sub_id) in enumerate(periph_ids):
			if (periph_id, periph_sub_id) in cur_periph_ids:
				# A viewer already been created for this widget, make sure its
				# peripheral number is up-to-date
				index = cur_periph_ids.index((periph_id, periph_sub_id))
				self.periph_viewers[index].architecture_changed(periph_num)
				
				# Widget has been updated
				cur_periph_ids[index] = None
			else:
				# No viewer exists, create one (if possible)
				name, PeripheralWidget = get_peripheral_view(periph_id, periph_sub_id)
				if PeripheralWidget is not None:
					self._init_periph(periph_num, periph_id, periph_sub_id,
					                  name, PeripheralWidget)
		
		# Remove any old peripherals which still remain
		for index, periph_ids in list(enumerate(cur_periph_ids))[::-1]:
			# If the periph_ids has not been cleared to None, it was not updated and
			# thus the corresponding widget should be destroyed.
			if periph_ids is not None:
				periph_viewer = self.periph_viewers.pop(index)
				self._destroy_periph(periph_viewer)
Beispiel #2
0
	def _add_periph_info_page(self):
		"""
		Adds a page to the notebook showing the peripherals in the system.
		"""
		# Request peripherals from the system
		periph_ids = self.system.get_peripheral_ids()
		
		# Display them in the GUI thread
		yield
		
		# Don't add if there aren't any peripherals
		if len(periph_ids) == 0:
			return
		
		# Table of (Name, Type, Subtype, Number, Supported)
		periph_list = gtk.ListStore(str, str, str, str, str)
		for periph_num, (periph_id, periph_sub_id) in enumerate(periph_ids):
			name, PeriphWidget = get_peripheral_view(periph_id, periph_sub_id)
			
			# Add the peripheral to the list
			periph_list.append((name or "Unknown",
			                    "%02X"%periph_id,
			                    "%04X"%periph_sub_id,
			                    str(periph_num),
			                    "No" if PeriphWidget is None else "Yes"))
		
		# Create the TreeView to display the table
		treeview = gtk.TreeView(periph_list)
		scroller = gtk.ScrolledWindow()
		scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
		scroller.add(treeview)
		cell_renderer = gtk.CellRendererText()
		
		# Add the tab and make sure its visible as this is happening late
		label = gtk.Label("Peripherals")
		self.notebook.append_page(scroller, label)
		self.show_all()
		
		column = gtk.TreeViewColumn("Number")
		column.pack_start(cell_renderer)
		column.add_attribute(cell_renderer, "text", 3)
		treeview.append_column(column)
		
		column = gtk.TreeViewColumn("Type")
		column.pack_start(cell_renderer)
		column.add_attribute(cell_renderer, "text", 0)
		treeview.append_column(column)
		
		column = gtk.TreeViewColumn("ID")
		column.pack_start(cell_renderer)
		column.add_attribute(cell_renderer, "text", 1)
		treeview.append_column(column)
		
		column = gtk.TreeViewColumn("Sub ID")
		column.pack_start(cell_renderer)
		column.add_attribute(cell_renderer, "text", 2)
		treeview.append_column(column)
		
		column = gtk.TreeViewColumn("Supported")
		column.pack_start(cell_renderer)
		column.add_attribute(cell_renderer, "text", 4)
		treeview.append_column(column)