示例#1
0
    def __init__(self, application, parent=None):
        """
        Initialize the workspace dialog.
        :type application: QApplication
        :type parent: QtWidgets.QWidget
        """
        super().__init__(parent)

        settings = QtCore.QSettings()

        self.pending = False
        self.workspace = settings.value('workspace/home', WORKSPACE, str)

        #############################################
        # LEFT AREA
        #################################

        self.innerWidgetL = QtWidgets.QWidget(self)
        self.innerWidgetL.setProperty('class', 'inner-left')
        self.innerWidgetL.setContentsMargins(0, 0, 0, 0)

        self.innerLayoutL = QtWidgets.QVBoxLayout(self.innerWidgetL)
        self.innerLayoutL.setContentsMargins(0, 0, 0, 0)
        self.innerLayoutL.setSpacing(0)

        #############################################
        # RIGHT AREA
        #################################

        self.actionBugTracker = QtWidgets.QAction('Report a bug', self)
        self.actionBugTracker.setData(BUG_TRACKER)
        connect(self.actionBugTracker.triggered, self.doOpenURL)
        self.actionGrapholWeb = QtWidgets.QAction('Visit Graphol website',
                                                  self)
        self.actionGrapholWeb.setData(GRAPHOL_HOME)
        connect(self.actionGrapholWeb.triggered, self.doOpenURL)
        self.actionProjectHome = QtWidgets.QAction('GitHub repository', self)
        self.actionProjectHome.setData(PROJECT_HOME)
        connect(self.actionProjectHome.triggered, self.doOpenURL)

        self.menuHelp = QtWidgets.QMenu(self)
        self.menuHelp.addAction(self.actionBugTracker)
        self.menuHelp.addAction(self.actionProjectHome)
        self.menuHelp.addAction(self.actionGrapholWeb)

        self.innerWidgetR = QtWidgets.QWidget(self)
        self.innerWidgetR.setProperty('class', 'inner-right')
        self.innerWidgetR.setContentsMargins(0, 30, 0, 0)

        self.appPix = QtWidgets.QLabel(self)
        self.appPix.setPixmap(QtGui.QIcon(':/icons/128/ic_eddy').pixmap(128))
        self.appPix.setContentsMargins(0, 0, 0, 0)
        self.appName = QtWidgets.QLabel(APPNAME, self)
        self.appName.setFont(Font(scale=2.5, capitalization=Font.SmallCaps))
        self.appName.setProperty('class', 'appname')
        self.appVersion = QtWidgets.QLabel('Version: {0}'.format(VERSION),
                                           self)
        self.appVersion.setFont(
            Font(scale=1.3333, capitalization=Font.SmallCaps))
        self.appVersion.setProperty('class', 'version')

        self.buttonNewProject = PHCQPushButton(self)
        self.buttonNewProject.setIcon(
            QtGui.QIcon(':/icons/24/ic_add_document_black'))
        self.buttonNewProject.setIconSize(QtCore.QSize(24, 24))
        self.buttonNewProject.setText('&Create new project')
        connect(self.buttonNewProject.clicked, self.doNewProject)
        self.buttonOpenProject = PHCQPushButton(self)
        self.buttonOpenProject.setIcon(
            QtGui.QIcon(':/icons/24/ic_folder_open_black'))
        self.buttonOpenProject.setIconSize(QtCore.QSize(24, 24))
        self.buttonOpenProject.setText('&Open project')
        connect(self.buttonOpenProject.clicked, self.doOpen)

        self.buttonHelp = PHCQToolButton(self)
        self.buttonHelp.setIcon(
            QtGui.QIcon(':/icons/24/ic_help_outline_black'))
        self.buttonHelp.setIconSize(QtCore.QSize(24, 24))
        self.buttonHelp.setText('&Help')
        self.buttonHelp.setMenu(self.menuHelp)
        self.buttonHelp.setPopupMode(PHCQToolButton.InstantPopup)
        self.buttonHelp.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)

        self.buttonLayoutRT = QtWidgets.QVBoxLayout()
        self.buttonLayoutRT.addWidget(self.buttonNewProject)
        self.buttonLayoutRT.addWidget(self.buttonOpenProject)
        self.buttonLayoutRT.setContentsMargins(0, 38, 0, 0)
        self.buttonLayoutRT.setAlignment(QtCore.Qt.AlignHCenter)
        self.buttonLayoutRB = QtWidgets.QHBoxLayout()
        self.buttonLayoutRB.addWidget(self.buttonHelp)
        self.buttonLayoutRB.setAlignment(QtCore.Qt.AlignBottom
                                         | QtCore.Qt.AlignRight)
        self.buttonLayoutRB.setContentsMargins(0, 30, 8, 0)

        self.innerLayoutR = QtWidgets.QVBoxLayout(self.innerWidgetR)
        self.innerLayoutR.setContentsMargins(0, 0, 0, 0)
        self.innerLayoutR.addWidget(self.appPix, 0, QtCore.Qt.AlignHCenter)
        self.innerLayoutR.addWidget(self.appName, 0, QtCore.Qt.AlignHCenter)
        self.innerLayoutR.addWidget(self.appVersion, 0, QtCore.Qt.AlignHCenter)
        self.innerLayoutR.addLayout(self.buttonLayoutRT)
        self.innerLayoutR.addLayout(self.buttonLayoutRB)

        #############################################
        # SETUP DIALOG LAYOUT
        #################################

        self.placeholder = QtWidgets.QLabel('No Recent Projects', self)
        self.placeholder.setEnabled(False)
        self.placeholder.setFixedSize(300, 400)
        self.placeholder.setFont(Font(scale=1.5))
        self.placeholder.setAlignment(QtCore.Qt.AlignCenter
                                      | QtCore.Qt.AlignHCenter)

        self.outerWidgetL = QtWidgets.QWidget(self)
        self.outerWidgetL.setProperty('class', 'outer-left')
        self.outerWidgetL.setContentsMargins(0, 0, 0, 0)
        self.outerWidgetL.setFixedWidth(300)
        self.outerLayoutL = QtWidgets.QVBoxLayout(self.outerWidgetL)
        self.outerLayoutL.setContentsMargins(0, 0, 0, 0)
        self.outerLayoutL.addWidget(self.placeholder, 1, QtCore.Qt.AlignTop)
        self.outerLayoutL.addWidget(self.innerWidgetL, 0, QtCore.Qt.AlignTop)

        self.outerWidgetR = QtWidgets.QWidget(self)
        self.outerWidgetR.setProperty('class', 'outer-right')
        self.outerWidgetR.setContentsMargins(0, 0, 0, 0)
        self.outerLayoutR = QtWidgets.QVBoxLayout(self.outerWidgetR)
        self.outerLayoutR.setContentsMargins(0, 0, 0, 0)
        self.outerLayoutR.addWidget(self.innerWidgetR, 0, QtCore.Qt.AlignTop)

        self.mainLayout = QtWidgets.QHBoxLayout(self)
        self.mainLayout.setContentsMargins(0, 0, 0, 0)
        self.mainLayout.addWidget(self.outerWidgetL)
        self.mainLayout.addWidget(self.outerWidgetR)

        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
        self.setFixedSize(720, 400)
        self.setWindowIcon(QtGui.QIcon(':/icons/128/ic_eddy'))
        self.setWindowTitle('Welcome to {0}'.format(APPNAME))

        connect(self.sgnCreateSession, application.doCreateSession)
        connect(self.sgnCreateSessionFromScratch,
                application.doCreateSessionFromScratch)

        connect(self.sgnOpenProject, self.doOpenProject)
        connect(self.sgnUpdateRecentProjects, self.doUpdateRecentProjects)

        desktop = QtWidgets.QDesktopWidget()
        screen = desktop.availableGeometry(self)
        widget = self.geometry()
        x = screen.x() + (screen.width() - widget.width()) / 2
        y = screen.y() + (screen.height() - widget.height()) / 2
        self.move(x, y)

        # UPDATE RECENT PROJECTS
        self.sgnUpdateRecentProjects.emit()
