コード例 #1
0
	def switch_color(self) :
		self.color_switch = SwitchColorWindow(self)
コード例 #2
0
class ApplicationWindow(QtGui.QMainWindow):
	def __init__(self):
		QtGui.QMainWindow.__init__(self)
		self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
		self.setWindowTitle("Structure Viewer")

		self.data_manager = DataManager(self)

		self.color_switch = None
		self.lastopenfile = None

		self.initUI()
		self.main_widget.setFocus()
		self.setCentralWidget(self.main_widget)
		self.showMaximized()

		self.update_plot()

	def initUI(self) :
		self.main_widget = QtGui.QWidget(self)
		self.main_widget.move(10, 20)
		self.main_widget.resize(960, 730)
		self.layout = QtGui.QVBoxLayout(self.main_widget)
		self.initMenu()

		self.error_dialog_load = QtGui.QErrorMessage()

	def initMenu(self) :
		self.file_menu = QtGui.QMenu("&Options", self)
		self.file_menu.addAction("&Open file", self.open_file, QtCore.Qt.CTRL + QtCore.Qt.Key_O)
		self.file_menu.addAction("&Save fig", self.save_file, QtCore.Qt.CTRL + QtCore.Qt.Key_S)
		self.file_menu.addAction('&Graph settings', self.switch_color, QtCore.Qt.CTRL + QtCore.Qt.Key_G)

		self.action_border = QtGui.QAction("Border", self)
		self.action_labels = QtGui.QAction("Show all labels", self)

		self.action_border.changed.connect(self.update_plot)
		self.action_border.setCheckable(True)

		self.action_labels.changed.connect(self.update_plot)
		self.action_labels.setCheckable(True)

		self.file_menu.addAction(self.action_border)
		self.file_menu.addAction(self.action_labels)
		self.menuBar().addMenu(self.file_menu)

	def open_file(self) :
		if self.lastopenfile :
			fnames = QtGui.QFileDialog.getOpenFileNames(self, 'Open file', dirname(self.lastopenfile))
		else :
			fnames = QtGui.QFileDialog.getOpenFileNames(self, 'Open file')

		for fname in fnames :
			try :
				self.load_file(fname)
			except SVInternalException as error :
				self.error_dialog_load.showMessage(str(fname) + " : " + str(error))
				return

		self.lastopenfile = str(fname)
		self.update_plot()

	def load_file(self, fname) :
		self.data_manager.add_structure_fname(fname)

	def update_plot(self) :
		# Generate an error, I don't really know why
		border = self.is_border_checked()
		show_all_labels = self.is_all_labels_checked()
		self.canva = self.data_manager.get_canva(edge=border, show_all_labels=show_all_labels)
		if not self.canva : return
		for i in reversed(range(self.layout.count())):
				if isinstance(self.layout.itemAt(i), QtGui.QWidgetItem) :
					self.layout.itemAt(i).widget().setParent(None)

		self.canva.setParent(self.main_widget)
		self.canva.setFocus()
		self.layout.addWidget(self.canva)
		self.show()

	def is_border_checked(self) :
		return self.action_border.isChecked()

	def is_all_labels_checked(self) :
		return self.action_labels.isChecked()

	def popup(self, data, row, column) :
		self.menu = QtGui.QMenu(self)
		go_up_action = QtGui.QAction("Go up", self)
		go_up_action.triggered.connect(partial(self.change_row, data, column, 1))
		go_down_action = QtGui.QAction("Go down", self)
		go_down_action.triggered.connect(partial(self.change_row, data, column, -1))
		sort_action = QtGui.QAction("Sort", self)
		sort_action.triggered.connect(partial(self.sort_pop, data, column))
		self.menu.addAction(go_up_action)
		self.menu.addAction(go_down_action)
		self.menu.addAction(sort_action)
		self.menu.popup(QtGui.QCursor.pos())

	def switch_color(self) :
		self.color_switch = SwitchColorWindow(self)

	def sort_pop(self, data, column) :
		data.reorder_pop(column)
		self.data_manager.uniform_names(data)
		self.update_plot()

	def change_row(self, data, column, level) :
		if data.reorder_column(column, level) :
			self.update_plot()

	def save_file(self) :
		if self.lastopenfile :
			fname = QtGui.QFileDialog.getSaveFileName(self, 'Open file', dirname(self.lastopenfile))
		else :
			fname = QtGui.QFileDialog.getSaveFileName(self, 'Open file')

		self.data_manager.save(str(fname))

	def closeEvent(self, ce) :
		if self.color_switch :
			self.color_switch.terminate()
		self.close()