예제 #1
0
    def __init__(self, parent=None):
        QtGui.QMainWindow.__init__(self, parent)

        self._infoBox = InfoBox(self)
        self._menuBar = QtGui.QMenuBar()
        self._messageLoggedObserver = Observer()

        self.setWindowTitle("coraline")
        self.resize(900, 500)
        self.setMenuBar(self._menuBar)
        self.setDockOptions(QtGui.QMainWindow.AllowTabbedDocks
                            | QtGui.QMainWindow.AllowNestedDocks
                            | QtGui.QMainWindow.AnimatedDocks)

        self._menuBar.clear()

        coralApp.addMessageLoggedObserver(self._messageLoggedObserver,
                                          self._messageLogged)
예제 #2
0
    def __init__(self, coralAttribute, parentWidget, sourceCoralAttributes=[]):
        AttributeInspectorWidget.__init__(self, coralAttribute, parentWidget)

        self._valueField = None
        self._attributeSpecializedObserver = Observer()

        coralApp.addAttributeSpecializedObserver(
            self._attributeSpecializedObserver, coralAttribute,
            self._specialized)

        self._update()
예제 #3
0
    def __init__(self, parent):
        QtGui.QWidget.__init__(self, parent)

        self._mainLayout = QtGui.QVBoxLayout(self)
        self._header = QtGui.QWidget(self)
        self._headerLayout = QtGui.QHBoxLayout(self._header)
        self._nodeSearchField = NodeSearchField(self._header)
        self._nodeShelf = NodeShelf(self)
        self._nodeHelp = QtGui.QTextEdit(self)
        self._registeredNodeClassesObserver = Observer()

        self.setWindowTitle("node box")
        self.setLayout(self._mainLayout)

        self._header.setLayout(self._headerLayout)

        self._mainLayout.setContentsMargins(5, 5, 5, 5)
        self._mainLayout.setSpacing(5)
        self._mainLayout.addWidget(self._header)
        self._mainLayout.addWidget(self._nodeShelf)
        self._mainLayout.addWidget(self._nodeHelp)

        self._headerLayout.addWidget(self._nodeSearchField)
        self._headerLayout.setContentsMargins(0, 0, 0, 0)

        self._nodeHelp.setMaximumHeight(150)
        self._nodeHelp.setReadOnly(True)
        palette = self._nodeHelp.palette()
        palette.setColor(QtGui.QPalette.Base, QtGui.QColor(97, 108, 117))
        palette.setColor(QtGui.QPalette.Text, QtGui.QColor(200, 190, 200))
        self._nodeHelp.setPalette(palette)

        self._nodeSearchField.textChanged.connect(self._searchTextChanged)
        self._nodeSearchField.returnPressed.connect(self._shelfReturnPressed)
        self._nodeSearchField.movedEntry.connect(self._searchFieldMovedUpDown)
        self._nodeShelf.itemPressed.connect(self._nodeShelfItemClicked)
        self._nodeShelf.currentRowChanged.connect(self._nodeShelfRowChanged)
        self._nodeShelf.doubleClicked.connect(self._nodeShelfDblClick)
        self.connect(mainWindow.MainWindow.globalInstance(),
                     QtCore.SIGNAL("coralDataDropped"), self._dropEnd)

        coralApp.addRegisteredNodeClassesObserver(
            self._registeredNodeClassesObserver,
            self._registeredNodeClassesCallback)

        self._rebuildNodeShelf()

        NodeBox._globalInstance = weakref.ref(self)

        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
예제 #4
0
    def __init__(self, parent = None):
        QtGui.QMainWindow.__init__(self, parent)

        self._infoBox = InfoBox(self)         
        self._menuBar = QtGui.QMenuBar()
        self._messageLoggedObserver = Observer()
        
        self.setWindowTitle("coraline")
        self.resize(900, 500)
        self.setMenuBar(self._menuBar)
        self.setDockOptions(QtGui.QMainWindow.AllowTabbedDocks | QtGui.QMainWindow.AllowNestedDocks | QtGui.QMainWindow.AnimatedDocks)
        
        self._menuBar.clear()


        coralApp.addMessageLoggedObserver(self._messageLoggedObserver, self._messageLogged)