示例#2
0
    def __init__(self, application, parent=None):
        """
        Initialize the workspace dialog.
        :type application: QApplication
        :type parent: QtWidgets.QWidget
        """
        super().__init__(parent)

        settings = QtCore.QSettings(ORGANIZATION, APPNAME)

        self.workspace = settings.value('workspace/home', WORKSPACE, str)

        #############################################
        # LEFT AREA
        #################################

        self.innerWidgetL = QtWidgets.QWidget(self)
        self.innerWidgetL.setProperty('class', 'inner-left')
        self.innerWidgetL.setContentsMargins(0, 0, 0, 0)

        self.innerLayoutL = QtWidgets.QVBoxLayout(self.innerWidgetL)
        self.innerLayoutL.setContentsMargins(0, 0, 0, 0)
        self.innerLayoutL.setSpacing(0)

        for path in settings.value('project/recent', None, str) or []:
            project = ProjectBlock(path, self.innerWidgetL)
            connect(project.sgnDeleteProject, self.doDeleteProject)
            connect(project.sgnOpenProject, self.doOpenRecentProject)
            self.innerLayoutL.addWidget(project, 0, QtCore.Qt.AlignTop)

        #############################################
        # RIGHT AREA
        #################################

        self.actionBugTracker = QtWidgets.QAction('Report a bug', self)
        self.actionBugTracker.setData(BUG_TRACKER)
        connect(self.actionBugTracker.triggered, self.doOpenURL)
        self.actionGrapholWeb = QtWidgets.QAction('Visit Graphol website', self)
        self.actionGrapholWeb.setData(GRAPHOL_HOME)
        connect(self.actionGrapholWeb.triggered, self.doOpenURL)
        self.actionProjectHome = QtWidgets.QAction('GitHub repository', self)
        self.actionProjectHome.setData(PROJECT_HOME)
        connect(self.actionProjectHome.triggered, self.doOpenURL)

        self.menuHelp = QtWidgets.QMenu(self)
        self.menuHelp.addAction(self.actionBugTracker)
        self.menuHelp.addAction(self.actionProjectHome)
        self.menuHelp.addAction(self.actionGrapholWeb)

        self.innerWidgetR = QtWidgets.QWidget(self)
        self.innerWidgetR.setProperty('class', 'inner-right')
        self.innerWidgetR.setContentsMargins(0, 30, 0, 0)

        self.appPix = QtWidgets.QLabel(self)
        self.appPix.setPixmap(QtGui.QIcon(':/icons/128/ic_eddy').pixmap(128))
        self.appPix.setContentsMargins(0, 0, 0, 0)
        self.appName = QtWidgets.QLabel(APPNAME, self)
        self.appName.setFont(Font('Roboto', 30, capitalization=Font.SmallCaps))
        self.appName.setProperty('class', 'appname')
        self.appVersion = QtWidgets.QLabel('Version: {0}'.format(VERSION), self)
        self.appVersion.setFont(Font('Roboto', 16))
        self.appVersion.setProperty('class', 'version')

        self.buttonNewProject = PHCQPushButton(self)
        self.buttonNewProject.setFont(Font('Roboto', 13))
        self.buttonNewProject.setIcon(QtGui.QIcon(':/icons/24/ic_add_document_black'))
        self.buttonNewProject.setIconSize(QtCore.QSize(24, 24))
        self.buttonNewProject.setText('Create new project')
        connect(self.buttonNewProject.clicked, self.doNewProject)
        self.buttonOpenProject = PHCQPushButton(self)
        self.buttonOpenProject.setFont(Font('Roboto', 13))
        self.buttonOpenProject.setIcon(QtGui.QIcon(':/icons/24/ic_folder_open_black'))
        self.buttonOpenProject.setIconSize(QtCore.QSize(24, 24))
        self.buttonOpenProject.setText('Open project')
        connect(self.buttonOpenProject.clicked, self.doOpenProject)

        self.buttonHelp = PHCQToolButton(self)
        self.buttonHelp.setFont(Font('Roboto', 12))
        self.buttonHelp.setIcon(QtGui.QIcon(':/icons/24/ic_help_outline_black'))
        self.buttonHelp.setIconSize(QtCore.QSize(24, 24))
        self.buttonHelp.setText('Help')
        self.buttonHelp.setMenu(self.menuHelp)
        self.buttonHelp.setPopupMode(PHCQToolButton.InstantPopup)
        self.buttonHelp.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)

        self.buttonLayoutRT = QtWidgets.QVBoxLayout()
        self.buttonLayoutRT.addWidget(self.buttonNewProject)
        self.buttonLayoutRT.addWidget(self.buttonOpenProject)
        self.buttonLayoutRT.setContentsMargins(0, 38, 0, 0)
        self.buttonLayoutRT.setAlignment(QtCore.Qt.AlignHCenter)
        self.buttonLayoutRB = QtWidgets.QHBoxLayout()
        self.buttonLayoutRB.addWidget(self.buttonHelp)
        self.buttonLayoutRB.setAlignment(QtCore.Qt.AlignBottom|QtCore.Qt.AlignRight)
        self.buttonLayoutRB.setContentsMargins(0, 30, 8, 0)

        self.innerLayoutR = QtWidgets.QVBoxLayout(self.innerWidgetR)
        self.innerLayoutR.setContentsMargins(0, 0, 0, 0)
        self.innerLayoutR.addWidget(self.appPix, 0, QtCore.Qt.AlignHCenter)
        self.innerLayoutR.addWidget(self.appName, 0, QtCore.Qt.AlignHCenter)
        self.innerLayoutR.addWidget(self.appVersion, 0, QtCore.Qt.AlignHCenter)
        self.innerLayoutR.addLayout(self.buttonLayoutRT)
        self.innerLayoutR.addLayout(self.buttonLayoutRB)

        #############################################
        # SETUP DIALOG LAYOUT
        #################################

        self.outerWidgetL = QtWidgets.QWidget(self)
        self.outerWidgetL.setProperty('class', 'outer-left')
        self.outerWidgetL.setContentsMargins(0, 0, 0, 0)
        self.outerWidgetL.setFixedWidth(280)
        self.outerLayoutL = QtWidgets.QVBoxLayout(self.outerWidgetL)
        self.outerLayoutL.setContentsMargins(0, 0, 0, 0)
        self.outerLayoutL.addWidget(self.innerWidgetL, 0,  QtCore.Qt.AlignTop)

        self.outerWidgetR = QtWidgets.QWidget(self)
        self.outerWidgetR.setProperty('class', 'outer-right')
        self.outerWidgetR.setContentsMargins(0, 0, 0, 0)
        self.outerLayoutR = QtWidgets.QVBoxLayout(self.outerWidgetR)
        self.outerLayoutR.setContentsMargins(0, 0, 0, 0)
        self.outerLayoutR.addWidget(self.innerWidgetR, 0,  QtCore.Qt.AlignTop)

        self.mainLayout = QtWidgets.QHBoxLayout(self)
        self.mainLayout.setContentsMargins(0, 0, 0, 0)
        self.mainLayout.addWidget(self.outerWidgetL)
        self.mainLayout.addWidget(self.outerWidgetR)

        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
        self.setFixedSize(720, 400)
        self.setWindowIcon(QtGui.QIcon(':/icons/128/ic_eddy'))
        self.setWindowTitle('Welcome to {0}'.format(APPNAME))
        connect(self.sgnCreateSession, application.doCreateSession)

        desktop = QtWidgets.QDesktopWidget()
        screen = desktop.screenGeometry()
        widget = self.geometry()
        x = (screen.width() - widget.width()) / 2
        y = (screen.height() - widget.height()) / 2
        self.move(x, y)
