def buildValueDomainNodeMenu(self, diagram, node): """ Build and return a QMenu instance for value domain nodes. :type diagram: Diagram :type node: ValueDomainNode :rtype: QMenu """ menu = self.buildGenericNodeMenu(diagram, node) # CREATE A NEW MENU FOR DATATYPE SELECTION NOT TO OVERWRITE THE PRE-DEFINED ONE self.customMenu['datatype'] = QtWidgets.QMenu('Select type') self.customMenu['datatype'].setIcon(self.session.menu('datatype').icon()) # CREATE NEW CUSTOM ACTION SET FOR THE DATATYPES SUPPORTED BY THE CURRENT PROFILE self.customAction['datatype'] = [] for datatype in sorted(Datatype.forProfile(self.project.profile.type()), key=attrgetter('value')): action = QtWidgets.QAction(self.session) action.setCheckable(True) action.setData(datatype) action.setText(datatype.value) connect(action.triggered, self.session.doSetDatatype) self.customAction['datatype'].append(action) self.customMenu['datatype'].addAction(action) # INSERT THE CUSTOM MENU IN THE NODE CONTEXTUAL MENU menu.insertMenu(self.session.action('node_properties'), self.customMenu['datatype']) menu.insertSeparator(self.session.action('node_properties')) for action in self.customAction['datatype']: action.setChecked(node.datatype == action.data()) return menu
def base_except_hook(exc_type, exc_value, exc_traceback): """ Used to handle all uncaught exceptions. :type exc_type: class :type exc_value: Exception :type exc_traceback: Traceback """ if issubclass(exc_type, KeyboardInterrupt): app.quit() else: global msgbox if not msgbox: LOGGER.critical(format_exception(exc_value)) msgbox = QtWidgets.QMessageBox() msgbox.setIconPixmap(QtGui.QPixmap(':/images/eddy-sad')) msgbox.setWindowIcon(QtGui.QIcon(':/icons/128/ic_eddy')) msgbox.setWindowTitle('Fatal error!') msgbox.setText('This is embarrassing ...\n\n' \ 'A critical error has just occurred. {0} will continue to work, ' \ 'however a reboot is highly recommended.'.format(APPNAME)) msgbox.setInformativeText('If the problem persists you can ' '<a href="{0}">submit a bug report</a>.'.format(BUG_TRACKER)) msgbox.setDetailedText(format_exception(exc_value)) msgbox.setStandardButtons(QtWidgets.QMessageBox.Close | QtWidgets.QMessageBox.Ok) buttonOk = msgbox.button(QtWidgets.QMessageBox.Ok) buttonOk.setText('Close') buttonQuit = msgbox.button(QtWidgets.QMessageBox.Close) buttonQuit.setText('Quit {0}'.format(APPNAME)) connect(buttonOk.clicked, msgbox.close) connect(buttonQuit.clicked, app.quit) # noinspection PyArgumentList QtWidgets.QApplication.beep() msgbox.exec_() msgbox = None
def startThread(self, name, worker): """ Start a thread using the given worker. :type name: str :type worker: QtCore.QObject """ if not isinstance(worker, AbstractWorker): raise ValueError('worker class must be subclass of eddy.core.threading.AbstractWorker') if name not in self._threads and name not in self._workers: #LOGGER.debug("Requested threaded execution of worker instance: %s", worker.__class__.__name__) # START THE WORKER THREAD qthread = QtCore.QThread() qthread.setObjectName(name) #LOGGER.debug("Moving worker '%s' in a new thread '%s'", worker.__class__.__name__, name) worker.moveToThread(qthread) connect(qthread.finished, self.onQThreadFinished) connect(qthread.finished, qthread.deleteLater) connect(worker.finished, qthread.quit) connect(worker.finished, worker.deleteLater) connect(qthread.started, worker.run) #LOGGER.debug("Starting thread: %s", name) qthread.start() # STORE LOCALLY self._started[name] = time.monotonic() self._threads[name] = qthread self._workers[name] = worker
def buildPredicateNodeMenu(self, diagram, node): """ Build and return a QMenu instance for a predicate node (CONCEPT, ROLE, ATTRIBUTE). :type diagram: Diagram :type node: AbstractNode :rtype: QMenu """ menu = self.buildGenericNodeMenu(diagram, node) # BUILD CUSTOM ACTIONS FOR PREDICATE OCCURRENCES self.customAction['occurrences'] = [] for pnode in self.project.predicates(node.type(), node.text()): action = QtWidgets.QAction(self.session) action.setCheckable(True) action.setChecked(pnode is node) action.setData(pnode) action.setText('{} ({})'.format(pnode.diagram.name, pnode.id)) connect(action.triggered, self.session.doLookupOccurrence) self.customAction['occurrences'].append(action) # BUILD CUSTOM MENU FOR PREDICATE OCCURRENCES self.customMenu['occurrences'] = QtWidgets.QMenu('Occurrences') self.customMenu['occurrences'].setIcon(QtGui.QIcon(':/icons/24/ic_visibility_black')) for action in sorted(self.customAction['occurrences'], key=lambda x: x.text()): self.customMenu['occurrences'].addAction(action) menu.insertMenu(self.session.action('node_properties'), self.customMenu['occurrences']) return menu
def __init__(self, diagram, session): """ Initialize the view to browse the given diagram. :type diagram: Diagram :type session: Session """ super().__init__(diagram) self.mp_CenterPos = None self.mp_Pos = None self.mv_Timer = None self.rubberBandOrigin = None self.rubberBand = QtWidgets.QRubberBand(QtWidgets.QRubberBand.Rectangle, self) self.rubberBand.hide() self.pinchFactor = 1.0 self.session = session self.zoom = 1.0 self.setContextMenuPolicy(QtCore.Qt.PreventContextMenu) self.setDragMode(DiagramView.NoDrag) self.setGridSize(Diagram.GridSize) self.setOptimizationFlags(DiagramView.DontAdjustForAntialiasing) self.setOptimizationFlags(DiagramView.DontSavePainterState) self.setViewportUpdateMode(DiagramView.MinimalViewportUpdate) connect(diagram.sgnUpdated, self.doUpdateView)
def start(self): """ Perform initialization tasks for the plugin. """ # INITIALIZE THE WIDGET self.debug('Creating ontology explorer widget') widget = OntologyExplorerWidget(self) widget.setObjectName('ontology_explorer') self.addWidget(widget) # CREATE DOCKING AREA WIDGET self.debug('Creating docking area widget') widget = DockWidget('Ontology Explorer', QtGui.QIcon(':icons/18/ic_explore_black'), self.session) widget.setAllowedAreas(QtCore.Qt.LeftDockWidgetArea|QtCore.Qt.RightDockWidgetArea) widget.setObjectName('ontology_explorer_dock') widget.setWidget(self.widget('ontology_explorer')) self.addWidget(widget) # CREATE ENTRY IN VIEW MENU self.debug('Creating docking area widget toggle in "view" menu') menu = self.session.menu('view') menu.addAction(self.widget('ontology_explorer_dock').toggleViewAction()) # CONFIGURE SIGNALS self.debug('Configuring session specific signals') connect(self.session.sgnReady, self.onSessionReady) # INSTALL DOCKING AREA WIDGET self.debug('Installing docking area widget') self.session.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.widget('ontology_explorer_dock'))
def onSubWindowActivated(self, subwindow): """ Executed when the active subwindow changes. :type subwindow: MdiSubWindow """ if subwindow: if self.view: # If the Zoom control widgets are currently controlling a diagram view, # disconnect them from the old view before connecting them to the new one. self.debug('Disconnecting from diagram: %s', self.view.diagram.name) disconnect(self.sgnChanged, self.view.onZoomChanged) disconnect(self.view.sgnScaled, self.onScaleChanged) # Attach the new view to the Zoom controls. self.debug('Connecting to diagram: %s', subwindow.diagram.name) connect(self.sgnChanged, subwindow.view.onZoomChanged) connect(subwindow.view.sgnScaled, self.onScaleChanged) self.adjust(subwindow.view.zoom) self.setView(subwindow.view) else: if not self.session.mdi.subWindowList(): if self.view: # If the Zoom control widgets are currently controlling a diagram view, # disconnect them from the old view before connecting them to the new one. self.debug('Disconnecting from diagram: %s', self.view.diagram.name) disconnect(self.sgnChanged, self.view.onZoomChanged) disconnect(self.view.sgnScaled, self.onScaleChanged) self.setLevel(DiagramView.ZoomDefault) self.setView(None)
def start(self): """ Perform initialization tasks for the plugin. """ # INITIALIZE THE WIDGETS self.debug('Creating zoom control widgets') self.addWidget(QtWidgets.QToolButton( icon=QtGui.QIcon(':/icons/24/ic_zoom_in_black'), enabled=False, checkable=False, clicked=self.doZoomIn, objectName='button_zoom_in')) self.addWidget(QtWidgets.QToolButton( icon=QtGui.QIcon(':/icons/24/ic_zoom_out_black'), enabled=False, checkable=False, clicked=self.doZoomOut, objectName='button_zoom_out')) self.addWidget(QtWidgets.QToolButton( icon=QtGui.QIcon(':/icons/24/ic_zoom_reset_black'), enabled=False, checkable=False, clicked=self.doZoomReset, objectName='button_zoom_reset')) # CONFIGURE SIGNALS/SLOTS self.debug('Configuring session and MDI area specific signals/slots') connect(self.session.mdi.subWindowActivated, self.onSubWindowActivated) connect(self.session.sgnUpdateState, self.doUpdateState) # CREATE VIEW TOOLBAR BUTTONS self.debug('Installing zoom controls in "view" toolbar') self.afwset.add(self.session.widget('view_toolbar').addSeparator()) self.afwset.add(self.session.widget('view_toolbar').addWidget(self.widget('button_zoom_out'))) self.afwset.add(self.session.widget('view_toolbar').addWidget(self.widget('button_zoom_in'))) self.afwset.add(self.session.widget('view_toolbar').addWidget(self.widget('button_zoom_reset')))
def __init__(self, title, icon, parent=None): """ Initialize the widget. :type title: str :type icon: QIcon :type parent: QDockWidget """ super().__init__(parent) # CREATE TITLEBAR ICON AND TITLE self.imageLabel = QtWidgets.QLabel(self) self.imageLabel.setPixmap(icon.pixmap(18)) self.imageLabel.setAlignment(QtCore.Qt.AlignLeft|QtCore.Qt.AlignVCenter) self.imageLabel.setContentsMargins(0, 0, 0, 0) self.imageLabel.setFixedSize(18, 18) self.titleLabel = QtWidgets.QLabel(title, self) self.titleLabel.setAlignment(QtCore.Qt.AlignLeft|QtCore.Qt.AlignVCenter) self.titleLabel.setContentsMargins(4, 0, 0, 0) self.titleLabel.setFont(Font('Roboto', 13)) # CREATE STANDARD BUTTONS close = QtWidgets.QPushButton(self) close.setIcon(QtGui.QIcon(':/icons/18/ic_close_black')) close.setFixedSize(18, 18) connect(close.clicked, parent.close) self.buttons = [close] # CONFIGURE LAYOUT self.mainLayout = QtWidgets.QHBoxLayout(self) self.mainLayout.setContentsMargins(0, 0, 0, 0) self.mainLayout.setSpacing(0) self.setContentsMargins(6, 4, 6, 4) self.setContextMenuPolicy(QtCore.Qt.PreventContextMenu) self.setFont(Font('Roboto', 13)) self.updateLayout()
def start(self): """ Perform initialization tasks for the plugin. """ # INITIALIZE THE WIDGET self.debug('Creating overview widget') widget = OverviewWidget(self) widget.setObjectName('overview') self.addWidget(widget) # CREATE DOCKING AREA WIDGET self.debug('Creating docking area widget') widget = DockWidget('Overview', QtGui.QIcon(':/icons/18/ic_zoom_black'), self.session) widget.installEventFilter(self) widget.setAllowedAreas(QtCore.Qt.LeftDockWidgetArea | QtCore.Qt.RightDockWidgetArea) widget.setObjectName('overview_dock') widget.setWidget(self.widget('overview')) self.addWidget(widget) # CREATE ENTRY IN VIEW MENU self.debug('Creating docking area widget toggle in "view" menu') menu = self.session.menu('view') menu.addAction(self.widget('overview_dock').toggleViewAction()) # CONFIGURE SIGNALS/SLOTS self.debug('Connecting to active session') connect(self.session.mdi.subWindowActivated, self.onSubWindowActivated) # CREATE DOCKING AREA WIDGET self.debug('Installing docking area widget') self.session.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.widget('overview_dock'))
def __init__(self, plugin): """ Initialize the ontology explorer widget. :type plugin: Session """ super().__init__(plugin.session) self.plugin = plugin self.iconAttribute = QtGui.QIcon(':/icons/18/ic_treeview_attribute') self.iconConcept = QtGui.QIcon(':/icons/18/ic_treeview_concept') self.iconInstance = QtGui.QIcon(':/icons/18/ic_treeview_instance') self.iconRole = QtGui.QIcon(':/icons/18/ic_treeview_role') self.iconValue = QtGui.QIcon(':/icons/18/ic_treeview_value') self.search = StringField(self) self.search.setAcceptDrops(False) self.search.setClearButtonEnabled(True) self.search.setPlaceholderText('Search...') self.search.setFixedHeight(30) self.model = QtGui.QStandardItemModel(self) self.proxy = QtCore.QSortFilterProxyModel(self) self.proxy.setDynamicSortFilter(False) self.proxy.setFilterCaseSensitivity(QtCore.Qt.CaseInsensitive) self.proxy.setSortCaseSensitivity(QtCore.Qt.CaseSensitive) self.proxy.setSourceModel(self.model) self.ontoview = OntologyExplorerView(self) self.ontoview.setModel(self.proxy) self.mainLayout = QtWidgets.QVBoxLayout(self) self.mainLayout.setContentsMargins(0, 0, 0, 0) self.mainLayout.addWidget(self.search) self.mainLayout.addWidget(self.ontoview) self.setContentsMargins(0, 0, 0, 0) self.setMinimumWidth(216) self.setStyleSheet(""" QLineEdit, QLineEdit:editable, QLineEdit:hover, QLineEdit:pressed, QLineEdit:focus { border: none; border-radius: 0; background: #FFFFFF; color: #000000; padding: 4px 4px 4px 4px; } """) header = self.ontoview.header() header.setStretchLastSection(False) header.setSectionResizeMode(QtWidgets.QHeaderView.ResizeToContents) connect(self.ontoview.doubleClicked, self.onItemDoubleClicked) connect(self.ontoview.pressed, self.onItemPressed) connect(self.search.textChanged, self.doFilterItem) connect(self.sgnItemDoubleClicked, self.session.doFocusItem) connect(self.sgnItemRightClicked, self.session.doFocusItem)
def onDiagramAdded(self, diagram): """ Executed when a diagram is added to the project. :typw diagram: Diagram """ self.debug('Connecting to diagram: %s', diagram.name) connect(diagram.sgnItemInsertionCompleted, self.onDiagramItemInsertionCompleted) connect(diagram.sgnModeChanged, self.onDiagramModeChanged)
def __init__(self, *args, **kwargs): """ Initialize the timer. """ self._remaining = 0 self._paused = False super().__init__(*args, **kwargs) connect(self.timeout, self.onTimeout)
def onSessionReady(self): """ Executed whenever the main session completes the startup sequence. """ widget = self.widget('project_explorer') self.debug('Connecting to project: %s', self.project.name) connect(self.project.sgnDiagramAdded, widget.doAddDiagram) connect(self.project.sgnDiagramRemoved, widget.doRemoveDiagram) widget.setProject(self.project)
def __init__(self, plugin): """ Initialize the palette widget. :type plugin: Palette """ super().__init__(plugin.parent()) self.columns = -1 self.buttons = {} self.display = {} self.plugin = plugin self.items = [ Item.ConceptNode, Item.RoleNode, Item.AttributeNode, Item.ValueDomainNode, Item.IndividualNode, Item.FacetNode, Item.DomainRestrictionNode, Item.RangeRestrictionNode, Item.IntersectionNode, Item.RoleChainNode, Item.DatatypeRestrictionNode, Item.RoleInverseNode, Item.ComplementNode, Item.EnumerationNode, Item.UnionNode, Item.DisjointUnionNode, Item.PropertyAssertionNode, Item.InclusionEdge, Item.EquivalenceEdge, Item.InputEdge, Item.MembershipEdge, ] # CREATE BUTTONS for item in self.items: button = PaletteButton(item) button.installEventFilter(self) connect(button.clicked, self.onButtonClicked) self.addButton(item, button) # LOAD BUTTONS DISPLAY SETTINGS settings = QtCore.QSettings(ORGANIZATION, APPNAME) for item in self.items: self.display[item] = settings.value('plugins/palette/{0}'.format(item.name), True, bool) # SETUP LAYOUT self.mainLayout = QtWidgets.QGridLayout(self) self.mainLayout.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignTop) self.mainLayout.setContentsMargins(0, 6, 0, 6) self.mainLayout.setSpacing(0) self.setContentsMargins(0, 0, 0, 0) self.setMinimumWidth(216) self.setStyleSheet(""" QDockWidget PaletteWidget { background: #F0F0F0; }""")
def __init__(self, parent=None): """ Initialize the form dialog. :type parent: QtWidgets.QWidget """ super().__init__(parent) ############################################# # FORM AREA ################################# self.minLabel = QtWidgets.QLabel(self) self.minLabel.setFont(Font('Roboto', 12)) self.minLabel.setText('Min. cardinality') self.minField = IntegerField(self) self.minField.setFont(Font('Roboto', 12)) self.minField.setFixedWidth(80) self.maxLabel = QtWidgets.QLabel(self) self.maxLabel.setFont(Font('Roboto', 12)) self.maxLabel.setText('Max. cardinality') self.maxField = IntegerField(self) self.maxField.setFont(Font('Roboto', 12)) self.maxField.setFixedWidth(80) self.formWidget = QtWidgets.QWidget(self) self.formLayout = QtWidgets.QFormLayout(self.formWidget) self.formLayout.addRow(self.minLabel, self.minField) self.formLayout.addRow(self.maxLabel, self.maxField) ############################################# # CONFIRMATION AREA ################################# self.confirmationBox = QtWidgets.QDialogButtonBox(QtCore.Qt.Horizontal, self) self.confirmationBox.addButton(QtWidgets.QDialogButtonBox.Ok) self.confirmationBox.addButton(QtWidgets.QDialogButtonBox.Cancel) self.confirmationBox.setContentsMargins(10, 0, 10, 10) self.confirmationBox.setFont(Font('Roboto', 12)) ############################################# # SETUP DIALOG LAYOUT ################################# self.mainLayout = QtWidgets.QVBoxLayout(self) self.mainLayout.setContentsMargins(0, 0, 0, 0) self.mainLayout.addWidget(self.formWidget) self.mainLayout.addWidget(self.confirmationBox, 0, QtCore.Qt.AlignRight) self.setFixedSize(self.sizeHint()) self.setWindowIcon(QtGui.QIcon(':/icons/128/ic_eddy')) self.setWindowTitle('Insert cardinality') connect(self.confirmationBox.accepted, self.accept) connect(self.confirmationBox.rejected, self.reject)
def onSessionReady(self): """ Executed whenever the main session completes the startup sequence. """ self.debug('Connecting to project: %s', self.project.name) connect(self.project.sgnDiagramAdded, self.onDiagramAdded) connect(self.project.sgnDiagramRemoved, self.onDiagramRemoved) connect(self.project.sgnUpdated, self.doActivatePalette) for diagram in self.project.diagrams(): self.debug('Connecting to diagram: %s', diagram.name) connect(diagram.sgnItemInsertionCompleted, self.onDiagramItemInsertionCompleted) connect(diagram.sgnModeChanged, self.onDiagramModeChanged)
def doWork(self): """ Perform on or more advancements step in the validation procedure. """ worker = OntologyConsistencyCheckWorker(self.status_bar, self.project, self.session) connect(worker.sgnBusy, self.displaybusydialog) connect(worker.sgnError, self.onErrorInExec) connect(worker.sgnAllOK, self.onPerfectOntology) connect(worker.sgnOntologyInconsistency, self.onOntologicalInconsistency) connect(worker.sgnUnsatisfiableEntities, self.onUnsatisfiableEntities) self.startThread('OntologyConsistencyCheck', worker)
def __init__(self, project, parent=None): """ Initialize the project block. :type project: str :type parent: QtWidgets.QWidget """ super().__init__(parent) self.nameLabel = QtWidgets.QLabel(os.path.basename(project), self) self.nameLabel.setContentsMargins(20, 0, 20, 0) self.nameLabel.setProperty('class', 'name') self.nameLabel.setFont(Font(bold=True)) self.pathLabel = QtWidgets.QLabel(compressPath(shortPath(project), 34), self) self.pathLabel.setContentsMargins(20, 0, 20, 0) self.pathLabel.setProperty('class', 'path') self.removeBtn = PHCQPushButton(self) self.removeBtn.setIcon(QtGui.QIcon(':icons/24/ic_close_black')) self.removeBtn.setToolTip('Remove Project') self.removeBtn.setVisible(False) connect(self.removeBtn.clicked, self.onRemoveButtonClicked) self.deleteBtn = PHCQPushButton(self) self.deleteBtn.setToolTip('Delete Project') self.deleteBtn.setIcon(QtGui.QIcon(':/icons/24/ic_delete_black')) self.deleteBtn.setVisible(False) connect(self.deleteBtn.clicked, self.onDeleteButtonClicked) self.leftWidget = QtWidgets.QWidget(self) self.leftWidget.setContentsMargins(0, 0, 0, 0) self.leftLayout = QtWidgets.QVBoxLayout(self.leftWidget) self.leftLayout.setContentsMargins(0, 0, 0, 0) self.leftLayout.setSpacing(0) self.leftLayout.addWidget(self.nameLabel) self.leftLayout.addWidget(self.pathLabel) self.rightWidget = QtWidgets.QWidget(self) self.rightWidget.setContentsMargins(0, 0, 10, 0) self.rightLayout = QtWidgets.QHBoxLayout(self.rightWidget) self.rightLayout.setContentsMargins(0, 0, 0, 0) self.rightLayout.setSpacing(0) self.rightLayout.addWidget(self.removeBtn) self.rightLayout.addWidget(self.deleteBtn) self.mainLayout = QtWidgets.QHBoxLayout(self) self.mainLayout.setContentsMargins(0, 0, 0, 0) self.mainLayout.addWidget(self.leftWidget) self.mainLayout.addWidget(self.rightWidget, 1, QtCore.Qt.AlignRight) self.installEventFilter(self) self.setContentsMargins(0, 0, 0, 0) self.setCursor(QtCore.Qt.PointingHandCursor) self.setFixedHeight(40) self.setFocusPolicy(QtCore.Qt.TabFocus) self.setToolTip(expandPath(project)) self.path = project
def __init__(self, diagram, node, session): """ Initialize the node properties dialog. :type diagram: Diagram :type node: AbstractNode :type session: Session """ super().__init__(diagram, node, session) ############################################# # ORDERING TAB ################################# if self.node.inputs: self.sortLabel = QtWidgets.QLabel(self) self.sortLabel.setFont(Font('Roboto', 12)) self.sortLabel.setText('Sort') self.list = QtWidgets.QListWidget(self) for i in self.node.inputs: edge = self.diagram.edge(i) item = QtWidgets.QListWidgetItem('{0} ({1})'.format(edge.source.text(), edge.source.id)) item.setData(QtCore.Qt.UserRole, edge.id) self.list.addItem(item) self.list.setCurrentRow(0) self.list.setDragDropMode(QtWidgets.QAbstractItemView.NoDragDrop) self.buttonUp = QtWidgets.QPushButton(self) self.buttonUp.setIcon(QtGui.QIcon(':/icons/24/ic_keyboard_arrow_up_black')) self.buttonUp.setFixedSize(20, 20) connect(self.buttonUp.clicked, self.moveUp) self.buttonDown = QtWidgets.QPushButton(self) self.buttonDown.setIcon(QtGui.QIcon(':/icons/24/ic_keyboard_arrow_down_black')) self.buttonDown.setFixedSize(20, 20) connect(self.buttonDown.clicked, self.moveDown) inLayout = QtWidgets.QVBoxLayout() inLayout.addWidget(self.buttonUp) inLayout.addWidget(self.buttonDown) outLayout = QtWidgets.QHBoxLayout() outLayout.addWidget(self.list) outLayout.addLayout(inLayout) self.orderWidget = QtWidgets.QWidget() self.orderLayout = QtWidgets.QFormLayout(self.orderWidget) self.orderLayout.addRow(self.sortLabel, outLayout) self.mainWidget.addTab(self.orderWidget, 'Ordering')
def __init__(self, session, **kwargs): """ Initialize the MDI area. :type session: Session """ super().__init__(session, **kwargs) self.setContentsMargins(0, 0, 0, 0) self.setViewMode(MdiArea.TabbedView) self.setTabPosition(QtWidgets.QTabWidget.North) self.setTabsClosable(True) self.setTabsMovable(True) self.tabBar.setExpanding(False) connect(self.subWindowActivated, self.onSubWindowActivated)
def onSessionReady(self): widget = self.widget('Prefix Explorer') connect(self.project.sgnIRIPrefixNodeDictionaryUpdated, widget.UpdateTableForIRI) connect(self.project.sgnIRIPrefixesEntryModified, widget.entry_MODIFY_ok) connect(self.project.sgnIRIPrefixEntryAdded, widget.entry_ADD_ok) connect(self.project.sgnIRIPrefixEntryRemoved, widget.entry_REMOVE_OK) connect(self.project.sgnIRIPrefixesEntryIgnored, widget.entry_NOT_OK) widget.run()
def onSessionReady(self): widget = self.widget('developers_iri') connect(self.project.sgnIRIPrefixNodeDictionaryUpdated, widget.FillTableWithIRIPrefixNodesDictionaryKeysAndValues) connect(self.project.sgnIRIPrefixesEntryModified, widget.entry_MODIFY_ok) connect(self.project.sgnIRIPrefixEntryAdded, widget.entry_ADD_ok) connect(self.project.sgnIRIPrefixEntryRemoved, widget.entry_REMOVE_OK) connect(self.project.sgnIRIPrefixesEntryIgnored, widget.entry_NOT_OK) widget.run()
def setProject(self, project): """ Set the project explorer to browse the given project. :type project: Project """ self.model.clear() self.model.appendRow(self.root) self.root.setText(project.name) connect(self.sgnFakeDiagramAdded, self.doAddDiagram) for diagram in project.diagrams(): self.sgnFakeDiagramAdded.emit(diagram) disconnect(self.sgnFakeDiagramAdded) sindex = self.root.index() pindex = self.proxy.mapFromSource(sindex) self.projectview.expand(pindex)
def __init__(self, session, iris): """ Initialize the Label dialog. :type session: Session :type explanations: list """ # super().__init__() super().__init__(session) self.iris = iris self.project = session.project ############################################# # EXPLANATIONS TAB ################################# labelWidget = LabelExplorerWidget(self.project, self.session, objectName='label_widget') self.addWidget(labelWidget) ############################################# # MAIN WIDGET ################################# ############################################# # CONFIRMATION BOX ################################# confirmation = QtWidgets.QDialogButtonBox(QtCore.Qt.Horizontal, self, objectName='confirmation_widget') doneBtn = QtWidgets.QPushButton('Done', objectName='done_button') confirmation.addButton(doneBtn, QtWidgets.QDialogButtonBox.AcceptRole) confirmation.setContentsMargins(10, 0, 10, 10) self.addWidget(confirmation) layout = QtWidgets.QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self.widget('label_widget')) layout.addWidget(self.widget('confirmation_widget'), 0, QtCore.Qt.AlignRight) self.setLayout(layout) self.setMinimumSize(800, 520) self.setWindowIcon(QtGui.QIcon(':/icons/128/ic_eddy')) title = 'IRIs with no matching labels' self.setWindowTitle(title) self.setWindowModality(QtCore.Qt.NonModal) self.redraw() connect(confirmation.accepted, self.accept)
def doCreateSessionFromScratch(self, projName, ontIri, ontPrefix): """ Create a session for a new brand project. """ for session in self.sessions: # Look among the active sessions and see if we already have # a session loaded for the given project: if so, focus it. if not session.project.path and session.project.name == projName and session.project.ontologyIRI == ontIri: session.show() break else: # If we do not have a session for the given project we'll create one. with BusyProgressDialog('Creating new project with name: {0}'.format(projName)): try: session = Session(self, path=None, projName=projName, ontIri=ontIri, ontPrefix=ontPrefix) except ProjectStopLoadingError: pass except Exception as e: LOGGER.warning('Failed to create session for new project : %s', e) msgbox = QtWidgets.QMessageBox() msgbox.setIconPixmap(QtGui.QIcon(':/icons/48/ic_error_outline_black').pixmap(48)) msgbox.setText('Failed to create session for new project') msgbox.setTextFormat(QtCore.Qt.RichText) msgbox.setDetailedText(format_exception(e)) msgbox.setStandardButtons(QtWidgets.QMessageBox.Close) msgbox.setWindowIcon(QtGui.QIcon(':/icons/128/ic_eddy')) msgbox.setWindowTitle('Project Error!') msgbox.exec_() else: ############################################# # CLOSE THE WELCOME SCREEN IF NECESSARY ################################# try: self.welcome.close() except (AttributeError, RuntimeError): pass ############################################# # STARTUP THE SESSION ################################# connect(session.sgnQuit, self.doQuit) connect(session.sgnClosed, self.onSessionClosed) self.sessions.append(session) self.sgnSessionCreated.emit(session) session.show()
def doDeleteProject(self, path): """ Delete the given project. :type path: str """ msgbox = QtWidgets.QMessageBox(self) msgbox.setFont(Font('Roboto', 11)) msgbox.setIconPixmap(QtGui.QIcon(':/icons/48/ic_question_outline_black').pixmap(48)) msgbox.setInformativeText('<b>NOTE: This action is not reversible!</b>') msgbox.setStandardButtons(QtWidgets.QMessageBox.No | QtWidgets.QMessageBox.Yes) msgbox.setTextFormat(QtCore.Qt.RichText) msgbox.setWindowIcon(QtGui.QIcon(':/icons/128/ic_eddy')) msgbox.setWindowTitle('Remove project: {0}?'.format(os.path.basename(path))) msgbox.setText('Are you sure you want to remove project: <b>{0}</b>'.format(os.path.basename(path))) msgbox.exec_() if msgbox.result() == QtWidgets.QMessageBox.Yes: try: # REMOVE THE PROJECT FROM DISK rmdir(path) except Exception as e: msgbox = QtWidgets.QMessageBox(self) msgbox.setDetailedText(format_exception(e)) msgbox.setIconPixmap(QtGui.QIcon(':/icons/48/ic_error_outline_black').pixmap(48)) msgbox.setStandardButtons(QtWidgets.QMessageBox.Close) msgbox.setTextFormat(QtCore.Qt.RichText) msgbox.setText('Eddy could not remove the specified project: <b>{0}</b>!'.format(os.path.basename(path))) msgbox.setWindowIcon(QtGui.QIcon(':/icons/128/ic_eddy')) msgbox.setWindowTitle('ERROR!') msgbox.exec_() else: # UPDATE THE RECENT PROJECT LIST recentList = [] settings = QtCore.QSettings(ORGANIZATION, APPNAME) for path in map(expandPath, settings.value('project/recent')): if isdir(path): recentList.append(path) settings.setValue('project/recent', recentList) settings.sync() # CLEAR CURRENT LAYOUT for i in reversed(range(self.innerLayoutL.count())): item = self.innerLayoutL.itemAt(i) self.innerLayoutL.removeItem(item) # DISPOSE NEW PROJECT BLOCK for path in recentList: project = ProjectBlock(path, self.innerWidgetL) connect(project.sgnDeleteProject, self.doDeleteProject) connect(project.sgnOpenProject, self.doOpenRecentProject) self.innerLayoutL.addWidget(project, 0, QtCore.Qt.AlignTop)
def addSubWindow(self, subwindow, flags=0, **kwargs): """ Add a subwindow to the MDI area. :type subwindow: MdiSubWindow :type flags: int """ menu = subwindow.systemMenu() action = QtWidgets.QAction('Close All', subwindow) action.setIcon(menu.actions()[7].icon()) connect(action.triggered, self.closeAllSubWindows) menu.addAction(action) action = QtWidgets.QAction('Close Others', subwindow) action.setIcon(menu.actions()[7].icon()) connect(action.triggered, self.doCloseOtherSubWindows) menu.addAction(action) return super().addSubWindow(subwindow)
def connectIRISignals(self, iri): """ :type iri: IRI """ connect(iri.sgnAnnotationAdded, self.onIRIAnnotationAssertionAdded) connect(iri.sgnAnnotationRemoved, self.onIRIAnnotationAssertionRemoved) connect(iri.sgnAnnotationModified, self.onIRIAnnotationAssertionModified) connect(iri.sgnIRIModified, self.onIRIModified)
def addAColumnOfButtons(self, floor, ceiling): explanationButtonsColumnLayout = QtWidgets.QVBoxLayout() explanationButtonsColumnArea = QtWidgets.QWidget() for e in range(floor, ceiling + 1): widget = QtWidgets.QPushButton(objectName=str(e)) widget.setText('Explanation ' + str(e)) widget.setFont(Font('Roboto', 12)) connect(widget.clicked, self.set_explanation_to_display_in_widget, e) explanationButtonsColumnLayout.addWidget(widget) explanationButtonsColumnArea.setLayout(explanationButtonsColumnLayout) self.explanationButtonsLayout.addWidget(explanationButtonsColumnArea)
def __init__(self, parent=None): """ Initialize the dialog. :type parent: QWidget """ super().__init__(parent) stream = LOGGER.getDefaultStream() ############################################# # MESSAGE AREA ################################# self.messageArea = QtWidgets.QPlainTextEdit(self) self.messageArea.setAttribute(QtCore.Qt.WA_MacShowFocusRect, 0) self.messageArea.setContentsMargins(10, 0, 0, 0) self.messageArea.setFont(Font('Roboto Mono', 11)) self.messageArea.setLineWrapMode(QtWidgets.QPlainTextEdit.NoWrap) self.messageArea.setMinimumSize(800, 500) self.highlighter = LogHighlighter(self.messageArea.document()) self.messageArea.setPlainText(stream.getvalue()) self.messageArea.setReadOnly(True) ############################################# # CONFIRMATION AREA ################################# self.confirmationBox = QtWidgets.QDialogButtonBox( QtWidgets.QDialogButtonBox.Ok, QtCore.Qt.Horizontal, self) self.confirmationBox.setContentsMargins(10, 0, 0, 0) self.confirmationBox.setFont(Font('Roboto', 12)) ############################################# # SETUP DIALOG LAYOUT ################################# self.mainLayout = QtWidgets.QVBoxLayout(self) self.mainLayout.setContentsMargins(10, 10, 10, 10) self.mainLayout.addWidget(self.messageArea) self.mainLayout.addWidget(self.confirmationBox, 0, QtCore.Qt.AlignRight) connect(self.confirmationBox.accepted, self.accept) self.setWindowIcon(QtGui.QIcon(':/icons/128/ic_eddy')) self.setWindowTitle('Log')
def onSessionReady(self): """ Executed whenever the main session completes the startup sequence. """ # CONNECT TO PROJECT SPECIFIC SIGNALS widget = self.widget('ontology_explorer') self.debug('Connecting to project: %s', self.project.name) connect(self.project.sgnItemAdded, widget.doAddNode) connect(self.project.sgnItemRemoved, widget.doRemoveNode) connect(self.project.sgnMetaAdded, widget.onMetaUpdated) connect(self.project.sgnMetaRemoved, widget.onMetaUpdated) # FILL IN ONTOLOGY EXPLORER WITH DATA connect(self.sgnFakeItemAdded, widget.doAddNode) for node in self.project.nodes(): self.sgnFakeItemAdded.emit(node.diagram, node) widget.doFilterItem('') disconnect(self.sgnFakeItemAdded, widget.doAddNode)
def start(self): """ Perform initialization tasks for the plugin. """ # INITIALIZE THE WIDGETS self.debug('Creating zoom control widgets') self.addWidget( QtWidgets.QToolButton( icon=QtGui.QIcon(':/icons/24/ic_zoom_in_black'), enabled=False, checkable=False, clicked=self.doZoomIn, objectName='button_zoom_in')) self.addWidget( QtWidgets.QToolButton( icon=QtGui.QIcon(':/icons/24/ic_zoom_out_black'), enabled=False, checkable=False, clicked=self.doZoomOut, objectName='button_zoom_out')) self.addWidget( QtWidgets.QToolButton( icon=QtGui.QIcon(':/icons/24/ic_zoom_reset_black'), enabled=False, checkable=False, clicked=self.doZoomReset, objectName='button_zoom_reset')) # CONFIGURE SIGNALS/SLOTS self.debug('Configuring session and MDI area specific signals/slots') connect(self.session.mdi.subWindowActivated, self.onSubWindowActivated) connect(self.session.sgnUpdateState, self.doUpdateState) # CREATE VIEW TOOLBAR BUTTONS self.debug('Installing zoom controls in "view" toolbar') self.afwset.add(self.session.widget('view_toolbar').addSeparator()) self.afwset.add( self.session.widget('view_toolbar').addWidget( self.widget('button_zoom_out'))) self.afwset.add( self.session.widget('view_toolbar').addWidget( self.widget('button_zoom_in'))) self.afwset.add( self.session.widget('view_toolbar').addWidget( self.widget('button_zoom_reset')))
def append_row_and_column_to_table(self, iri, prefix, editable, brush, checkbox_value): item_iri = QtWidgets.QTableWidgetItem() item_iri.setText(iri) if editable is True: item_iri.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEditable) else: item_iri.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable) if brush is not None: item_iri.setBackground(brush) item_prefix = QtWidgets.QTableWidgetItem() item_prefix.setText(prefix) if editable is True: item_prefix.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEditable) else: item_prefix.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable) if brush is not None: item_prefix.setBackground(brush) if checkbox_value != 0: checkbox = QtWidgets.QRadioButton() if checkbox_value == 0: checkbox.setEnabled(False) elif checkbox_value == 1: connect(checkbox.toggled, self.set_project_IRI) elif checkbox_value == 2: checkbox.setChecked(True) connect(checkbox.toggled, self.set_project_IRI) else: pass checkbox.setObjectName(str(self.table.rowCount() - 1)) else: null_item = QtWidgets.QTableWidgetItem() null_item.setFlags(QtCore.Qt.NoItemFlags) self.table.setItem(self.table.rowCount() - 1, 0, item_iri) self.table.setItem(self.table.rowCount() - 1, 1, item_prefix) if checkbox_value != 0: self.table.setCellWidget(self.table.rowCount() - 1, 2, checkbox) else: self.table.setItem(self.table.rowCount() - 1, 2, null_item) self.table.setRowCount(self.table.rowCount() + 1)
def addSubWindow(self, subwindow, flags=0, **kwargs): """ Add a subwindow to the MDI area. :type subwindow: MdiSubWindow :type flags: int """ menu = subwindow.systemMenu() action = menu.actions()[7] # CLOSE ACTION action.setShortcut(QtGui.QKeySequence.Close) action = QtWidgets.QAction('Close All', subwindow) action.setIcon(self.style().standardIcon(QtWidgets.QStyle.SP_TitleBarCloseButton)) connect(action.triggered, self.closeAllSubWindows) menu.addAction(action) action = QtWidgets.QAction('Close Others', subwindow) action.setIcon(self.style().standardIcon(QtWidgets.QStyle.SP_TitleBarCloseButton)) connect(action.triggered, self.doCloseOtherSubWindows) menu.addAction(action) return super().addSubWindow(subwindow)
def __init__(self, session, num): """ Initialize the popup window. :type num: int """ super().__init__(session) self.num = num self.hideAnimation = QtCore.QPropertyAnimation(self, b'windowOpacity', self) self.hideAnimation.setDuration(400) self.hideAnimation.setStartValue(1.0) self.hideAnimation.setEndValue(0.0) self.showAnimation = QtCore.QPropertyAnimation(self, b'windowOpacity', self) self.showAnimation.setDuration(400) self.showAnimation.setStartValue(0.0) self.showAnimation.setEndValue(1.0) self.sleepTimer = PausableTimer() self.sleepTimer.setSingleShot(True) ############################################# # SETUP UI ################################# self.btnClose = QtWidgets.QPushButton(self) self.btnClose.setContentsMargins(0, 0, 0, 0) self.btnClose.setFont(Font('Roboto', 12)) self.btnClose.setIcon(QtGui.QIcon(':/icons/18/ic_close_black')) self.btnClose.setIconSize(QtCore.QSize(18, 18)) self.popupLabel = QtWidgets.QLabel(self) self.popupLabel.setAlignment(QtCore.Qt.AlignTop | QtCore.Qt.AlignLeft) self.popupLabel.setFixedSize(QtCore.QSize(216, 88)) self.popupLabel.setFont(Font('Roboto', 12)) self.popupLabel.setOpenExternalLinks(True) self.popupLabel.setTextFormat(QtCore.Qt.RichText) self.popupLabel.setTextInteractionFlags(QtCore.Qt.TextBrowserInteraction) self.popupLabel.setWordWrap(True) self.mainLayout = QtWidgets.QHBoxLayout(self) self.mainLayout.setContentsMargins(10, 10, 10, 10) self.mainLayout.addWidget(self.popupLabel, 1, QtCore.Qt.AlignTop | QtCore.Qt.AlignLeft) self.mainLayout.addWidget(self.btnClose, 0, QtCore.Qt.AlignTop | QtCore.Qt.AlignRight) self.setFixedSize(QtCore.QSize(260, 100)) self.setWindowOpacity(0) self.setWindowFlags(QtCore.Qt.SplashScreen | QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint) connect(self.btnClose.clicked, self.onButtonCloseClicked) connect(self.hideAnimation.finished, self.onHideAnimationFinished) connect(self.showAnimation.finished, self.onShowAnimationFinished) connect(self.sleepTimer.timeout, self.onSleepTimerTimeout)
def __init__(self, parent=None): """ Initialize the dialog. :type parent: QWidget """ super().__init__(parent) stream = LOGGER.getDefaultStream() ############################################# # MESSAGE AREA ################################# self.messageArea = QtWidgets.QPlainTextEdit(self) self.messageArea.setAttribute(QtCore.Qt.WA_MacShowFocusRect, 0) self.messageArea.setContentsMargins(10, 0, 0, 0) self.messageArea.setFont(Font('Roboto Mono', 11)) self.messageArea.setLineWrapMode(QtWidgets.QPlainTextEdit.NoWrap) self.messageArea.setMinimumSize(800, 500) self.highlighter = LogHighlighter(self.messageArea.document()) self.messageArea.setPlainText(stream.getvalue()) self.messageArea.setReadOnly(True) ############################################# # CONFIRMATION AREA ################################# self.confirmationBox = QtWidgets.QDialogButtonBox(QtWidgets.QDialogButtonBox.Ok, QtCore.Qt.Horizontal, self) self.confirmationBox.setContentsMargins(10, 0, 0, 0) self.confirmationBox.setFont(Font('Roboto', 12)) ############################################# # SETUP DIALOG LAYOUT ################################# self.mainLayout = QtWidgets.QVBoxLayout(self) self.mainLayout.setContentsMargins(10, 10, 10, 10) self.mainLayout.addWidget(self.messageArea) self.mainLayout.addWidget(self.confirmationBox, 0, QtCore.Qt.AlignRight) connect(self.confirmationBox.accepted, self.accept) self.setWindowIcon(QtGui.QIcon(':/icons/128/ic_eddy')) self.setWindowTitle('Log')
def __init__(self, session, **kwargs): """ Initialize the MDI area. :type session: Session """ super().__init__(session, **kwargs) self.setContentsMargins(0, 0, 0, 0) self.setViewMode(MdiArea.TabbedView) self.setTabPosition(QtWidgets.QTabWidget.North) self.setTabsClosable(True) self.setTabsMovable(True) for child in self.children(): if isinstance(child, QtWidgets.QTabBar): child.setExpanding(False) break connect(self.subWindowActivated, self.onSubWindowActivated)
def start(self): """ Perform initialization tasks for the plugin. """ # INITIALIZE THE WIDGET self.debug('Creating ontology explorer widget') widget = OntologyExplorerWidget(self) widget.setObjectName('ontology_explorer') self.addWidget(widget) # CREATE DOCKING AREA WIDGET self.debug('Creating docking area widget') widget = DockWidget('Ontology Explorer', QtGui.QIcon(':icons/18/ic_explore_black'), self.session) widget.addTitleBarButton(self.widget('explorer_toggle')) widget.installEventFilter(self) widget.setAllowedAreas(QtCore.Qt.LeftDockWidgetArea | QtCore.Qt.RightDockWidgetArea | QtCore.Qt.BottomDockWidgetArea) widget.setObjectName('ontology_explorer_dock') widget.setWidget(self.widget('ontology_explorer')) self.addWidget(widget) # CREATE SHORTCUTS action = widget.toggleViewAction() action.setParent(self.session) action.setShortcut(QtGui.QKeySequence('Alt+4')) # CREATE ENTRY IN VIEW MENU self.debug('Creating docking area widget toggle in "view" menu') menu = self.session.menu('view') menu.addAction( self.widget('ontology_explorer_dock').toggleViewAction()) # CONFIGURE SIGNALS self.debug('Configuring session specific signals') connect(self.session.sgnReady, self.onSessionReady) # INSTALL DOCKING AREA WIDGET self.debug('Installing docking area widget') self.session.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.widget('ontology_explorer_dock'))
def __init__(self, project, parent=None): """ Initialize the project block. :type project: str :type parent: QtWidgets.QWidget """ super().__init__(parent) self.nameLabel = QtWidgets.QLabel(os.path.basename(project), self) self.nameLabel.setContentsMargins(20, 0, 20, 0) self.nameLabel.setProperty('class', 'name') self.nameLabel.setFont(Font('Roboto', 12, bold=True)) self.pathLabel = QtWidgets.QLabel(compressPath(shortPath(project), 34), self) self.pathLabel.setContentsMargins(20, 0, 20, 0) self.pathLabel.setProperty('class', 'path') self.pathLabel.setFont(Font('Roboto', 12)) self.deleteBtn = PHCQPushButton(self) self.deleteBtn.setIcon(QtGui.QIcon(':/icons/24/ic_delete_black')) self.deleteBtn.setVisible( not isSubPath(expandPath('@examples/'), project)) connect(self.deleteBtn.clicked, self.onDeleteButtonClicked) self.leftWidget = QtWidgets.QWidget(self) self.leftWidget.setContentsMargins(0, 0, 0, 0) self.leftLayout = QtWidgets.QVBoxLayout(self.leftWidget) self.leftLayout.setContentsMargins(0, 0, 0, 0) self.leftLayout.setSpacing(0) self.leftLayout.addWidget(self.nameLabel) self.leftLayout.addWidget(self.pathLabel) self.rightWidget = QtWidgets.QWidget(self) self.rightWidget.setContentsMargins(0, 0, 10, 0) self.rightLayout = QtWidgets.QVBoxLayout(self.rightWidget) self.rightLayout.setContentsMargins(0, 0, 0, 0) self.rightLayout.setSpacing(0) self.rightLayout.addWidget(self.deleteBtn) self.mainLayout = QtWidgets.QHBoxLayout(self) self.mainLayout.setContentsMargins(0, 0, 0, 0) self.mainLayout.addWidget(self.leftWidget) self.mainLayout.addWidget(self.rightWidget, 1, QtCore.Qt.AlignRight) self.setContentsMargins(0, 0, 0, 0) self.setFixedHeight(40) self.path = project
def onSubWindowActivated(self, subwindow): """ Executed when the active subwindow changes. :type subwindow: MdiSubWindow """ if subwindow: # If we have an active subwindow, we change the overview # widget to browse the diagram within such subwindow. widget = self.widget('overview') if widget.view(): # If the overview widget is currently inspecting a # diagram, detach signals from the subwindow which # is going out of focus, before connecting new ones. self.debug('Disconnecting from diagram: %s', widget.diagram.name) disconnect(widget.diagram.selectionChanged, self.onDiagramSelectionChanged) disconnect(widget.diagram.sgnUpdated, self.onDiagramUpdated) # Attach the new view/diagram to the overview widget. self.debug('Connecting to diagram: %s', subwindow.diagram.name) connect(subwindow.diagram.selectionChanged, self.onDiagramSelectionChanged) connect(subwindow.diagram.sgnUpdated, self.onDiagramUpdated) widget.setScene(subwindow.diagram) widget.setView(subwindow.view) widget.redraw() else: if not self.session.mdi.subWindowList(): # If we don't have any active subwindow (which means that # they have been all closed and not just out of focus) we # detach the widget from the last inspected diagram. widget = self.widget('overview') if widget.view(): self.debug('Disconnecting from diagram: %s', widget.diagram.name) disconnect(widget.diagram.selectionChanged, self.onDiagramSelectionChanged) disconnect(widget.diagram.sgnUpdated, self.onDiagramUpdated) widget.setScene(None) widget.setView(None) widget.redraw()
def __init__(self, options, argv): """ Initialize Eddy. :type options: Namespace :type argv: list """ super().__init__(argv) self.server = None self.socket = QtNetwork.QLocalSocket() self.socket.connectToServer(APPID) self.running = self.socket.waitForConnected() self.sessions = DistinctList() self.welcome = None if not self.isRunning() or options.tests: self.server = QtNetwork.QLocalServer() self.server.listen(APPID) self.socket = None connect(self.sgnCreateSession, self.doCreateSession)
def __init__(self, session, parent=None): """ Initialize the base information box. :type session: Session :type parent: QtWidgets.QWidget """ super().__init__(parent) self.session = session self.isValidUri = False uriLabel = QtWidgets.QLabel(self, objectName='uri_label') uriLabel.setText('URI') self.uriField = StringField(self, objectName='uri_field') connect(self.uriField.textChanged, self.onUriFieldChanged) formlayout = QtWidgets.QFormLayout() formlayout.addRow(uriLabel, self.uriField) groupbox = QtWidgets.QGroupBox('Import from remote document', self) groupbox.setLayout(formlayout) outerFormLayout = QtWidgets.QFormLayout() outerFormLayout.addRow(groupbox) self.setLayout(outerFormLayout)
def start(self): """ Perform initialization tasks for the plugin. """ # INITIALIZE THE WIDGET self.debug('Creating overview widget') widget = OverviewWidget(self) widget.setObjectName('overview') self.addWidget(widget) # CREATE DOCKING AREA WIDGET self.debug('Creating docking area widget') widget = DockWidget('Overview', QtGui.QIcon(':/icons/18/ic_zoom_black'), self.session) widget.installEventFilter(self) widget.setAllowedAreas(QtCore.Qt.LeftDockWidgetArea | QtCore.Qt.RightDockWidgetArea | QtCore.Qt.BottomDockWidgetArea) widget.setObjectName('overview_dock') widget.setWidget(self.widget('overview')) self.addWidget(widget) # CREATE SHORTCUTS action = widget.toggleViewAction() action.setParent(self.session) action.setShortcut(QtGui.QKeySequence('Alt+3')) # CREATE ENTRY IN VIEW MENU self.debug('Creating docking area widget toggle in "view" menu') menu = self.session.menu('view') menu.addAction(self.widget('overview_dock').toggleViewAction()) # CONFIGURE SIGNALS/SLOTS self.debug('Connecting to active session') connect(self.session.mdi.subWindowActivated, self.onSubWindowActivated) # CREATE DOCKING AREA WIDGET self.debug('Installing docking area widget') self.session.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.widget('overview_dock'))
def onUnsatisfiableEntities(self): """ Executed when the consistency check detects unsatisfiable entities in the ontology. """ # CONNECT TO PROJECT SPECIFIC SIGNALS widget = self.widget('unsatisfiable_entity_explorer') connect(self.project.sgnItemAdded, widget.doAddNode) connect(self.project.sgnItemRemoved, widget.doRemoveNode) # FILL IN UNSATISFIABLE ENTITIES EXPLORER WITH DATA connect(self.sgnFakeItemAdded, widget.doAddNode) connect(self.sgnFakeExplanationAdded, widget.doAddExplanation) classes_only_unsatisfiable_nodes_in_diagram = \ self.get_list_of_nodes_in_diagram_from_OWL_terms(self.project.unsatisfiable_classes) attributes_only_unsatisfiable_nodes_in_diagram = \ self.get_list_of_nodes_in_diagram_from_OWL_terms(self.project.unsatisfiable_attributes) roles_only_unsatisfiable_nodes_in_diagram = \ self.get_list_of_nodes_in_diagram_from_OWL_terms(self.project.unsatisfiable_roles) for n in classes_only_unsatisfiable_nodes_in_diagram: self.project.nodes_of_unsatisfiable_entities.extend(n) for n in attributes_only_unsatisfiable_nodes_in_diagram: self.project.nodes_of_unsatisfiable_entities.extend(n) for n in roles_only_unsatisfiable_nodes_in_diagram: self.project.nodes_of_unsatisfiable_entities.extend(n) temp = [] for n in self.project.nodes_of_unsatisfiable_entities: owl_term = self.project.getOWLtermfornode(n) temp.append(owl_term) self.project.nodes_of_unsatisfiable_entities.extend(temp) self.add_unsatisfiable_nodes_in_widget( classes_only_unsatisfiable_nodes_in_diagram, 'unsatisfiable_classes') self.add_unsatisfiable_nodes_in_widget( attributes_only_unsatisfiable_nodes_in_diagram, 'unsatisfiable_attributes') self.add_unsatisfiable_nodes_in_widget( roles_only_unsatisfiable_nodes_in_diagram, 'unsatisfiable_roles') disconnect(self.sgnFakeItemAdded, widget.doAddNode) disconnect(self.sgnFakeExplanationAdded, widget.doAddExplanation) # SHOW THE PLUGIN DOCK WIDGET if not self.widget('unsatisfiable_entity_explorer_dock').isVisible(): self.widget('unsatisfiable_entity_explorer_dock').toggleViewAction( ).trigger() self.widget('unsatisfiable_entity_explorer_dock').raise_()
def startMove(self, delta, rate): """ Start the view movement. :type delta: QtCore.QPointF :type rate: float """ if self.mv_Timer: self.stopMove() # Move the view: this is needed before the timer so that if we keep # moving the mouse fast outside the viewport rectangle we still are able # to move the view; if we don't do this the timer may not have kicked in # and thus we remain with a non-moving view with a unfocused graphics item. self.moveBy(delta) # Setup a timer for future move, so the view keeps moving # also if we are not moving the mouse anymore but we are # holding the position outside the viewport rect. self.mv_Timer = QtCore.QTimer() connect(self.mv_Timer.timeout, self.moveBy, delta) self.mv_Timer.start(rate)
def mergeDiagrams(self): """ Perform the merge of the diagrams by importing all the diagrams in the 'other' project in the loaded one. """ for diagram in self.other.diagrams(): # We may be in the situation in which we are importing a diagram with name 'X' # even though we already have a diagram 'X' in our project. Because we do not # want to overwrite diagrams, we perform a rename of the diagram being imported, # to be sure to have a unique diagram name, in the current project namespace. occurrence = 1 name = diagram.name while self.project.diagram(diagram.name): diagram.name = '{0}_{1}'.format(name, occurrence) occurrence += 1 ## SWITCH SIGNAL SLOTS disconnect(diagram.sgnItemAdded, self.other.doAddItem) disconnect(diagram.sgnItemRemoved, self.other.doRemoveItem) connect(diagram.sgnItemAdded, self.project.doAddItem) connect(diagram.sgnItemRemoved, self.project.doRemoveItem) ## MERGE THE DIAGRAM IN THE CURRENT PROJECT self.commands.append(CommandDiagramAdd(diagram, self.project))
def start(self): """ Perform initialization tasks for the plugin. """ # INITIALIZE THE WIDGET self.debug('Creating project explorer widget') widget = ProjectExplorerWidget(self) widget.setObjectName('project_explorer') self.addWidget(widget) # CREATE DOCKING AREA WIDGET self.debug('Creating docking area widget') widget = DockWidget('Project Explorer', QtGui.QIcon(':icons/18/ic_storage_black'), self.session) widget.setAllowedAreas(QtCore.Qt.LeftDockWidgetArea | QtCore.Qt.RightDockWidgetArea | QtCore.Qt.BottomDockWidgetArea) widget.setObjectName('project_explorer_dock') widget.setWidget(self.widget('project_explorer')) self.addWidget(widget) # CREATE SHORTCUTS action = widget.toggleViewAction() action.setParent(self.session) action.setShortcut(QtGui.QKeySequence('Alt+5')) # CREATE ENTRY IN VIEW MENU self.debug('Creating docking area widget toggle in "view" menu') menu = self.session.menu('view') menu.addAction(self.widget('project_explorer_dock').toggleViewAction()) # CONFIGURE SIGNALS/SLOTS self.debug('Connecting to active session') connect(self.session.sgnReady, self.onSessionReady) # INSTALL DOCKING AREA WIDGET self.debug('Installing docking area widget') self.session.addDockWidget(QtCore.Qt.LeftDockWidgetArea, self.widget('project_explorer_dock'))
def __init__(self, name, parent): """ Initialize the diagram. :type name: str :type parent: Project """ super().__init__(parent) self.factory = ItemFactory(self) self.guid = GUID(self) self.mode = DiagramMode.Idle self.modeParam = Item.Undefined self.name = name self.pasteX = Clipboard.PasteOffsetX self.pasteY = Clipboard.PasteOffsetY self.mo_Node = None self.mp_Data = None self.mp_Edge = None self.mp_Label = None self.mp_LabelPos = None self.mp_Node = None self.mp_NodePos = None self.mp_Pos = None settings = QtCore.QSettings() self.setFont( Font(font=self.font(), pixelSize=settings.value('diagram/fontsize', self.font().pixelSize(), int))) connect(self.sgnItemAdded, self.onItemAdded) connect(self.sgnItemRemoved, self.onItemRemoved) connect(self.sgnNodeIdentification, self.doNodeIdentification)
def __init__(self, project, parent=None): """ Initialize the project block. :type project: str :type parent: QtWidgets.QWidget """ super().__init__(parent) self.nameLabel = QtWidgets.QLabel(os.path.basename(project), self) self.nameLabel.setContentsMargins(20, 0, 20, 0) self.nameLabel.setProperty('class', 'name') self.nameLabel.setFont(Font('Roboto', 12, bold=True)) self.pathLabel = QtWidgets.QLabel(compressPath(shortPath(project), 34), self) self.pathLabel.setContentsMargins(20, 0, 20, 0) self.pathLabel.setProperty('class', 'path') self.pathLabel.setFont(Font('Roboto', 12)) self.deleteBtn = PHCQPushButton(self) self.deleteBtn.setIcon(QtGui.QIcon(':/icons/24/ic_delete_black')) self.deleteBtn.setVisible(not isSubPath(expandPath('@examples/'), project)) connect(self.deleteBtn.clicked, self.onDeleteButtonClicked) self.leftWidget = QtWidgets.QWidget(self) self.leftWidget.setContentsMargins(0, 0, 0, 0) self.leftLayout = QtWidgets.QVBoxLayout(self.leftWidget) self.leftLayout.setContentsMargins(0, 0, 0, 0) self.leftLayout.setSpacing(0) self.leftLayout.addWidget(self.nameLabel) self.leftLayout.addWidget(self.pathLabel) self.rightWidget = QtWidgets.QWidget(self) self.rightWidget.setContentsMargins(0, 0, 10, 0) self.rightLayout = QtWidgets.QVBoxLayout(self.rightWidget) self.rightLayout.setContentsMargins(0, 0, 0, 0) self.rightLayout.setSpacing(0) self.rightLayout.addWidget(self.deleteBtn) self.mainLayout = QtWidgets.QHBoxLayout(self) self.mainLayout.setContentsMargins(0, 0, 0, 0) self.mainLayout.addWidget(self.leftWidget) self.mainLayout.addWidget(self.rightWidget, 1, QtCore.Qt.AlignRight) self.setContentsMargins(0, 0, 0, 0) self.setFixedHeight(40) self.path = project
def doUpdateRecentProjects(self): """ Update the list of recent projects. """ # UPDATE THE RECENT PROJECT LIST recentList = [] settings = QtCore.QSettings() for path in map(expandPath, settings.value('project/recent', None, str) or []): if fexists(path): recentList.append(path) settings.setValue('project/recent', recentList) settings.sync() # CLEAR CURRENT LAYOUT for i in reversed(range(self.innerLayoutL.count())): item = self.innerLayoutL.itemAt(i) self.innerLayoutL.removeItem(item) # DISPOSE NEW PROJECT BLOCK if recentList: self.placeholder.setVisible(False) for path in recentList: project = ProjectBlock(path, self.innerWidgetL) connect(project.sgnDeleteProject, self.doDeleteProject) connect(project.sgnOpenProject, self.doOpenProject) connect(project.sgnRemoveProject, self.doRemoveProject) self.innerLayoutL.addWidget(project, 0, QtCore.Qt.AlignTop) else: self.placeholder.setVisible(True)
def __init__(self, name, parent): """ Initialize the diagram. :type name: str :type parent: Project """ super().__init__(parent) self.factory = ItemFactory(self) self.guid = GUID(self) self.mode = DiagramMode.Idle self.modeParam = Item.Undefined self.name = name self.pasteX = Clipboard.PasteOffsetX self.pasteY = Clipboard.PasteOffsetY self.mo_Node = None self.mp_Data = None self.mp_Edge = None self.mp_Label = None self.mp_LabelPos = None self.mp_Node = None self.mp_NodePos = None self.mp_Pos = None connect(self.sgnItemAdded, self.onItemAdded) connect(self.sgnItemRemoved, self.onItemRemoved) connect(self.sgnNodeIdentification, self.doNodeIdentification)
def __init__(self, template='', movable=True, editable=True, parent=None): """ Initialize the label. :type template: str :type movable: bool :type editable: bool :type parent: QObject """ self._alignment = QtCore.Qt.AlignCenter self._editable = bool(editable) self._movable = bool(movable) super().__init__(parent) self.focusInData = None self.template = template self.setDefaultTextColor(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)).color()) self.setFlag(AbstractLabel.ItemIsFocusable, self.isEditable()) self.setFont(Font('Roboto', 12, Font.Light)) self.setText(self.template) self.setTextInteractionFlags(QtCore.Qt.NoTextInteraction) document = self.document() connect(document.contentsChange[int, int, int], self.onContentsChanged)
def __init__(self, node, session): """ Initialize the form dialog. :type node: AbstractNode :type session: Session """ super().__init__(session) self.node = node ############################################# # FORM AREA ################################# self.renameLabel = QtWidgets.QLabel(self) self.renameLabel.setFont(Font('Roboto', 12)) self.renameLabel.setText('Name') self.renameField = StringField(self) self.renameField.setFixedWidth(200) self.renameField.setFont(Font('Roboto', 12)) self.renameField.setValue(self.node.text()) connect(self.renameField.textChanged, self.nameChanged) self.formWidget = QtWidgets.QWidget(self) self.formLayout = QtWidgets.QFormLayout(self.formWidget) self.formLayout.addRow(self.renameLabel, self.renameField) ############################################# # CONFIRMATION AREA ################################# self.confirmationBox = QtWidgets.QDialogButtonBox(QtCore.Qt.Horizontal, self) self.confirmationBox.addButton(QtWidgets.QDialogButtonBox.Ok) self.confirmationBox.addButton(QtWidgets.QDialogButtonBox.Cancel) self.confirmationBox.setContentsMargins(10, 0, 10, 10) self.confirmationBox.setFont(Font('Roboto', 12)) ############################################# # SETUP DIALOG LAYOUT ################################# self.caption = QtWidgets.QLabel(self) self.caption.setFont(Font('Roboto', 12)) self.caption.setContentsMargins(8, 0, 8, 0) self.caption.setProperty('class', 'invalid') self.caption.setVisible(False) self.mainLayout = QtWidgets.QVBoxLayout(self) self.mainLayout.setContentsMargins(0, 0, 0, 0) self.mainLayout.addWidget(self.formWidget) self.mainLayout.addWidget(self.caption) self.mainLayout.addWidget(self.confirmationBox, 0, QtCore.Qt.AlignRight) self.setFixedSize(self.sizeHint()) self.setWindowIcon(QtGui.QIcon(':/icons/128/ic_eddy')) self.setWindowTitle('Rename') connect(self.confirmationBox.accepted, self.accept) connect(self.confirmationBox.rejected, self.reject)