Changeset 284 for nodebox/branches/try-qt
- Timestamp:
- 12/21/07 13:32:44 (13 months ago)
- Location:
- nodebox/branches/try-qt
- Files:
-
- 1 added
- 5 modified
- 2 copied
-
nodebox/console.py (modified) (4 diffs)
-
nodebox/graphics/qt.py (modified) (15 diffs)
-
nodebox/gui/mac/__init__.py (modified) (1 diff)
-
nodebox/gui/qt/__init__.py (modified) (9 diffs)
-
nodebox/gui/qt/editor.py (added)
-
nodebox/util/__init__.py (modified) (1 diff)
-
tests/graphics/006-text.png (copied) (copied from nodebox/trunk/src/tests/graphics/006-text.png)
-
tests/graphics/006-text.py (copied) (copied from nodebox/trunk/src/tests/graphics/006-text.py)
Legend:
- Unmodified
- Added
- Removed
-
nodebox/branches/try-qt/nodebox/console.py
r267 r284 77 77 78 78 """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""" 80 80 81 81 runner = NodeBoxRunner() … … 102 102 Usage: console.py sourcefile imagefile 103 103 or: console.py sourcefile moviefile number_of_frames [fps] 104 Supported image extensions: pdf, tiff, png, jpg , gif104 Supported image extensions: pdf, tiff, png, jpg 105 105 Supported movie extension: mov""" + err 106 106 … … 111 111 elif len(sys.argv) == 3: # Should be an image 112 112 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'): 114 114 return usage('This is not a supported image format.') 115 115 make_image(open(sys.argv[1]).read(), sys.argv[2]) … … 140 140 141 141 # 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') 143 143 make_movie('size(200,200)\ntext(FRAME, 100, 100)', 'console-test.mov', 10) 144 144 -
nodebox/branches/try-qt/nodebox/graphics/qt.py
r267 r284 4 4 5 5 from PyQt4.QtGui import QPainterPath, QColor, QTransform, QBrush, QPen, QImage, QPrinter, QPainter, QFontMetrics, QFont 6 from PyQt4.QtCore import Qt, QSize 6 from PyQt4.QtCore import Qt, QSize, QPointF, QRectF 7 7 from PyQt4.QtSvg import QSvgGenerator 8 8 … … 548 548 549 549 def _set(self, painter): 550 painter.setBrush(self. qColor)550 painter.setBrush(self._rgb) 551 551 552 552 def _get_qColor(self): … … 620 620 trans = painter.transform() 621 621 painter.setTransform(trans * self._qtransform) 622 #m1 = trans.m11(), trans.m12(), trans.m13(), trans.m21(), trans.m22(), trans.dx(), trans.dy()623 #trans = self._qtransform624 #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 NotImplemented628 #trans += QTransform(self._qtransform)629 #painter.setTransform(trans)630 622 631 623 def copy(self): … … 717 709 if data is not None: 718 710 self._nsImage = QImage(data) 719 if self._q Image is None:711 if self._qimage is None: 720 712 raise NodeBoxError, "can't read image %r" % path 721 713 elif image is not None: 722 714 if isinstance(image, QImage): 723 self._q Image = image715 self._qimage = image 724 716 else: 725 717 raise NodeBoxError, "Don't know what to do with %s." % image … … 739 731 raise NodeBoxError, "Can't read image %r" % path 740 732 self._ctx._imagecache[path] = (image, curtime) 741 self._q Image = image733 self._qimage = image 742 734 self.x = x 743 735 self.y = y … … 748 740 749 741 def _get_image(self): 750 warnings.warn("The 'image' attribute is deprecated. Please use _q Image instead.", DeprecationWarning, stacklevel=2)751 return self._q Image742 warnings.warn("The 'image' attribute is deprecated. Please use _qimage instead.", DeprecationWarning, stacklevel=2) 743 return self._qimage 752 744 image = property(_get_image) 753 745 … … 765 757 """Draw an image on the given coordinates.""" 766 758 767 srcW, srcH = self._q Image.width(), self._qImage.height()759 srcW, srcH = self._qimage.width(), self._qimage.height() 768 760 srcRect = ((0, 0), (srcW, srcH)) 769 761 … … 824 816 # A debugImage draws a black rectangle instead of an image. 825 817 if self.debugImage: 826 #Color(self._ctx).set()827 #pt = BezierPath()828 #pt.rect(0, 0, )829 #pt.fill()830 818 painter.setBrush(QBrush(Qt.SolidPattern)) 831 819 painter.fillRect(QRectF(0, 0, srcW / factor, srcH / factor)) 832 820 else: 833 # TODO: Stuff with composition modes 834 painter.drawImage(QPointF(0, 0), self._q Image, 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)) 835 823 painter.restore() 836 824 # No width or height given 837 825 else: 838 _save()826 painter.save() 839 827 x,y = self.x, self.y 840 828 # Center-mode transforms: translate to image center … … 854 842 painter.fillRect(QRectF(0, 0, srcW, srcH)) 855 843 else: 856 # TODO: Stuff with composition modes 857 painter.drawImage(QPointF(0, 0), self._q Image, 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)) 858 846 painter.restore() 859 847 … … 864 852 865 853 __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 } 867 855 868 856 def __init__(self, ctx, text, x=0, y=0, width=None, height=None, **kwargs): … … 912 900 if self._fillcolor is None: return 913 901 x,y = r.x(), r.y() 902 w, h = r.width(), r.height() 914 903 preferredWidth, preferredHeight = r.width(), r.height() 915 904 if self.width is not None: … … 920 909 921 910 painter.save() 911 painter.setFont(self._qfont) 912 self._fillcolor._set(painter) 913 #painter.setBrush(QBrush(self._fillcolor)) 922 914 # Center-mode transforms: translate to image center 923 915 if self._transformmode == CENTER: … … 925 917 deltaY = h / 2 926 918 t = Transform() 927 t.translate(x+deltaX, y-fm.ascent()+deltaY)919 #t.translate(x+deltaX, y+fm.ascent()+deltaY) 928 920 t.concat(painter) 929 921 self._transform.concat(painter) … … 931 923 #layoutManager.drawGlyphsForGlyphRange_atPoint_(glyphRange, (-deltaX-dx,-deltaY-dy)) 932 924 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) 935 927 #layoutManager.drawGlyphsForGlyphRange_atPoint_(glyphRange, (x-dx,y-dy-self.font.defaultLineHeightForFont())) 936 928 painter.restore() … … 1090 1082 self.draw(painter) 1091 1083 painter.end() 1092 elif format in ("png", "tiff", "jpg", "jpeg" , "gif"):1084 elif format in ("png", "tiff", "jpg", "jpeg"): 1093 1085 img = QImage(self.width, self.height, QImage.Format_ARGB32) 1094 1086 painter = QPainter(img) -
nodebox/branches/try-qt/nodebox/gui/mac/__init__.py
r227 r284 486 486 487 487 def exportImageFormatChanged_(self, sender): 488 image_formats = ('pdf', 'png', 'tiff', 'jpg' , 'gif')488 image_formats = ('pdf', 'png', 'tiff', 'jpg') 489 489 panel = sender.window() 490 490 panel.setRequiredFileType_(image_formats[sender.indexOfSelectedItem()]) -
nodebox/branches/try-qt/nodebox/gui/qt/__init__.py
r283 r284 10 10 from PyQt4.QtCore import Qt, SIGNAL, SLOT, pyqtSignature, QTimer, QRectF, QSize 11 11 from PyQt4.QtSvg import QSvgGenerator 12 13 from nodebox.gui.qt.editor import PythonHighlighter, CodeEdit, loadConfig 12 14 13 15 MAGICVAR = "__magic_var__" … … 87 89 p.drawPixmap(0, 0, self._image) 88 90 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 #QTextCursor107 108 91 class NodeBoxDocument(QMainWindow): 109 92 def __init__(self): … … 187 170 self.graphicsScroll.setWidget(self.graphicsView) 188 171 self.graphicsScroll.setMinimumSize(300, 300) 189 self.codeView = Code View()172 self.codeView = CodeEdit() 190 173 self.codeView.setFontFamily(codeFont.defaultFamily()) 191 174 self.codeView.setCurrentFont(codeFont) … … 193 176 self.codeView.setMinimumSize(300, 300) 194 177 self.codeView.setAcceptRichText(False) 178 PythonHighlighter(self.codeView.document()) 195 179 self.outputView = QTextEdit() 196 180 self.outputView.setMinimumSize(300, 300) … … 286 270 global app 287 271 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") 289 273 print "save image as ", fileName 290 274 if fileName is not None and len(fileName) > 0: … … 419 403 420 404 # Set the mouse position 405 # TODO: Get correct mouse position 421 406 #window = self.currentView.window() 422 407 pt = 0, 0 # window.mouseLocationOutsideOfEventStream() … … 427 412 my = self.currentView.bounds()[1][1] - my 428 413 self.namespace["MOUSEX"], self.namespace["MOUSEY"] = mx, my 429 #self.namespace["mousedown"] = Q tGui.QApplication.mouseButtons() & QtCore.Qt.LeftButton > 0414 #self.namespace["mousedown"] = QApplication.mouseButtons() & Qt.LeftButton 430 415 #self.namespace["keydown"] = self.currentView.keydown 431 416 #self.namespace["key"] = self.currentView.key … … 522 507 pass 523 508 sys.argv = saveArgv 524 self._flushOutput(output)525 509 return True, output 526 510 … … 580 564 def __init__(self, args): 581 565 QApplication.__init__(self, args) 566 loadConfig() 582 567 self.documents = [] 583 568 if sys.platform == "win32": -
nodebox/branches/try-qt/nodebox/util/__init__.py
r205 r284 55 55 56 56 You can use wildcards to specify which files to pick, e.g. 57 f = files('*. gif')57 f = files('*.png') 58 58 """ 59 59 from glob import glob
