Changeset 286

Show
Ignore:
Timestamp:
12/21/07 14:11:13 (13 months ago)
Author:
fdb
Message:

- Colors are clamped
- Remember last opened directory

Location:
nodebox/branches/try-qt/nodebox
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • nodebox/branches/try-qt/nodebox/graphics/qt.py

    r284 r286  
    584584    def _normalize(self, v): 
    585585        """Bring the color into the 0-1 scale for the current colorrange""" 
    586         return v / self._ctx._colorrange 
     586        return clamp(v / self._ctx._colorrange) 
    587587 
    588588    def _normalizeList(self, lst): 
    589589        """Bring the color into the 0-1 scale for the current colorrange""" 
    590         return map(lambda x:x / self._ctx._colorrange, lst) 
     590        return map(lambda x:clamp(x / self._ctx._colorrange), lst) 
    591591 
    592592color = Color 
     593 
     594def clamp(v): 
     595    return max(min(v, 1.0), 0.0) 
    593596 
    594597class Transform(object): 
  • nodebox/branches/try-qt/nodebox/gui/qt/__init__.py

    r285 r286  
    88 
    99from PyQt4.QtGui import QApplication, QWidget, QColor, QPainter, QMenuBar, QMenu, QKeySequence, QTextEdit, QSplitter, QGridLayout, QDialog, QScrollArea, QFont, QTextCharFormat, QFileDialog, QTextCursor, QPixmap, QPrinter, QImage, QMainWindow 
    10 from PyQt4.QtCore import Qt, SIGNAL, SLOT, pyqtSignature, QTimer, QRectF, QSize 
     10from PyQt4.QtCore import Qt, SIGNAL, SLOT, pyqtSignature, QTimer, QRectF, QSize, QCoreApplication, QSettings, QVariant 
    1111from PyQt4.QtSvg import QSvgGenerator 
    1212 
     
    227227    def doOpen(self): 
    228228        global app 
    229         fileName = QFileDialog.getOpenFileName(None, self.tr("Open File"), app.home, "*.py") 
     229        fileName = QFileDialog.getOpenFileName(None, self.tr("Open File"), app.lastDir, "*.py") 
    230230        print "open", fileName 
    231231        if fileName is not None and len(fileName) > 0: 
     
    234234            source = fp.read() 
    235235            fp.close() 
     236            app.lastDir = os.path.dirname(fileName) 
    236237            doc = app.newDocument() 
    237238            doc.fileName = fileName 
     
    566567    def __init__(self, args): 
    567568        QApplication.__init__(self, args) 
     569        QCoreApplication.setOrganizationName("NodeBox") 
     570        QCoreApplication.setOrganizationDomain("nodebox.net") 
     571        QCoreApplication.setApplicationName("NodeBox") 
     572        self.settings = QSettings() 
    568573        loadConfig() 
    569574        self.documents = [] 
     
    577582            self.home = os.getenv('HOME') 
    578583            self.lib = os.path.join(self.home, "nodebox") 
     584        self._lastDir = self.settings.value("lastDir", QVariant(self.home)).toString() 
    579585        try: 
    580586            if not os.path.exists(self.lib): 
     
    591597        self.documents.append(doc) 
    592598        return doc 
     599         
     600    def _get_lastDir(self): 
     601        return self._lastDir 
     602    def _set_lastDir(self, lastDir): 
     603        self._lastDir = lastDir 
     604        self.settings.setValue("lastDir", QVariant(lastDir)) 
     605    lastDir = property(_get_lastDir, _set_lastDir) 
    593606 
    594607def qtmain():