예제 #5
0
class MainWindow(QtGui.QMainWindow):
    _globalInstance = None
    _lastFileDialogDir = ""
    _closedWidgets = {}
    _registeredWidgets = {}

    @staticmethod
    def openRegisteredWidget(widgetName):
        if MainWindow._registeredWidgets.has_key(widgetName):
            widgetClass = MainWindow._registeredWidgets[widgetName]
            MainWindow._globalInstance.dockWidget(
                widgetClass(MainWindow._globalInstance))

    @staticmethod
    def registerWidget(widgetName, widget):
        MainWindow._registeredWidgets[widgetName] = widget

    @staticmethod
    def _init(parent=None):
        MainWindow._globalInstance = MainWindow(parent)

    @staticmethod
    def globalInstance():
        return MainWindow._globalInstance

    @staticmethod
    def okCancelDialog(message):
        dialog = QtGui.QMessageBox(MainWindow._globalInstance)
        dialog.setText(message)
        dialog.addButton("No", QtGui.QMessageBox.NoRole)
        dialog.addButton("Yes", QtGui.QMessageBox.YesRole)

        result = dialog.exec_()
        return result

    @staticmethod
    def saveFileDialog(title, fileType):
        filename = QtGui.QFileDialog.getSaveFileName(
            MainWindow._globalInstance, title, MainWindow._lastFileDialogDir,
            fileType)

        MainWindow._lastFileDialogDir = os.path.split(str(filename))[0]

        return str(filename)

    @staticmethod
    def openFileDialog(title, fileType):
        filename = QtGui.QFileDialog.getOpenFileName(
            MainWindow._globalInstance, title, MainWindow._lastFileDialogDir,
            fileType)

        MainWindow._lastFileDialogDir = os.path.split(str(filename))[0]

        return str(filename)

    def __init__(self, parent=None):
        QtGui.QMainWindow.__init__(self, parent)

        self._infoBox = InfoBox(self)
        self._menuBar = QtGui.QMenuBar()
        self._messageLoggedObserver = Observer()

        self.setWindowTitle("coraline")
        self.resize(900, 500)
        self.setMenuBar(self._menuBar)
        self.setDockOptions(QtGui.QMainWindow.AllowTabbedDocks
                            | QtGui.QMainWindow.AllowNestedDocks
                            | QtGui.QMainWindow.AnimatedDocks)

        self._menuBar.clear()

        coralApp.addMessageLoggedObserver(self._messageLoggedObserver,
                                          self._messageLogged)

    def _messageLogged(self):
        message = self._messageLoggedObserver.data("message")
        verboseLevel = self._messageLoggedObserver.data("verboseLevel")

        if verboseLevel == coralApp.VerboseLevel.logInfos:
            self._infoBox.showMessage(message)
        elif verboseLevel == coralApp.VerboseLevel.logErrors:
            self._infoBox.showError(message)

    def about(self):
        aboutBox = QtGui.QMessageBox(self)
        aboutBox.setWindowTitle("About Coral")

        aboutMsg = '<h2>Coral Version ' + coralApp.version() + '</h2>'
        aboutMsg += '<p style="color: #333333; font-size: small;">Created by Andrea Interguglielmi</p>'
        aboutMsg += '<p style="color: #333333; font-size: small;">Developed at <a href="http://code.google.com/p/coral-repo/">code.google.com/p/coral-repo</a></p>'

        aboutBox.setTextFormat(QtCore.Qt.RichText)
        aboutBox.setText(aboutMsg)
        aboutBox.exec_()

    def menuBar(self):
        return self._menuBar

    def dockWidget(self, widget, area=None):
        dock = dockWidget.DockWidget(widget, self)
        dock.setObjectName(widget.windowTitle())
        dock.show()

        if area is None:
            dock.setFloating(True)
        else:
            self.addDockWidget(area, dock)

        return dock

    def _restoreLastOpenWindows(self, settings):
        widgetsLastOpen = settings.value("openWidgets")
        if widgetsLastOpen:
            widgetsLastOpen = eval(str(widgetsLastOpen))

        openWidgetsName = []
        for dockWidget in self.dockWidgets():
            openWidgetsName.append(str(dockWidget.windowTitle()))

        if not widgetsLastOpen:
            return
        for widgetName in widgetsLastOpen:
            if widgetName not in openWidgetsName:
                if MainWindow._registeredWidgets.has_key(widgetName):
                    widgetClass = MainWindow._registeredWidgets[widgetName]
                    self.dockWidget(widgetClass(self))

    def restoreSettings(self):
        settings = self.settings()

        self._restoreLastOpenWindows(settings)

        lastFileDialogDir = settings.value("lastFileDialogDir")
        if lastFileDialogDir:
            MainWindow._lastFileDialogDir = lastFileDialogDir

        geometry = str(settings.value("mainWinGeometry"))
        if geometry:
            geometry = eval(geometry)
        if not geometry:
            return
        self.move(geometry[0], geometry[1])
        self.resize(geometry[2], geometry[3])

        self.restoreState(settings.value("mainWinState"))

    def settings(self):
        return QtCore.QSettings(self.windowTitle())

    def dockWidgets(self):
        dockWidgets = []
        for obj in self.children():
            if type(obj) is dockWidget.DockWidget:
                dockWidgets.append(obj)
            elif isinstance(obj, nodeBox.NodeBox):
                dockWidgets.append(obj)

        return dockWidgets

    def closeEvent(self, event):
        settings = self.settings()
        settings.setValue(
            "mainWinGeometry",
            str([
                self.pos().x(),
                self.pos().y(),
                self.size().width(),
                self.size().height()
            ]))
        settings.setValue("mainWinState", self.saveState())

        openWidgets = []
        for dockWidget in self.dockWidgets():
            widgetName = str(dockWidget.windowTitle())
            if dockWidget.isVisible() and widgetName not in openWidgets:
                openWidgets.append(widgetName)

            dockWidget.closeEvent(event)

        settings.setValue("openWidgets", str(openWidgets))
        settings.setValue("lastFileDialogDir", MainWindow._lastFileDialogDir)
        settings.setValue("settingsStored", True)

        QtGui.QMainWindow.closeEvent(self, event)

    def setShortcutsMap(self, shortcuts):
        for key, function in shortcuts.iteritems():
            QtGui.QShortcut(QtGui.QKeySequence(key), self, function)

    def setCentralWidget(self, widget):
        QtGui.QMainWindow.setCentralWidget(self, widget)
        self._infoBox = InfoBox(widget)

    def resizeEvent(self, event):
        self._infoBox.updateSize()

    def showError(self, errorMessage):
        """ Display an error dialog """
        QtGui.QMessageBox.critical(self, "Error", errorMessage)
