Example #1
0
    def updateExportBackground(self, colorname):
        """Update color on export background."""
        pixmap = qt4.QPixmap(16, 16)
        col = utils.extendedColorToQColor(colorname)
        pixmap.fill(col)

        # update button (storing color in button itself - what fun!)
        self.exportBackgroundButton.setIcon(qt4.QIcon(pixmap))
        self.exportBackgroundButton.iconcolor = colorname
Example #2
0
    def checkPlotUpdate(self):
        """Check whether plot needs updating."""

        # print >>sys.stderr, "checking update"
        # no threads, so can't get interrupted here
        # draw data into background pixmap if modified
        if (self.zoomfactor != self.oldzoom
                or self.document.changeset != self.docchangeset
                or self.pagenumber != self.oldpagenumber):

            # print >>sys.stderr, "updating"
            self.pickeritem.hide()

            self.pagenumber = min(self.document.getNumberPages() - 1,
                                  self.pagenumber)
            self.oldpagenumber = self.pagenumber

            if self.pagenumber >= 0:
                size = self.document.pageSize(self.pagenumber,
                                              scaling=self.zoomfactor)

                # draw the data into the buffer
                # errors cause an exception window to pop up
                try:
                    phelper = document.PaintHelper(size,
                                                   scaling=self.zoomfactor,
                                                   dpi=self.dpi)
                    self.document.paintTo(phelper, self.pagenumber)

                except Exception:
                    # stop updates this time round and show exception dialog
                    d = exceptiondialog.ExceptionDialog(sys.exc_info(), self)
                    self.oldzoom = self.zoomfactor
                    self.docchangeset = self.document.changeset
                    d.exec_()

                self.painthelper = phelper
                self.rendercontrol.addJob(phelper)
            else:
                self.painthelper = None
                self.pagenumber = 0
                size = self.document.docSize()
                pixmap = qt4.QPixmap(*size)
                pixmap.fill(setting.settingdb.color('page'))
                self.setSceneRect(0, 0, *size)
                self.pixmapitem.setPixmap(pixmap)

            self.emit(qt4.SIGNAL("sigUpdatePage"), self.pagenumber)
            self.updatePageToolbar()

            self.updateControlGraphs(self.lastwidgetsselected)
            self.oldzoom = self.zoomfactor
            self.docchangeset = self.document.changeset
Example #3
0
 def _pagedocsize(self, widget, dpi, scaling, integer):
     """Helper for page or doc size."""
     if dpi is None:
         p = qt4.QPixmap(1, 1)
         dpi = (p.logicalDpiX(), p.logicalDpiY())
     helper = painthelper.PaintHelper((1, 1), dpi=dpi, scaling=scaling)
     w = widget.settings.get('width').convert(helper)
     h = widget.settings.get('height').convert(helper)
     if integer:
         return int(w), int(h)
     else:
         return w, h
Example #4
0
    def getPreviewPixmap(self, ds):
        """Get a preview pixmap for a dataset."""
        size = (140, 70)
        if ds.dimensions != 1 or ds.datatype != "numeric":
            return None

        pixmap = qt4.QPixmap(*size)
        pixmap.fill(qt4.Qt.transparent)
        p = qt4.QPainter(pixmap)
        p.setRenderHint(qt4.QPainter.Antialiasing)

        # calculate data points
        try:
            if len(ds.data) < size[1]:
                y = ds.data
            else:
                intvl = len(ds.data) / size[1] + 1
                y = ds.data[::intvl]
            x = N.arange(len(y))

            # plot data points on image
            minval, maxval = N.nanmin(y), N.nanmax(y)
            y = (y - minval) / (maxval - minval) * size[1]
            finite = N.isfinite(y)
            x, y = x[finite], y[finite]
            x = x * (1. / len(x)) * size[0]

            poly = qt4.QPolygonF()
            utils.addNumpyToPolygonF(poly, x, size[1] - y)
            p.setPen(qt4.QPen(qt4.Qt.blue))
            p.drawPolyline(poly)

            # draw x axis if span 0
            p.setPen(qt4.QPen(qt4.Qt.black))
            if minval <= 0 and maxval > 0:
                y0 = size[1] - (0 - minval) / (maxval - minval) * size[1]
                p.drawLine(x[0], y0, x[-1], y0)
            else:
                p.drawLine(x[0], size[1], x[-1], size[1])
            p.drawLine(x[0], 0, x[0], size[1])

        except (ValueError, ZeroDivisionError):
            # zero sized array after filtering or min == max, so return None
            p.end()
            return None

        p.end()
        return pixmap