示例#3
0
class Welcome(QtWidgets.QDialog):
    """
    This class is used to display the welcome screen of Eddy.
    """
    sgnCreateSession = QtCore.pyqtSignal(str)
    sgnOpenProject = QtCore.pyqtSignal(str)
    sgnCreateSessionFromScratch = QtCore.pyqtSignal(str, str, str)
    sgnUpdateRecentProjects = QtCore.pyqtSignal()

    def __init__(self, application, parent=None):
        """
        Initialize the workspace dialog.
        :type application: QApplication
        :type parent: QtWidgets.QWidget
        """
        super().__init__(parent)

        settings = QtCore.QSettings()

        self.pending = False
        self.workspace = settings.value('workspace/home', WORKSPACE, str)

        #############################################
        # LEFT AREA
        #################################

        self.innerWidgetL = QtWidgets.QWidget(self)
        self.innerWidgetL.setProperty('class', 'inner-left')
        self.innerWidgetL.setContentsMargins(0, 0, 0, 0)

        self.innerLayoutL = QtWidgets.QVBoxLayout(self.innerWidgetL)
        self.innerLayoutL.setContentsMargins(0, 0, 0, 0)
        self.innerLayoutL.setSpacing(0)

        #############################################
        # RIGHT AREA
        #################################

        self.actionBugTracker = QtWidgets.QAction('Report a bug', self)
        self.actionBugTracker.setData(BUG_TRACKER)
        connect(self.actionBugTracker.triggered, self.doOpenURL)
        self.actionGrapholWeb = QtWidgets.QAction('Visit Graphol website',
                                                  self)
        self.actionGrapholWeb.setData(GRAPHOL_HOME)
        connect(self.actionGrapholWeb.triggered, self.doOpenURL)
        self.actionProjectHome = QtWidgets.QAction('GitHub repository', self)
        self.actionProjectHome.setData(PROJECT_HOME)
        connect(self.actionProjectHome.triggered, self.doOpenURL)

        self.menuHelp = QtWidgets.QMenu(self)
        self.menuHelp.addAction(self.actionBugTracker)
        self.menuHelp.addAction(self.actionProjectHome)
        self.menuHelp.addAction(self.actionGrapholWeb)

        self.innerWidgetR = QtWidgets.QWidget(self)
        self.innerWidgetR.setProperty('class', 'inner-right')
        self.innerWidgetR.setContentsMargins(0, 30, 0, 0)

        self.appPix = QtWidgets.QLabel(self)
        self.appPix.setPixmap(QtGui.QIcon(':/icons/128/ic_eddy').pixmap(128))
        self.appPix.setContentsMargins(0, 0, 0, 0)
        self.appName = QtWidgets.QLabel(APPNAME, self)
        self.appName.setFont(Font(scale=2.5, capitalization=Font.SmallCaps))
        self.appName.setProperty('class', 'appname')
        self.appVersion = QtWidgets.QLabel('Version: {0}'.format(VERSION),
                                           self)
        self.appVersion.setFont(
            Font(scale=1.3333, capitalization=Font.SmallCaps))
        self.appVersion.setProperty('class', 'version')

        self.buttonNewProject = PHCQPushButton(self)
        self.buttonNewProject.setIcon(
            QtGui.QIcon(':/icons/24/ic_add_document_black'))
        self.buttonNewProject.setIconSize(QtCore.QSize(24, 24))
        self.buttonNewProject.setText('&Create new project')
        connect(self.buttonNewProject.clicked, self.doNewProject)
        self.buttonOpenProject = PHCQPushButton(self)
        self.buttonOpenProject.setIcon(
            QtGui.QIcon(':/icons/24/ic_folder_open_black'))
        self.buttonOpenProject.setIconSize(QtCore.QSize(24, 24))
        self.buttonOpenProject.setText('&Open project')
        connect(self.buttonOpenProject.clicked, self.doOpen)

        self.buttonHelp = PHCQToolButton(self)
        self.buttonHelp.setIcon(
            QtGui.QIcon(':/icons/24/ic_help_outline_black'))
        self.buttonHelp.setIconSize(QtCore.QSize(24, 24))
        self.buttonHelp.setText('&Help')
        self.buttonHelp.setMenu(self.menuHelp)
        self.buttonHelp.setPopupMode(PHCQToolButton.InstantPopup)
        self.buttonHelp.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)

        self.buttonLayoutRT = QtWidgets.QVBoxLayout()
        self.buttonLayoutRT.addWidget(self.buttonNewProject)
        self.buttonLayoutRT.addWidget(self.buttonOpenProject)
        self.buttonLayoutRT.setContentsMargins(0, 38, 0, 0)
        self.buttonLayoutRT.setAlignment(QtCore.Qt.AlignHCenter)
        self.buttonLayoutRB = QtWidgets.QHBoxLayout()
        self.buttonLayoutRB.addWidget(self.buttonHelp)
        self.buttonLayoutRB.setAlignment(QtCore.Qt.AlignBottom
                                         | QtCore.Qt.AlignRight)
        self.buttonLayoutRB.setContentsMargins(0, 30, 8, 0)

        self.innerLayoutR = QtWidgets.QVBoxLayout(self.innerWidgetR)
        self.innerLayoutR.setContentsMargins(0, 0, 0, 0)
        self.innerLayoutR.addWidget(self.appPix, 0, QtCore.Qt.AlignHCenter)
        self.innerLayoutR.addWidget(self.appName, 0, QtCore.Qt.AlignHCenter)
        self.innerLayoutR.addWidget(self.appVersion, 0, QtCore.Qt.AlignHCenter)
        self.innerLayoutR.addLayout(self.buttonLayoutRT)
        self.innerLayoutR.addLayout(self.buttonLayoutRB)

        #############################################
        # SETUP DIALOG LAYOUT
        #################################

        self.placeholder = QtWidgets.QLabel('No Recent Projects', self)
        self.placeholder.setEnabled(False)
        self.placeholder.setFixedSize(300, 400)
        self.placeholder.setFont(Font(scale=1.5))
        self.placeholder.setAlignment(QtCore.Qt.AlignCenter
                                      | QtCore.Qt.AlignHCenter)

        self.outerWidgetL = QtWidgets.QWidget(self)
        self.outerWidgetL.setProperty('class', 'outer-left')
        self.outerWidgetL.setContentsMargins(0, 0, 0, 0)
        self.outerWidgetL.setFixedWidth(300)
        self.outerLayoutL = QtWidgets.QVBoxLayout(self.outerWidgetL)
        self.outerLayoutL.setContentsMargins(0, 0, 0, 0)
        self.outerLayoutL.addWidget(self.placeholder, 1, QtCore.Qt.AlignTop)
        self.outerLayoutL.addWidget(self.innerWidgetL, 0, QtCore.Qt.AlignTop)

        self.outerWidgetR = QtWidgets.QWidget(self)
        self.outerWidgetR.setProperty('class', 'outer-right')
        self.outerWidgetR.setContentsMargins(0, 0, 0, 0)
        self.outerLayoutR = QtWidgets.QVBoxLayout(self.outerWidgetR)
        self.outerLayoutR.setContentsMargins(0, 0, 0, 0)
        self.outerLayoutR.addWidget(self.innerWidgetR, 0, QtCore.Qt.AlignTop)

        self.mainLayout = QtWidgets.QHBoxLayout(self)
        self.mainLayout.setContentsMargins(0, 0, 0, 0)
        self.mainLayout.addWidget(self.outerWidgetL)
        self.mainLayout.addWidget(self.outerWidgetR)

        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
        self.setFixedSize(720, 400)
        self.setWindowIcon(QtGui.QIcon(':/icons/128/ic_eddy'))
        self.setWindowTitle('Welcome to {0}'.format(APPNAME))

        connect(self.sgnCreateSession, application.doCreateSession)
        connect(self.sgnCreateSessionFromScratch,
                application.doCreateSessionFromScratch)

        connect(self.sgnOpenProject, self.doOpenProject)
        connect(self.sgnUpdateRecentProjects, self.doUpdateRecentProjects)

        desktop = QtWidgets.QDesktopWidget()
        screen = desktop.availableGeometry(self)
        widget = self.geometry()
        x = screen.x() + (screen.width() - widget.width()) / 2
        y = screen.y() + (screen.height() - widget.height()) / 2
        self.move(x, y)

        # UPDATE RECENT PROJECTS
        self.sgnUpdateRecentProjects.emit()

    #############################################
    #   EVENTS
    #################################

    def paintEvent(self, paintEvent):
        """
        This is needed for the widget to pick the stylesheet.
        :type paintEvent: QPaintEvent
        """
        option = QtWidgets.QStyleOption()
        option.initFrom(self)
        painter = QtGui.QPainter(self)
        style = self.style()
        style.drawPrimitive(QtWidgets.QStyle.PE_Widget, option, painter, self)

    #############################################
    #   SLOTS
    #################################

    @QtCore.pyqtSlot(str)
    def doDeleteProject(self, path):
        """
        Delete the given project.
        :type path: str
        """
        msgbox = QtWidgets.QMessageBox(self)
        msgbox.setIconPixmap(
            QtGui.QIcon(':/icons/48/ic_help_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.setWindowTitle('Remove project: {0}?'.format(path))
        #msgbox.setText('Are you sure you want to remove project: <b>{0}</b>'.format(os.path.basename(path)))
        msgbox.setText(
            'Are you sure you want to remove project: <b>{0}</b>'.format(path))
        msgbox.exec_()
        if msgbox.result() == QtWidgets.QMessageBox.Yes:
            try:
                # REMOVE THE PROJECT FROM DISK
                #rmdir(path)
                fremove(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(path))
                msgbox.setWindowIcon(QtGui.QIcon(':/icons/128/ic_eddy'))
                msgbox.setWindowTitle('ERROR!')
                msgbox.exec_()
            else:
                self.sgnUpdateRecentProjects.emit()

    @QtCore.pyqtSlot()
    def doNewProject(self):
        """
        Bring up a modal window used to create a new project.
        """
        form = NewProjectDialog(self)
        if form.exec_() == NewProjectDialog.Accepted:
            self.sgnCreateSessionFromScratch.emit(form.name(), form.iri(),
                                                  form.prefix())
            #self.sgnCreateSession.emit(expandPath(form.pathField.value()))

    @QtCore.pyqtSlot()
    def doOpen(self):
        """
        Bring up a modal window used to open a project.
        """
        '''
        dialog = QtWidgets.QFileDialog(self)
        dialog.setAcceptMode(QtWidgets.QFileDialog.AcceptOpen)
        dialog.setDirectory(expandPath(self.workspace))
        dialog.setFileMode(QtWidgets.QFileDialog.Directory)
        dialog.setOption(QtWidgets.QFileDialog.ShowDirsOnly, True)
        dialog.setViewMode(QtWidgets.QFileDialog.Detail)
        if dialog.exec_() == QtWidgets.QFileDialog.Accepted:
            self.sgnOpenProject.emit(first(dialog.selectedFiles()))
        '''
        dialog = QtWidgets.QFileDialog(self)
        dialog.setAcceptMode(QtWidgets.QFileDialog.AcceptOpen)
        dialog.setDirectory(expandPath('~'))
        dialog.setFileMode(QtWidgets.QFileDialog.ExistingFiles)
        dialog.setViewMode(QtWidgets.QFileDialog.Detail)
        dialog.setNameFilters([File.Graphol.value])
        if dialog.exec_() == QtWidgets.QFileDialog.Accepted:
            self.sgnOpenProject.emit(first(dialog.selectedFiles()))

    @QtCore.pyqtSlot(str)
    def doOpenProject(self, path):
        """
        Open a recent project in a new session of Eddy.
        :type path: str
        """
        if not self.pending:
            self.pending = True
            self.sgnCreateSession.emit(expandPath(path))
            self.pending = False

    @QtCore.pyqtSlot()
    def doOpenURL(self):
        """
        Open a URL using the operating system default browser.
        """
        action = self.sender()
        weburl = action.data()
        if weburl:
            # noinspection PyTypeChecker,PyCallByClass,PyCallByClass
            QtGui.QDesktopServices.openUrl(QtCore.QUrl(weburl))

    @QtCore.pyqtSlot(str)
    def doRemoveProject(self, path):
        """
        Remove the given project from the recent list.
        :type path: str
        """
        recentList = []
        path = expandPath(path)
        settings = QtCore.QSettings()
        for recent in map(expandPath,
                          settings.value('project/recent', None, str) or []):
            if recent != path:
                recentList.append(recent)
        settings.setValue('project/recent', recentList)
        settings.sync()
        self.sgnUpdateRecentProjects.emit()

    @QtCore.pyqtSlot()
    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)
示例#4
0
class Welcome(QtWidgets.QWidget):
    """
    This class is used to display the welcome screen of Eddy.
    """
    sgnCreateSession = QtCore.pyqtSignal(str)

    def __init__(self, application, parent=None):
        """
        Initialize the workspace dialog.
        :type application: QApplication
        :type parent: QtWidgets.QWidget
        """
        super().__init__(parent)

        settings = QtCore.QSettings(ORGANIZATION, APPNAME)

        self.workspace = settings.value('workspace/home', WORKSPACE, str)

        #############################################
        # LEFT AREA
        #################################

        self.innerWidgetL = QtWidgets.QWidget(self)
        self.innerWidgetL.setProperty('class', 'inner-left')
        self.innerWidgetL.setContentsMargins(0, 0, 0, 0)

        self.innerLayoutL = QtWidgets.QVBoxLayout(self.innerWidgetL)
        self.innerLayoutL.setContentsMargins(0, 0, 0, 0)
        self.innerLayoutL.setSpacing(0)

        for path in settings.value('project/recent', None, str) or []:
            project = ProjectBlock(path, self.innerWidgetL)
            connect(project.sgnDeleteProject, self.doDeleteProject)
            connect(project.sgnOpenProject, self.doOpenRecentProject)
            self.innerLayoutL.addWidget(project, 0, QtCore.Qt.AlignTop)

        #############################################
        # RIGHT AREA
        #################################

        self.actionBugTracker = QtWidgets.QAction('Report a bug', self)
        self.actionBugTracker.setData(BUG_TRACKER)
        connect(self.actionBugTracker.triggered, self.doOpenURL)
        self.actionGrapholWeb = QtWidgets.QAction('Visit Graphol website', self)
        self.actionGrapholWeb.setData(GRAPHOL_HOME)
        connect(self.actionGrapholWeb.triggered, self.doOpenURL)
        self.actionProjectHome = QtWidgets.QAction('GitHub repository', self)
        self.actionProjectHome.setData(PROJECT_HOME)
        connect(self.actionProjectHome.triggered, self.doOpenURL)

        self.menuHelp = QtWidgets.QMenu(self)
        self.menuHelp.addAction(self.actionBugTracker)
        self.menuHelp.addAction(self.actionProjectHome)
        self.menuHelp.addAction(self.actionGrapholWeb)

        self.innerWidgetR = QtWidgets.QWidget(self)
        self.innerWidgetR.setProperty('class', 'inner-right')
        self.innerWidgetR.setContentsMargins(0, 30, 0, 0)

        self.appPix = QtWidgets.QLabel(self)
        self.appPix.setPixmap(QtGui.QIcon(':/icons/128/ic_eddy').pixmap(128))
        self.appPix.setContentsMargins(0, 0, 0, 0)
        self.appName = QtWidgets.QLabel(APPNAME, self)
        self.appName.setFont(Font('Roboto', 30, capitalization=Font.SmallCaps))
        self.appName.setProperty('class', 'appname')
        self.appVersion = QtWidgets.QLabel('Version: {0}'.format(VERSION), self)
        self.appVersion.setFont(Font('Roboto', 16))
        self.appVersion.setProperty('class', 'version')

        self.buttonNewProject = PHCQPushButton(self)
        self.buttonNewProject.setFont(Font('Roboto', 13))
        self.buttonNewProject.setIcon(QtGui.QIcon(':/icons/24/ic_add_document_black'))
        self.buttonNewProject.setIconSize(QtCore.QSize(24, 24))
        self.buttonNewProject.setText('Create new project')
        connect(self.buttonNewProject.clicked, self.doNewProject)
        self.buttonOpenProject = PHCQPushButton(self)
        self.buttonOpenProject.setFont(Font('Roboto', 13))
        self.buttonOpenProject.setIcon(QtGui.QIcon(':/icons/24/ic_folder_open_black'))
        self.buttonOpenProject.setIconSize(QtCore.QSize(24, 24))
        self.buttonOpenProject.setText('Open project')
        connect(self.buttonOpenProject.clicked, self.doOpenProject)

        self.buttonHelp = PHCQToolButton(self)
        self.buttonHelp.setFont(Font('Roboto', 12))
        self.buttonHelp.setIcon(QtGui.QIcon(':/icons/24/ic_help_outline_black'))
        self.buttonHelp.setIconSize(QtCore.QSize(24, 24))
        self.buttonHelp.setText('Help')
        self.buttonHelp.setMenu(self.menuHelp)
        self.buttonHelp.setPopupMode(PHCQToolButton.InstantPopup)
        self.buttonHelp.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)

        self.buttonLayoutRT = QtWidgets.QVBoxLayout()
        self.buttonLayoutRT.addWidget(self.buttonNewProject)
        self.buttonLayoutRT.addWidget(self.buttonOpenProject)
        self.buttonLayoutRT.setContentsMargins(0, 38, 0, 0)
        self.buttonLayoutRT.setAlignment(QtCore.Qt.AlignHCenter)
        self.buttonLayoutRB = QtWidgets.QHBoxLayout()
        self.buttonLayoutRB.addWidget(self.buttonHelp)
        self.buttonLayoutRB.setAlignment(QtCore.Qt.AlignBottom|QtCore.Qt.AlignRight)
        self.buttonLayoutRB.setContentsMargins(0, 30, 8, 0)

        self.innerLayoutR = QtWidgets.QVBoxLayout(self.innerWidgetR)
        self.innerLayoutR.setContentsMargins(0, 0, 0, 0)
        self.innerLayoutR.addWidget(self.appPix, 0, QtCore.Qt.AlignHCenter)
        self.innerLayoutR.addWidget(self.appName, 0, QtCore.Qt.AlignHCenter)
        self.innerLayoutR.addWidget(self.appVersion, 0, QtCore.Qt.AlignHCenter)
        self.innerLayoutR.addLayout(self.buttonLayoutRT)
        self.innerLayoutR.addLayout(self.buttonLayoutRB)

        #############################################
        # SETUP DIALOG LAYOUT
        #################################

        self.outerWidgetL = QtWidgets.QWidget(self)
        self.outerWidgetL.setProperty('class', 'outer-left')
        self.outerWidgetL.setContentsMargins(0, 0, 0, 0)
        self.outerWidgetL.setFixedWidth(280)
        self.outerLayoutL = QtWidgets.QVBoxLayout(self.outerWidgetL)
        self.outerLayoutL.setContentsMargins(0, 0, 0, 0)
        self.outerLayoutL.addWidget(self.innerWidgetL, 0,  QtCore.Qt.AlignTop)

        self.outerWidgetR = QtWidgets.QWidget(self)
        self.outerWidgetR.setProperty('class', 'outer-right')
        self.outerWidgetR.setContentsMargins(0, 0, 0, 0)
        self.outerLayoutR = QtWidgets.QVBoxLayout(self.outerWidgetR)
        self.outerLayoutR.setContentsMargins(0, 0, 0, 0)
        self.outerLayoutR.addWidget(self.innerWidgetR, 0,  QtCore.Qt.AlignTop)

        self.mainLayout = QtWidgets.QHBoxLayout(self)
        self.mainLayout.setContentsMargins(0, 0, 0, 0)
        self.mainLayout.addWidget(self.outerWidgetL)
        self.mainLayout.addWidget(self.outerWidgetR)

        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
        self.setFixedSize(720, 400)
        self.setWindowIcon(QtGui.QIcon(':/icons/128/ic_eddy'))
        self.setWindowTitle('Welcome to {0}'.format(APPNAME))
        connect(self.sgnCreateSession, application.doCreateSession)

        desktop = QtWidgets.QDesktopWidget()
        screen = desktop.screenGeometry()
        widget = self.geometry()
        x = (screen.width() - widget.width()) / 2
        y = (screen.height() - widget.height()) / 2
        self.move(x, y)

    #############################################
    #   EVENTS
    #################################

    def paintEvent(self, paintEvent):
        """
        This is needed for the widget to pick the stylesheet.
        :type paintEvent: QPaintEvent
        """
        option = QtWidgets.QStyleOption()
        option.initFrom(self)
        painter = QtGui.QPainter(self)
        style = self.style()
        style.drawPrimitive(QtWidgets.QStyle.PE_Widget, option, painter, self)

    #############################################
    #   SLOTS
    #################################

    @QtCore.pyqtSlot(str)
    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)

    @QtCore.pyqtSlot()
    def doNewProject(self):
        """
        Bring up a modal window used to create a new project.
        """
        form = ProjectDialog(self)
        if form.exec_() == ProjectDialog.Accepted:
            self.sgnCreateSession.emit(expandPath(form.pathField.value()))

    @QtCore.pyqtSlot()
    def doOpenProject(self):
        """
        Bring up a modal window used to open a project.
        """
        dialog = QtWidgets.QFileDialog(self)
        dialog.setAcceptMode(QtWidgets.QFileDialog.AcceptOpen)
        dialog.setDirectory(expandPath(self.workspace))
        dialog.setFileMode(QtWidgets.QFileDialog.Directory)
        dialog.setOption(QtWidgets.QFileDialog.ShowDirsOnly, True)
        dialog.setViewMode(QtWidgets.QFileDialog.Detail)
        if dialog.exec_() == QtWidgets.QFileDialog.Accepted:
            self.sgnCreateSession.emit(expandPath(first(dialog.selectedFiles())))

    @QtCore.pyqtSlot(str)
    def doOpenRecentProject(self, path):
        """
        Open a recent project in a new session of Eddy.
        :type path: str
        """
        self.sgnCreateSession.emit(expandPath(path))

    @QtCore.pyqtSlot()
    def doOpenURL(self):
        """
        Open a URL using the operating system default browser.
        """
        action = self.sender()
        weburl = action.data()
        if weburl:
            # noinspection PyTypeChecker,PyCallByClass,PyCallByClass
            QtGui.QDesktopServices.openUrl(QtCore.QUrl(weburl))