def sizeHint(self): """Return size hint for window.""" p = self.pixmapitem.pixmap() if p.width() <= 1 and p.height() <= 1: # if the document has been uninitialized, get the doc size return qt4.QSize(*self.document.docSize()) return p.size()
def _initText(self, text): """Setup MML document and draw it in recording paint device.""" self.error = '' self.size = qt4.QSize(1, 1) if not mmlsupport: self.mmldoc = None self.error = 'Error: MathML support not built\n' return self.mmldoc = doc = qtmml.QtMmlDocument() try: self.mmldoc.setContent(text) except ValueError, e: self.mmldoc = None self.error = ('Error interpreting MathML: %s\n' % unicode(e)) return
def exportSVG(self): """Export document as SVG""" if qt4.PYQT_VERSION >= 0x40600: # custom paint devices don't work in old PyQt versions dpi = svg_export.dpi * 1. size = self.doc.pageSize(self.pagenumber, dpi=(dpi, dpi), integer=False) f = open(self.filename, 'w') paintdev = svg_export.SVGPaintDevice( f, size[0] / dpi, size[1] / dpi, writetextastext=self.svgtextastext) painter = qt4.QPainter(paintdev) self.renderPage(size, (dpi, dpi), painter) f.close() else: # use built-in svg generation, which doesn't work very well # (no clipping, font size problems) import PyQt4.QtSvg dpi = 90. size = self.doc.pageSize(self.pagenumber, dpi=(dpi, dpi), integer=False) # actually paint the image gen = PyQt4.QtSvg.QSvgGenerator() gen.setFileName(self.filename) gen.setResolution(dpi) gen.setSize(qt4.QSize(int(size[0]), int(size[1]))) painter = qt4.QPainter(gen) self.renderPage(size, (dpi, dpi), painter)
def accept(self): """Keep settings if okay pressed.""" qt4.QDialog.accept(self) # view settings setdb = setting.settingdb setdb['plot_updatepolicy'] = (self.plotwindow.updateintervals[ self.intervalCombo.currentIndex()][0]) setdb['plot_antialias'] = self.antialiasCheck.isChecked() setdb['ui_english'] = self.englishCheck.isChecked() setdb['plot_numthreads'] = self.threadSpinBox.value() # use cwd setdb['dirname_usecwd'] = self.cwdCheck.isChecked() # update icon size if necessary iconsize = int(self.iconSizeCombo.currentText()) if iconsize != setdb['toolbar_size']: setdb['toolbar_size'] = iconsize for widget in self.parent().children(): # find toolbars if isinstance(widget, qt4.QToolBar): widget.setIconSize(qt4.QSize(iconsize, iconsize)) # update dpi if possible # FIXME: requires some sort of visual notification of validator for cntrl, setn in ((self.exportDPI, 'export_DPI'), (self.exportDPIPDF, 'export_DPI_PDF')): try: text = cntrl.currentText() valid = cntrl.validator().validate(text, 0)[0] if valid == qt4.QValidator.Acceptable: setdb[setn] = int(text) except ValueError: pass # export settings setdb['export_antialias'] = self.exportAntialias.isChecked() setdb['export_quality'] = self.exportQuality.value() setdb['export_color'] = { 0: True, 1: False }[self.exportColor.currentIndex()] setdb['export_background'] = self.exportBackgroundButton.iconcolor setdb['export_SVG_text_as_text'] = self.exportSVGTextAsText.isChecked() # new document settings setdb['stylesheet_default'] = unicode(self.styleLineEdit.text()) setdb['custom_default'] = unicode(self.customLineEdit.text()) # colors for name, color in self.chosencolors.iteritems(): isdefault = self.colordefaultcheck[name].isChecked() colorname = unicode(color.name()) setdb['color_' + name] = (isdefault, colorname) # plugins plugins = [unicode(x) for x in self.pluginmodel.stringList()] setdb['plugins'] = plugins self.plotwindow.updatePlotSettings() # write settings out now, rather than wait until the end setdb.writeSettings()
def _constructToolbarMenu(self): """Add items to edit/add graph toolbar and menu.""" iconsize = setting.settingdb['toolbar_size'] self.addtoolbar.setIconSize( qt4.QSize(iconsize, iconsize) ) self.edittoolbar.setIconSize( qt4.QSize(iconsize, iconsize) ) self.addslots = {} self.vzactions = actions = self.parentwin.vzactions for widgettype in ('page', 'grid', 'graph', 'axis', 'xy', 'bar', 'fit', 'function', 'boxplot', 'image', 'contour', 'vectorfield', 'key', 'label', 'colorbar', 'rect', 'ellipse', 'imagefile', 'line', 'polygon', 'polar', 'ternary', 'nonorthpoint', 'nonorthfunc'): wc = document.thefactory.getWidgetClass(widgettype) slot = utils.BoundCaller(self.slotMakeWidgetButton, wc) self.addslots[wc] = slot actionname = 'add.' + widgettype actions[actionname] = utils.makeAction( self, wc.description, _('Add %s') % widgettype, slot, icon='button_%s' % widgettype) a = utils.makeAction actions.update({ 'edit.cut': a(self, _('Cut the selected widget'), _('Cu&t'), self.slotWidgetCut, icon='veusz-edit-cut', key='Ctrl+X'), 'edit.copy': a(self, _('Copy the selected widget'), _('&Copy'), self.slotWidgetCopy, icon='kde-edit-copy', key='Ctrl+C'), 'edit.paste': a(self, _('Paste widget from the clipboard'), _('&Paste'), self.slotWidgetPaste, icon='kde-edit-paste', key='Ctrl+V'), 'edit.moveup': a(self, _('Move the selected widget up'), _('Move &up'), utils.BoundCaller(self.slotWidgetMove, -1), icon='kde-go-up'), 'edit.movedown': a(self, _('Move the selected widget down'), _('Move d&own'), utils.BoundCaller(self.slotWidgetMove, 1), icon='kde-go-down'), 'edit.delete': a(self, _('Remove the selected widget'), _('&Delete'), self.slotWidgetDelete, icon='kde-edit-delete'), 'edit.rename': a(self, _('Renames the selected widget'), _('&Rename'), self.slotWidgetRename, icon='kde-edit-rename'), 'add.shapemenu': a(self, _('Add a shape to the plot'), _('Shape'), self.slotShowShapeMenu, icon='veusz-shape-menu'), }) # add actions to menus for adding widgets and editing addact = [('add.'+w) for w in ('page', 'grid', 'graph', 'axis', 'xy', 'nonorthpoint', 'bar', 'fit', 'function', 'nonorthfunc', 'boxplot', 'image', 'contour', 'vectorfield', 'key', 'label', 'colorbar', 'polar', 'ternary')] menuitems = [ ('insert', '', addact + [ ['insert.shape', 'Add shape', ['add.rect', 'add.ellipse', 'add.line', 'add.imagefile', 'add.polygon'] ]]), ('edit', '', [ 'edit.cut', 'edit.copy', 'edit.paste', 'edit.moveup', 'edit.movedown', 'edit.delete', 'edit.rename' ]), ] utils.constructMenus( self.parentwin.menuBar(), self.parentwin.menus, menuitems, actions ) # create shape toolbar button # attach menu to insert shape button actions['add.shapemenu'].setMenu(self.parentwin.menus['insert.shape']) # add actions to toolbar to create widgets utils.addToolbarActions(self.addtoolbar, actions, addact + ['add.shapemenu']) # add action to toolbar for editing utils.addToolbarActions(self.edittoolbar, actions, ('edit.cut', 'edit.copy', 'edit.paste', 'edit.moveup', 'edit.movedown', 'edit.delete', 'edit.rename')) self.connect( self.parentwin.menus['edit.select'], qt4.SIGNAL('aboutToShow()'), self.updateSelectMenu )
def createToolbar(self, parent, menu=None): """Make a view toolbar, and optionally update menu.""" self.viewtoolbar = qt4.QToolBar(_("View toolbar - Veusz"), parent) self.viewtoolbar.setObjectName('veuszviewtoolbar') iconsize = setting.settingdb['toolbar_size'] self.viewtoolbar.setIconSize(qt4.QSize(iconsize, iconsize)) self.viewtoolbar.hide() if parent: parent.addToolBar(qt4.Qt.TopToolBarArea, self.viewtoolbar) if parent and hasattr(parent, 'vzactions'): # share actions with parent if possible # as plot windows can be isolated from mainwindows, we need this self.vzactions = actions = parent.vzactions else: self.vzactions = actions = {} a = utils.makeAction actions.update({ 'view.zoomin': a(self, _('Zoom into the plot'), _('Zoom &In'), self.slotViewZoomIn, icon='kde-zoom-in', key='Ctrl++'), 'view.zoomout': a(self, _('Zoom out of the plot'), _('Zoom &Out'), self.slotViewZoomOut, icon='kde-zoom-out', key='Ctrl+-'), 'view.zoom11': a(self, _('Restore plot to natural size'), _('Zoom 1:1'), self.slotViewZoom11, icon='kde-zoom-1-veuszedit', key='Ctrl+1'), 'view.zoomwidth': a(self, _('Zoom plot to show whole width'), _('Zoom to width'), self.slotViewZoomWidth, icon='kde-zoom-width-veuszedit'), 'view.zoomheight': a(self, _('Zoom plot to show whole height'), _('Zoom to height'), self.slotViewZoomHeight, icon='kde-zoom-height-veuszedit'), 'view.zoompage': a(self, _('Zoom plot to show whole page'), _('Zoom to page'), self.slotViewZoomPage, icon='kde-zoom-page-veuszedit'), 'view.zoommenu': a(self, _('Zoom functions menu'), _('Zoom'), self.doZoomMenuButton, icon='kde-zoom-veuszedit'), 'view.prevpage': a(self, _('Move to the previous page'), _('&Previous page'), self.slotViewPreviousPage, icon='kde-go-previous', key='Ctrl+PgUp'), 'view.nextpage': a(self, _('Move to the next page'), _('&Next page'), self.slotViewNextPage, icon='kde-go-next', key='Ctrl+PgDown'), 'view.select': a(self, _('Select items from the graph or scroll'), _('Select items or scroll'), None, icon='kde-mouse-pointer'), 'view.pick': a(self, _('Read data points on the graph'), _('Read data points'), None, icon='veusz-pick-data'), 'view.zoomgraph': a(self, _('Zoom into graph'), _('Zoom graph'), None, icon='veusz-zoom-graph'), 'view.fullscreen': a(self, _('View plot full screen'), _('Full screen'), self.slotFullScreen, icon='veusz-view-fullscreen', key='Ctrl+F11'), }) if menu: # only construct menu if required menuitems = [ ('view', '', [ 'view.zoomin', 'view.zoomout', 'view.zoom11', 'view.zoomwidth', 'view.zoomheight', 'view.zoompage', '', 'view.prevpage', 'view.nextpage', 'view.fullscreen', '', 'view.select', 'view.pick', 'view.zoomgraph', ]), ] utils.constructMenus(menu, {'view': menu}, menuitems, actions) # populate menu on zoom menu toolbar icon zoommenu = qt4.QMenu(self) zoomag = qt4.QActionGroup(self) for act in ('view.zoomin', 'view.zoomout', 'view.zoom11', 'view.zoomwidth', 'view.zoomheight', 'view.zoompage'): a = actions[act] zoommenu.addAction(a) zoomag.addAction(a) a.vzname = act actions['view.zoommenu'].setMenu(zoommenu) self.connect(zoomag, qt4.SIGNAL('triggered(QAction*)'), self.zoomActionTriggered) lastzoom = setting.settingdb.get('view_defaultzoom', 'view.zoompage') self.updateZoomMenuButton(actions[lastzoom]) # add items to toolbar utils.addToolbarActions( self.viewtoolbar, actions, ('view.prevpage', 'view.nextpage', 'view.fullscreen', 'view.select', 'view.pick', 'view.zoomgraph', 'view.zoommenu')) # define action group for various different selection models grp = self.selectactiongrp = qt4.QActionGroup(self) grp.setExclusive(True) for a in ('view.select', 'view.pick', 'view.zoomgraph'): actions[a].setActionGroup(grp) actions[a].setCheckable(True) actions['view.select'].setChecked(True) self.connect(grp, qt4.SIGNAL('triggered(QAction*)'), self.slotSelectMode) return self.viewtoolbar
def sizeHint(self): """A reasonable size for the text editor.""" return qt4.QSize(self.spacing * 30, self.spacing * 20)