Example #5
0
    def identifyWidgetAtPoint(self, x, y, antialias=True):
        """What widget has drawn at the point x,y?

        Returns the widget drawn last on the point, or None if it is
        an empty part of the page.
        root is the root widget to recurse from
        if antialias is true, do test for antialiased drawing
        """
        
        # make a small image filled with a specific color
        box = 3
        specialcolor = qt4.QColor(254, 255, 254)
        origpix = qt4.QPixmap(2*box+1, 2*box+1)
        origpix.fill(specialcolor)
        origimg = origpix.toImage()
        # store most recent widget here
        lastwidget = [None]
        
        def rendernextstate(state):
            """Recursively draw painter.

            Checks whether drawing a widgetchanges the small image
            around the point given.
            """

            pixmap = qt4.QPixmap(origpix)
            painter = qt4.QPainter(pixmap)
            painter.setRenderHint(qt4.QPainter.Antialiasing, antialias)
            painter.setRenderHint(qt4.QPainter.TextAntialiasing, antialias)
            # this makes the small image draw from x-box->x+box, y-box->y+box
            # translate would get overriden by coordinate system playback
            painter.setWindow(x-box,y-box,box*2+1,box*2+1)
            state.record.play(painter)
            painter.end()
            newimg = pixmap.toImage()

            if newimg != origimg:
                lastwidget[0] = state.widget

            for child in state.children:
                rendernextstate(child)

        rendernextstate(self.rootstate)
        return lastwidget[0]
Example #6
0
        def rendernextstate(state):
            """Recursively draw painter.

            Checks whether drawing a widgetchanges the small image
            around the point given.
            """

            pixmap = qt4.QPixmap(origpix)
            painter = qt4.QPainter(pixmap)
            painter.setRenderHint(qt4.QPainter.Antialiasing, antialias)
            painter.setRenderHint(qt4.QPainter.TextAntialiasing, antialias)
            # this makes the small image draw from x-box->x+box, y-box->y+box
            # translate would get overriden by coordinate system playback
            painter.setWindow(x-box,y-box,box*2+1,box*2+1)
            state.record.play(painter)
            painter.end()
            newimg = pixmap.toImage()

            if newimg != origimg:
                lastwidget[0] = state.widget

            for child in state.children:
                rendernextstate(child)
Example #7
0
def makeSplashLogo():
    '''Make a splash screen logo.'''
    border = 16
    xw, yw = 520, 240
    pix = qt4.QPixmap(xw, yw)
    pix.fill()
    p = qt4.QPainter(pix)

    # draw logo on pixmap
    logo = utils.getPixmap('logo.png')
    p.drawPixmap(xw / 2 - logo.width() / 2, border, logo)

    # add copyright text
    doc = qt4.QTextDocument()
    doc.setPageSize(qt4.QSizeF(xw, yw - 3 * border - logo.height()))
    f = qt4.qApp.font()
    f.setPointSize(14)
    doc.setDefaultFont(f)
    doc.setDefaultTextOption(qt4.QTextOption(qt4.Qt.AlignCenter))
    doc.setHtml(splashcopyr % utils.version())
    p.translate(0, 2 * border + logo.height())
    doc.drawContents(p)
    p.end()
    return pix
