示例#1
0
	def __init__(self):
		"""Constructor method."""
		self.__gobject_init__()

		self.contextMenu = gtk.Menu()

		if haveAppIndicator:
			iconPath = gtk.icon_theme_get_default().lookup_icon('program-icon', 16, 0).get_filename()
			self.icon = appindicator.Indicator('botmanager-indicator', iconPath, appindicator.CATEGORY_APPLICATION_STATUS)
			self.icon.set_status(appindicator.STATUS_ACTIVE)
			self.icon.set_menu(self.contextMenu)
		else:
			self.icon = gtk.StatusIcon()
			self.icon.set_from_icon_name('program-icon')
			self.icon.connect('activate', self.onSystrayClicked)
			self.icon.connect('popup-menu', self.onMenu)
			self.icon.set_visible(True)
			self.icon.set_blinking(False)
			self.icon.set_tooltip_text('Budabot Bot Manager')
			self.contextMenu.connect('enter-notify-event', self.onMouseEnterContextMenu)
			self.contextMenu.connect('leave-notify-event', self.onMouseLeaveContextMenu)
		
		# build context menu
		self.itemOpen = gtk.MenuItem('Open')
		self.itemOpen.set_visible(True)
		self.itemOpen.connect('activate', self.onOpenClicked)
		self.contextMenu.append(self.itemOpen)
		itemExit = gtk.MenuItem('Exit')
		itemExit.set_visible(True)
		itemExit.connect('activate', self.onExitClicked)
		self.contextMenu.append(itemExit)
		
		# set default action as bold
		setItemAsBold(self.itemOpen)
		
		self.closeTimerId = None
	def __init__(self, botModel, settingModel):
		"""Constructor method."""
		self.__gobject_init__()
		self.botModel = botModel
		self.settingModel = settingModel
		self.position = (200, 200)
		# load controlpanel.glade file
		self.builder = gtk.Builder()
		self.builder.add_from_file(resourcePath('controlpanel.glade'))
		
		self.view = self.builder.get_object('controlPanelWindow')
		self.botListView = self.builder.get_object('botListView')
		self.botListContextMenu = self.builder.get_object('botListContextMenu')
		self.contextItemOpen = self.builder.get_object('contextItemOpen')
		self.contextItemModify = self.builder.get_object('contextItemConfigure')
		self.contextItemRemove = self.builder.get_object('contextItemRemove')
		self.contextItemStart = self.builder.get_object('contextItemStart')
		self.contextItemRestart = self.builder.get_object('contextItemRestart')
		self.contextItemShutdown = self.builder.get_object('contextItemShutdown')
		self.contextItemTerminate = self.builder.get_object('contextItemTerminate')
		
		self.botListView.set_model(self.botModel)

		# setup column for bot's name
		def botNameSetter(column, cell, model, iter):
			bot = model[iter][BotModel.COLUMN_BOTOBJECT]
			name = bot.getName()
			cell.set_property('text', name)
		nameRenderer = gtk.CellRendererText()
		nameRenderer.set_property('height', 50)
		nameColumn = gtk.TreeViewColumn('Bot', nameRenderer)
		nameColumn.set_property('expand', True)
		nameColumn.set_cell_data_func(nameRenderer, botNameSetter)
		self.botListView.append_column(nameColumn)
		
		# setup column for bot's status
		def botStatusSetter(column, cell, model, iter):
			bot = model[iter][BotModel.COLUMN_BOTOBJECT]
			status = getBotUIStatus(bot)
			cell.set_property('icon-name', status[1])

		statusRenderer = gtk.CellRendererPixbuf()
		statusRenderer.set_property('width', 50)
		statusRenderer.set_property('stock-size', gtk.icon_size_from_name('status-icon-size'))
		statusColumn = gtk.TreeViewColumn('Status', statusRenderer)
		statusColumn.set_cell_data_func(statusRenderer, botStatusSetter)
		self.botListView.append_column(statusColumn)
		
		# set default action as bold
		setItemAsBold(self.contextItemOpen)

		self.view.connect('delete-event', self.onDeleteEvent)
		self.view.connect('show', self.onViewShown)
		self.view.connect('hide', self.onViewHidden)
		
		self.botListView.connect('button-press-event', self.onBotListViewMousePressed)
		self.botListView.connect('key-press-event', self.onBotListViewKeyPressed)
		
		self.botListView.connect('row-activated', self.onBotListViewRowActivated)
		
		self.contextItemOpen.connect('activate', self.onContextMenuItemClicked, 'open')
		self.contextItemModify.connect('activate', self.onContextMenuItemClicked, 'configure')
		self.contextItemRemove.connect('activate', self.onContextMenuItemClicked, 'remove')
		self.contextItemStart.connect('activate', self.onContextMenuItemClicked, 'start')
		self.contextItemRestart.connect('activate', self.onContextMenuItemClicked, 'restart')
		self.contextItemShutdown.connect('activate', self.onContextMenuItemClicked, 'shutdown')
		self.contextItemTerminate.connect('activate', self.onContextMenuItemClicked, 'terminate')
		
		self.builder.get_object('addBotButton').connect('clicked', self.onAddBotClicked)
		self.builder.get_object('exitButton').connect('clicked', self.onExitClicked)