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

- Editor code
- No longer export gif files

Location:
nodebox/branches/try-qt
Files:
1 added
5 modified
2 copied

Legend:

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

    r267 r284  
    7777     
    7878    """Given a source string or code object, executes the scripts and saves the result as an image. 
    79     Supported image extensions: pdf, tiff, png, jpg, gif""" 
     79    Supported image extensions: pdf, tiff, png, jpg""" 
    8080     
    8181    runner = NodeBoxRunner() 
     
    102102Usage: console.py sourcefile imagefile 
    103103   or: console.py sourcefile moviefile number_of_frames [fps] 
    104 Supported image extensions: pdf, tiff, png, jpg, gif 
     104Supported image extensions: pdf, tiff, png, jpg 
    105105Supported movie extension:  mov""" + err 
    106106 
     
    111111    elif len(sys.argv) == 3: # Should be an image 
    112112        basename, ext = os.path.splitext(sys.argv[2]) 
    113         if ext not in ('.pdf', '.gif', '.jpg', '.jpeg', '.png', '.tiff'): 
     113        if ext not in ('.pdf', '.jpg', '.jpeg', '.png', '.tiff'): 
    114114            return usage('This is not a supported image format.') 
    115115        make_image(open(sys.argv[1]).read(), sys.argv[2]) 
     
    140140 
    141141    # Using the shortcut functions: 
    142     make_image('size(200,200)\ntext(FRAME, 100, 100)', 'console-test.gif') 
     142    make_image('size(200,200)\ntext(FRAME, 100, 100)', 'console-test.png') 
    143143    make_movie('size(200,200)\ntext(FRAME, 100, 100)', 'console-test.mov', 10) 
    144144 
  • nodebox/branches/try-qt/nodebox/graphics/qt.py

    r267 r284  
    44 
    55from PyQt4.QtGui import QPainterPath, QColor, QTransform, QBrush, QPen, QImage, QPrinter, QPainter, QFontMetrics, QFont 
    6 from PyQt4.QtCore import Qt, QSize 
     6from PyQt4.QtCore import Qt, QSize, QPointF, QRectF 
    77from PyQt4.QtSvg import QSvgGenerator 
    88 
     
    548548 
    549549    def _set(self, painter): 
    550         painter.setBrush(self.qColor) 
     550        painter.setBrush(self._rgb) 
    551551     
    552552    def _get_qColor(self): 
     
    620620        trans = painter.transform() 
    621621        painter.setTransform(trans * self._qtransform) 
    622         #m1 = trans.m11(), trans.m12(), trans.m13(), trans.m21(), trans.m22(), trans.dx(), trans.dy() 
    623         #trans = self._qtransform 
    624         #m2 = trans.m11(), trans.m12(), trans.m13(), trans.m21(), trans.m22(), trans.dx(), trans.dy() 
    625         #m3 = transform.mmult(m1, m2) 
    626         #trans = QTransform(*m3) 
    627         # TODO: returns a NotImplemented 
    628         #trans += QTransform(self._qtransform) 
    629         #painter.setTransform(trans) 
    630622 
    631623    def copy(self): 
     
    717709        if data is not None: 
    718710            self._nsImage = QImage(data) 
    719             if self._qImage is None: 
     711            if self._qimage is None: 
    720712                raise NodeBoxError, "can't read image %r" % path 
    721713        elif image is not None: 
    722714            if isinstance(image, QImage): 
    723                 self._qImage = image 
     715                self._qimage = image 
    724716            else: 
    725717                raise NodeBoxError, "Don't know what to do with %s." % image 
     
    739731                    raise NodeBoxError, "Can't read image %r" % path 
    740732                self._ctx._imagecache[path] = (image, curtime) 
    741             self._qImage = image 
     733            self._qimage = image 
    742734        self.x = x 
    743735        self.y = y 
     
    748740 
    749741    def _get_image(self): 
    750         warnings.warn("The 'image' attribute is deprecated. Please use _qImage instead.", DeprecationWarning, stacklevel=2) 
    751         return self._qImage 
     742        warnings.warn("The 'image' attribute is deprecated. Please use _qimage instead.", DeprecationWarning, stacklevel=2) 
     743        return self._qimage 
    752744    image = property(_get_image) 
    753745 
     
    765757        """Draw an image on the given coordinates.""" 
    766758 
    767         srcW, srcH = self._qImage.width(), self._qImage.height() 
     759        srcW, srcH = self._qimage.width(), self._qimage.height() 
    768760        srcRect = ((0, 0), (srcW, srcH)) 
    769761 
     
    824816            # A debugImage draws a black rectangle instead of an image. 
    825817            if self.debugImage: 
    826                 #Color(self._ctx).set() 
    827                 #pt = BezierPath() 
    828                 #pt.rect(0, 0, ) 
    829                 #pt.fill() 
    830818                painter.setBrush(QBrush(Qt.SolidPattern)) 
    831819                painter.fillRect(QRectF(0, 0, srcW / factor, srcH / factor)) 
    832820            else: 
    833                 # TODO: Stuff with composition modes 
    834                 painter.drawImage(QPointF(0, 0), self._qImage, srcRect) 
     821                # TODO: Stuff with composition modes to allow for alpha transparency 
     822                painter.drawImage(QPointF(0, 0), self._qimage, QRectF(0, 0, srcW, srcH)) 
    835823            painter.restore() 
    836824        # No width or height given 
    837825        else: 
    838             _save() 
     826            painter.save() 
    839827            x,y = self.x, self.y 
    840828            # Center-mode transforms: translate to image center 
     
    854842                painter.fillRect(QRectF(0, 0, srcW, srcH)) 
    855843            else: 
    856                 # TODO: Stuff with composition modes 
    857                 painter.drawImage(QPointF(0, 0), self._qImage, srcRect) 
     844                # TODO: Stuff with composition modes to allow for alpha transparency 
     845                painter.drawImage(QPointF(0, 0), self._qimage, QRectF(0, 0, srcW, srcH)) 
    858846            painter.restore() 
    859847 
     
    864852 
    865853    __dummy_color = QColor() 
    866     __alignMap = { LEFT: Qt.AlignLeft, RIGHT:Qt.AlignRight, CENTER:Qt.AlignCenter, JUSTIFY:Qt.AlignJustify } 
     854    __alignMap = { LEFT: Qt.AlignLeft, RIGHT: Qt.AlignRight, CENTER: Qt.AlignCenter, JUSTIFY: Qt.AlignJustify } 
    867855     
    868856    def __init__(self, ctx, text, x=0, y=0, width=None, height=None, **kwargs): 
     
    912900        if self._fillcolor is None: return 
    913901        x,y = r.x(), r.y() 
     902        w, h = r.width(), r.height() 
    914903        preferredWidth, preferredHeight = r.width(), r.height() 
    915904        if self.width is not None: 
     
    920909 
    921910        painter.save() 
     911        painter.setFont(self._qfont) 
     912        self._fillcolor._set(painter) 
     913        #painter.setBrush(QBrush(self._fillcolor)) 
    922914        # Center-mode transforms: translate to image center 
    923915        if self._transformmode == CENTER: 
     
    925917            deltaY = h / 2 
    926918            t = Transform() 
    927             t.translate(x+deltaX, y-fm.ascent()+deltaY) 
     919            #t.translate(x+deltaX, y+fm.ascent()+deltaY) 
    928920            t.concat(painter) 
    929921            self._transform.concat(painter) 
     
    931923            #layoutManager.drawGlyphsForGlyphRange_atPoint_(glyphRange, (-deltaX-dx,-deltaY-dy)) 
    932924        else: 
    933             #self._transform.concat() 
    934             painter.drawText(x, y, w, h, self.text) 
     925            self._transform.concat() 
     926            painter.drawText(x, y, w, h, flags, self.text) 
    935927            #layoutManager.drawGlyphsForGlyphRange_atPoint_(glyphRange, (x-dx,y-dy-self.font.defaultLineHeightForFont())) 
    936928        painter.restore() 
     
    10901082            self.draw(painter) 
    10911083            painter.end() 
    1092         elif format in ("png", "tiff", "jpg", "jpeg", "gif"): 
     1084        elif format in ("png", "tiff", "jpg", "jpeg"): 
    10931085            img = QImage(self.width, self.height, QImage.Format_ARGB32) 
    10941086            painter = QPainter(img) 
  • nodebox/branches/try-qt/nodebox/gui/mac/__init__.py

    r227 r284  
    486486             
    487487    def exportImageFormatChanged_(self, sender): 
    488         image_formats = ('pdf', 'png', 'tiff', 'jpg', 'gif') 
     488        image_formats = ('pdf', 'png', 'tiff', 'jpg') 
    489489        panel = sender.window() 
    490490        panel.setRequiredFileType_(image_formats[sender.indexOfSelectedItem()]) 
  • nodebox/branches/try-qt/nodebox/gui/qt/__init__.py

    r283 r284  
    1010from PyQt4.QtCore import Qt, SIGNAL, SLOT, pyqtSignature, QTimer, QRectF, QSize 
    1111from PyQt4.QtSvg import QSvgGenerator 
     12 
     13from nodebox.gui.qt.editor import PythonHighlighter, CodeEdit, loadConfig 
    1214 
    1315MAGICVAR = "__magic_var__" 
     
    8789            p.drawPixmap(0, 0, self._image) 
    8890         
    89 class CodeView(QTextEdit): 
    90  
    91     def __init__(self, parent=None): 
    92         QTextEdit.__init__(self, parent) 
    93         self.setLineWrapMode(QTextEdit.NoWrap) 
    94          
    95     def mousePressEvent(self, event): 
    96         if int(QApplication.keyboardModifiers()) & Qt.ControlModifier > 0: 
    97             event.x() 
    98             event.y() 
    99             cursor = self.cursorForPosition(event.pos()) 
    100             print "CURS", cursor.position() 
    101             code = unicode(self.toPlainText()) 
    102             print code[cursor.position()] 
    103             cursor.select(QTextCursor.BlockUnderCursor) 
    104             print unicode(cursor.selectedText()) 
    105         QTextEdit.mousePressEvent(self, event) 
    106         #QTextCursor 
    107  
    10891class NodeBoxDocument(QMainWindow): 
    10992    def __init__(self): 
     
    187170        self.graphicsScroll.setWidget(self.graphicsView) 
    188171        self.graphicsScroll.setMinimumSize(300, 300) 
    189         self.codeView = CodeView() 
     172        self.codeView = CodeEdit() 
    190173        self.codeView.setFontFamily(codeFont.defaultFamily()) 
    191174        self.codeView.setCurrentFont(codeFont) 
     
    193176        self.codeView.setMinimumSize(300, 300) 
    194177        self.codeView.setAcceptRichText(False) 
     178        PythonHighlighter(self.codeView.document()) 
    195179        self.outputView = QTextEdit() 
    196180        self.outputView.setMinimumSize(300, 300) 
     
    286270        global app 
    287271        if self.canvas is None: return 
    288         fileName = QFileDialog.getSaveFileName(self, self.tr("Save SVG File"), app.home, "*.svg,*.pdf,*.png,*.tiff,*.jpg,*.jpeg,*.gif") 
     272        fileName = QFileDialog.getSaveFileName(self, self.tr("Save SVG File"), app.home, "*.svg,*.pdf,*.png,*.tiff,*.jpg,*.jpeg") 
    289273        print "save image as ", fileName 
    290274        if fileName is not None and len(fileName) > 0: 
     
    419403 
    420404        # Set the mouse position 
     405        # TODO: Get correct mouse position 
    421406        #window = self.currentView.window() 
    422407        pt = 0, 0 # window.mouseLocationOutsideOfEventStream() 
     
    427412            my = self.currentView.bounds()[1][1] - my 
    428413        self.namespace["MOUSEX"], self.namespace["MOUSEY"] = mx, my 
    429         #self.namespace["mousedown"] = QtGui.QApplication.mouseButtons() & QtCore.Qt.LeftButton > 0 
     414        #self.namespace["mousedown"] = QApplication.mouseButtons() & Qt.LeftButton 
    430415        #self.namespace["keydown"] = self.currentView.keydown 
    431416        #self.namespace["key"] = self.currentView.key 
     
    522507                pass 
    523508            sys.argv = saveArgv 
    524             self._flushOutput(output) 
    525509        return True, output 
    526510 
     
    580564    def __init__(self, args): 
    581565        QApplication.__init__(self, args) 
     566        loadConfig() 
    582567        self.documents = [] 
    583568        if sys.platform == "win32": 
  • nodebox/branches/try-qt/nodebox/util/__init__.py

    r205 r284  
    5555     
    5656    You can use wildcards to specify which files to pick, e.g. 
    57         f = files('*.gif') 
     57        f = files('*.png') 
    5858    """ 
    5959    from glob import glob