Example #8
0
 def updateButtonColors(self):
     """Update color icons on color buttons."""
     for name, val in self.chosencolors.iteritems():
         pixmap = qt4.QPixmap(16, 16)
         pixmap.fill(val)
         self.colorbutton[name].setIcon(qt4.QIcon(pixmap))
Example #9
0
    def __init__(self, document, parent, menu=None):
        """Initialise the window.

        menu gives a menu to add any menu items to
        """

        qt4.QGraphicsView.__init__(self, parent)
        self.setBackgroundRole(qt4.QPalette.Dark)
        self.scene = qt4.QGraphicsScene()
        self.setScene(self.scene)

        # this graphics scene item is the actual graph
        pixmap = qt4.QPixmap(1, 1)
        self.dpi = (pixmap.logicalDpiX(), pixmap.logicalDpiY())
        self.pixmapitem = self.scene.addPixmap(pixmap)

        # whether full screen mode
        self.isfullscreen = False

        # set to be parent's actions
        self.vzactions = None

        # for controlling plot elements
        g = self.controlgraphgroup = qt4.QGraphicsItemGroup()
        g.setHandlesChildEvents(False)
        self.scene.addItem(g)

        # zoom rectangle for zooming into graph (not shown normally)
        self.zoomrect = self.scene.addRect(0, 0, 100, 100,
                                           qt4.QPen(qt4.Qt.DotLine))
        self.zoomrect.setZValue(2.)
        self.zoomrect.hide()

        # picker graphicsitem for marking the picked point
        self.pickeritem = PickerCrosshairItem()
        self.scene.addItem(self.pickeritem)
        self.pickeritem.setZValue(2.)
        self.pickeritem.hide()

        # all the widgets that picker key-navigation might cycle through
        self.pickerwidgets = []

        # the picker state
        self.pickerinfo = widgets.PickInfo()

        # set up so if document is modified we are notified
        self.document = document
        self.docchangeset = -100
        self.oldpagenumber = -1
        self.connect(self.document, qt4.SIGNAL("sigModified"),
                     self.slotDocModified)

        # state of last plot from painthelper
        self.painthelper = None

        self.lastwidgetsselected = []
        self.oldzoom = -1.
        self.zoomfactor = 1.
        self.pagenumber = 0
        self.ignoreclick = False

        # for rendering plots in separate threads
        self.rendercontrol = RenderControl(self)
        self.connect(self.rendercontrol, qt4.SIGNAL("renderfinished"),
                     self.slotRenderFinished)

        # mode for clicking
        self.clickmode = 'select'
        self.currentclickmode = None

        # wheel zooming accumulator
        self.sumwheeldelta = 0

        # set up redrawing timer
        self.timer = qt4.QTimer(self)
        self.connect(self.timer, qt4.SIGNAL('timeout()'), self.checkPlotUpdate)

        # for drag scrolling
        self.grabpos = None
        self.scrolltimer = qt4.QTimer(self)
        self.scrolltimer.setSingleShot(True)

        # for turning clicking into scrolling after a period
        self.connect(self.scrolltimer, qt4.SIGNAL('timeout()'),
                     self.slotBecomeScrollClick)

        # get plot view updating policy
        #  -1: update on document changes
        #   0: never update automatically
        #  >0: check for updates every x ms
        self.interval = setting.settingdb['plot_updatepolicy']

        # if using a time-based document update checking, start timer
        if self.interval > 0:
            self.timer.start(self.interval)

        # load antialias settings
        self.antialias = setting.settingdb['plot_antialias']

        # allow window to get focus, to allow context menu
        self.setFocusPolicy(qt4.Qt.StrongFocus)

        # get mouse move events if mouse is not pressed
        self.setMouseTracking(True)

        # create toolbar in main window (urgh)
        self.createToolbar(parent, menu)
Example #10
0
def getPixmap(pixmap):
    """Return a cached QPixmap for the filename in the icons directory."""
    if pixmap not in _pixmapcache:
        _pixmapcache[pixmap] = qt4.QPixmap(os.path.join(imagedir, pixmap))
    return _pixmapcache[pixmap]