예제 #6
0
class MainWindow(QtGui.QMainWindow):
    _globalInstance = None
    _lastFileDialogDir = ""
    _closedWidgets = {}
    _registeredWidgets = {}
    
    @staticmethod
    def openRegisteredWidget(widgetName):
        if MainWindow._registeredWidgets.has_key(widgetName):
            widgetClass = MainWindow._registeredWidgets[widgetName]
            MainWindow._globalInstance.dockWidget(widgetClass(MainWindow._globalInstance))
    
    @staticmethod
    def registerWidget(widgetName, widget):
        MainWindow._registeredWidgets[widgetName] = widget
    
    @staticmethod
    def _init(parent=None):
        MainWindow._globalInstance = MainWindow(parent)
    
    @staticmethod
    def globalInstance():
        return MainWindow._globalInstance
    
    @staticmethod
    def okCancelDialog(message):
        dialog = QtGui.QMessageBox(MainWindow._globalInstance)
        dialog.setText(message)
        dialog.addButton("No", QtGui.QMessageBox.NoRole)
        dialog.addButton("Yes", QtGui.QMessageBox.YesRole)
        
        result = dialog.exec_()
        return result
    
    @staticmethod
    def saveFileDialog(title, fileType):
        filename = QtGui.QFileDialog.getSaveFileName(MainWindow._globalInstance, title, MainWindow._lastFileDialogDir, fileType)
    
        MainWindow._lastFileDialogDir = os.path.split(str(filename))[0]
    
        return str(filename)
    
    @staticmethod
    def openFileDialog(title, fileType):
        filename = QtGui.QFileDialog.getOpenFileName(MainWindow._globalInstance, title, MainWindow._lastFileDialogDir, fileType)
    
        MainWindow._lastFileDialogDir = os.path.split(str(filename))[0]
    
        return str(filename)
    
    def __init__(self, parent = None):
        QtGui.QMainWindow.__init__(self, parent)

        self._infoBox = InfoBox(self)         
        self._menuBar = QtGui.QMenuBar()
        self._messageLoggedObserver = Observer()
        
        self.setWindowTitle("coraline")
        self.resize(900, 500)
        self.setMenuBar(self._menuBar)
        self.setDockOptions(QtGui.QMainWindow.AllowTabbedDocks | QtGui.QMainWindow.AllowNestedDocks | QtGui.QMainWindow.AnimatedDocks)
        
        self._menuBar.clear()


        coralApp.addMessageLoggedObserver(self._messageLoggedObserver, self._messageLogged)
    
    def _messageLogged(self):
        message = self._messageLoggedObserver.data("message")
        verboseLevel = self._messageLoggedObserver.data("verboseLevel")

        if verboseLevel == coralApp.VerboseLevel.logInfos:
            self._infoBox.showMessage(message)
        elif verboseLevel == coralApp.VerboseLevel.logErrors:
            self._infoBox.showError(message)

    def about(self):
        aboutBox = QtGui.QMessageBox(self)
        aboutBox.setWindowTitle("About Coral")
        
        aboutMsg = '<h2>Coral Version ' + coralApp.version() + '</h2>'
        aboutMsg += '<p style="color: #333333; font-size: small;">Created by Andrea Interguglielmi</p>'
        aboutMsg += '<p style="color: #333333; font-size: small;">Developed at <a href="http://code.google.com/p/coral-repo/">code.google.com/p/coral-repo</a></p>'
        
        aboutBox.setTextFormat(QtCore.Qt.RichText)
        aboutBox.setText(aboutMsg)
        aboutBox.exec_()
        
    def menuBar(self):
        return self._menuBar
    
    def dockWidget(self, widget, area = None):
        dock = dockWidget.DockWidget(widget, self)
        dock.setObjectName(widget.windowTitle())
        dock.show()
        
        if area is None:
            dock.setFloating(True)
        else:
            self.addDockWidget(area, dock)
        
        return dock
    
    def _restoreLastOpenWindows(self, settings):
        widgetsLastOpen = settings.value("openWidgets")
        if widgetsLastOpen:
            widgetsLastOpen = eval(str(widgetsLastOpen))
        
        openWidgetsName = []
        for dockWidget in self.dockWidgets():
            openWidgetsName.append(str(dockWidget.windowTitle()))
        
        if not widgetsLastOpen:
            return
        for widgetName in widgetsLastOpen:
            if widgetName not in openWidgetsName:
                if MainWindow._registeredWidgets.has_key(widgetName):
                    widgetClass = MainWindow._registeredWidgets[widgetName]
                    self.dockWidget(widgetClass(self))
        
    def restoreSettings(self):
        settings = self.settings()
        
        self._restoreLastOpenWindows(settings)

        lastFileDialogDir = settings.value("lastFileDialogDir")
        if lastFileDialogDir:
            MainWindow._lastFileDialogDir = lastFileDialogDir
        
        geometry = str(settings.value("mainWinGeometry"))
        if geometry:
            geometry = eval(geometry)
        if not geometry:
            return
        self.move(geometry[0], geometry[1])
        self.resize(geometry[2], geometry[3])
        
        self.restoreState(settings.value("mainWinState"))

    def settings(self):
        return QtCore.QSettings(self.windowTitle())
    
    def dockWidgets(self):
        dockWidgets = []
        for obj in self.children():
            if type(obj) is dockWidget.DockWidget:
                dockWidgets.append(obj)
            elif isinstance(obj, nodeBox.NodeBox):
                dockWidgets.append(obj)
        
        return dockWidgets
    
    def closeEvent(self, event):
        settings = self.settings()
        settings.setValue("mainWinGeometry", str([self.pos().x(), self.pos().y(), self.size().width(), self.size().height()]))
        settings.setValue("mainWinState", self.saveState())
        
        openWidgets = []
        for dockWidget in self.dockWidgets():
            widgetName = str(dockWidget.windowTitle())
            if dockWidget.isVisible() and widgetName not in openWidgets:
                openWidgets.append(widgetName)
                
            dockWidget.closeEvent(event)
        
        settings.setValue("openWidgets", str(openWidgets))
        settings.setValue("lastFileDialogDir", MainWindow._lastFileDialogDir)
        settings.setValue("settingsStored", True)
        
        QtGui.QMainWindow.closeEvent(self, event)

    def setShortcutsMap(self, shortcuts):
        for key, function in shortcuts.iteritems():
            QtGui.QShortcut(QtGui.QKeySequence(key), self, function)

    def setCentralWidget(self, widget):
        QtGui.QMainWindow.setCentralWidget(self, widget)
        self._infoBox = InfoBox(widget)

    def resizeEvent(self, event):
        self._infoBox.updateSize()

    def showError(self, errorMessage):
        """ Display an error dialog """
        QtGui.QMessageBox.critical(self, "Error", errorMessage)