def icon(self, act): settings = QSettings() iconSet = settings.value("toolbar/iconset", QtReduceDefaults.ICONSET) iconSize = settings.value("toolbar/iconsize", QtReduceDefaults.ICONSIZE) if iconSet: iEntry = self.db[iconSet] text = act.iconText() entry = None if text in iEntry.keys(): entry = iEntry[text] path = '' if entry: path = sys.path[0] + "/icons/" + iconSet + "/" if iEntry["sized"]: path += str(iconSize) + "/" path += entry traceLogger.debug("iconPath=%s" % path) return QIcon(path) else: if mEntry == "open": return self.style().standardIcon(QStyle.SP_DialogOpenButton) elif mEntry == "save": return self.style().standardIcon(QStyle.SP_DialogSaveButton) elif mEntry == "abort": return self.style().standardIcon(QStyle.SP_BrowserStop) else: return QIcon('')
def __init__(self,reduce='../../bin/redcsl'): traceLogger.debug("######### reduce is %s", reduce) super(Reduce,self).__init__() self.__process = procNew(sys.path[0] + "/" + reduce) self.__processId = self.__process['processId'] self.__process = self.__process['handle'] self.__mutex = QMutex()
def compute(self,row,count=1): traceLogger.debug("row=%d, count=%d" % (row, count)) for i in range(row,row+count): computation = self.data(self.index(i,0),QtReduceModel.RawDataRole) signalLogger.debug("Emmitting %s" % computation.command) #self.startComputation.emit(computation) self.reduce.compute(computation)
def compute1(self,c): self.wait() traceLogger.debug("after wait, %s"% c) self.computation = c self.computation.status = QtReduceComputation.Evaluating self.startedComputations.append(self.computation) self.start()
def icon(self, act): settings = QSettings() iconSet = settings.value("toolbar/iconset",QtReduceDefaults.ICONSET) iconSize = settings.value("toolbar/iconsize", QtReduceDefaults.ICONSIZE) if iconSet: iEntry = self.db[iconSet] text = act.iconText() entry = None if text in iEntry.keys(): entry = iEntry[text] path = '' if entry: path = sys.path[0] + "/icons/" + iconSet + "/" if iEntry["sized"]: path += str(iconSize) + "/" path += entry traceLogger.debug("iconPath=%s" % path) return QIcon(path) else: if mEntry == "open": return self.style().standardIcon(QStyle.SP_DialogOpenButton) elif mEntry == "save": return self.style().standardIcon(QStyle.SP_DialogSaveButton) elif mEntry == "abort": return self.style().standardIcon(QStyle.SP_BrowserStop) else: return QIcon('')
def setTitle(self,fullPath): traceLogger.debug("fullPath=%s" % fullPath) if fullPath is '': self.setWindowTitle("[*]" + self.tr("Untitled")) else: info = QFileInfo(fullPath) self.setWindowFilePath(info.absolutePath()) self.setWindowTitle("[*]" + info.fileName())
def __setWidthByFont(self,n,adaptHeight=False): oldWidth = self.width() width = n * self.controller.view.fontMetrics().width('m') traceLogger.debug("width=%s, n=%s, family=%s, size=%s" % (width,n,self.controller.view.font().family(), self.controller.view.font().pointSize())) self.setFixedWidth(width) if adaptHeight: factor = float(self.width())/float(oldWidth) self.resize(1,int(self.height()*factor))
def renderResult(self,result): traceLogger.debug("result=%s" % result) if result.strip("\\0123456789 ") == '': return result.replace('\\ ','\\\n') command = "qr_render(" + result.rstrip("$") + ");" answer = self.model.reduce.reduce.compute(command) rendered = answer['pretext'] if rendered: rendered = rendered.strip("\n") traceLogger.debug("rendered=%s" % rendered) return rendered
def abortComputation(self): traceLogger.debug("entering") if self.queue: self.reduce.signal("SIGSTOP") ans = self.__abortComputationBox() self.reduce.signal("SIGCONT") if ans == 'cancel': return if ans == 'all': self.queue = [] self.computation.status = QtReduceComputation.Aborted self.reduce.signal("SIGINT")
def setupFont(self,size=None,step=1): traceLogger.debug("size=%s, step=%s" % (size,step)) if not size: size = self.font().pointSize() font = self.font() font.setFamily(QSettings().value("worksheet/fontfamily", QtReduceDefaults.FONTFAMILY)) font.setFixedPitch(True) font.setKerning(0) font.setWeight(QFont.Normal) font.setItalic(False) font.setPointSize(self.__nextGoodFontSize(font,size,step)) self.setFont(font)
def saveAs(self): title = self.tr("Save Reduce Worksheet") path = os.path.dirname(os.path.abspath(self.controller.fileName().__str__())) filter = self.tr("Reduce Worksheets (*.rws)") fileName = QFileDialog.getSaveFileName(self,title,path,filter) fileName = str(fileName[0]) traceLogger.debug("fileName=%s" % fileName) if fileName == '': return if not fileName.endswith(".rws"): fileName += ".rws" self.controller.saveAs(fileName) self.activateWindow()
def setupFont(self, size=None, step=1): traceLogger.debug("size=%s, step=%s" % (size, step)) if not size: size = self.font().pointSize() font = self.font() font.setFamily(QSettings().value("worksheet/fontfamily", QtReduceDefaults.FONTFAMILY)) font.setFixedPitch(True) font.setKerning(0) font.setWeight(QFont.Normal) font.setItalic(False) font.setPointSize(self.__nextGoodFontSize(font, size, step)) self.setFont(font)
def __textToToolButtonStyle(self,show): traceLogger.debug("show=%s,('%s', '%s', '%s')" % (show, self.tr("Symbol and Text"), self.tr("Only Symbol"), self.tr("Only Text"))) if show == self.tr("Symbol and Text"): return Qt.ToolButtonTextUnderIcon if show == self.tr("Only Symbol"): return Qt.ToolButtonIconOnly if show == self.tr("Only Text"): return Qt.ToolButtonTextOnly traceLogger.warning("unknown tool button style '%s'" % show) return Qt.ToolButtonTextUnderIcon
def __init__(self,parent=None): super(QtReducePreferencesToolBar,self).__init__(parent) settings = QSettings() toolBarGroup = QGroupBox(self.tr("Toolbar")) self.iconSetCombo = QtReduceComboBox() iDbKeys = QtReduceIconSets().db.keys() iDbKeys.sort() self.iconSetCombo.addItems(iDbKeys) settings.setValue("toolbar/iconset","Oxygen") # Hack traceLogger.debug("toolbar/iconset=%s" % settings.value("toolbar/iconset")) self.iconSetCombo.setCurrentIndex( self.iconSetCombo.findText( settings.value("toolbar/iconset",QtReduceDefaults.ICONSET))) self.iconSizeCombo = QtReduceIconSizeComboBox() self.iconSizeCombo.addItems(["16","22","32"]) self.iconSizeCombo.setCurrentIndex( self.iconSizeCombo.findText( str(settings.value("toolbar/iconsize", QtReduceDefaults.ICONSIZE)))) self.showCombo = QtReduceComboBox() self.showCombo.addItems([self.tr("Symbol and Text"), self.tr("Only Symbol"), self.tr("Only Text")]) self.showCombo.setCurrentIndex(self.showCombo.findText( settings.value("toolbar/buttonstyle", self.tr(QtReduceDefaults.BUTTONSTYLE)))) toolBarLayout = QFormLayout() # toolBarLayout.addRow(self.tr("Symbol Set"),self.iconSetCombo) toolBarLayout.addRow(self.tr("Symbol Size"),self.iconSizeCombo) toolBarLayout.addRow(self.tr("Show"),self.showCombo) toolBarGroup.setLayout(toolBarLayout) mainLayout = QVBoxLayout() mainLayout.addWidget(toolBarGroup) self.setLayout(mainLayout)
def __init__(self,parent=None): super(QtReduceToolBar,self).__init__(parent) buttonStyle = QSettings().value("toolbar/buttonstyle", self.tr(QtReduceDefaults.BUTTONSTYLE)) self.setToolButtonStyleByText(buttonStyle) iconSize = QSettings().value("toolbar/iconsize", QtReduceDefaults.ICONSIZE) traceLogger.debug("2######### QtReduceDefaults.ICONSIZE is %s", QtReduceDefaults.ICONSIZE) traceLogger.debug("2######### iconSize is %s", iconSize) self.setIconSize(QSize(int(iconSize),int(iconSize))) self.setContextMenuPolicy(Qt.CustomContextMenu) self.customContextMenuRequested.connect(self.contextMenu) self.setVisible(True)
def open(self): ok = self.__suggestSave() if not ok: return title = self.tr("Open Reduce Worksheet") fn = self.controller.fileName().__str__() if fn == '': fn = '$HOME' path = os.path.dirname(os.path.abspath(fn)) traceLogger.debug("path=%s" % path) filter = self.tr("Reduce Worksheets (*.rws);;All Files (*.*)") fileName = QFileDialog.getOpenFileName(self,title,path,filter) fileName = str(fileName[0]) traceLogger.debug("fileName=%s" % fileName) if fileName is '': return if not fileName.endswith(".rws"): fileName += ".rws" return self.controller.open(fileName)
def __init__(self,parent=None): QStatusBar.__init__(self,parent) self.symbolic = None font = self.font() traceLogger.debug(font.pointSize()) if os.uname()[0] == "Darwin": font.setPointSize(font.pointSize() - 2) self.setFont(font) self.reduceMode = QLabel() self.reduceMode.setFixedWidth( QFontMetrics(font).width(self.tr("Mode: Algebraic"))) self.reduceMode.setFont(font) self.reduceTime = QLabel() self.reduceTime.setFont(font) self.reduceStatus = QLabel() self.reduceStatus.setFont(font) self.addPermanentWidget(self.reduceMode) self.addPermanentWidget(self.reduceTime) self.addWidget(self.reduceStatus) self.reduceStatus.setText(self.tr("Initializing ..."))
def pruneSelection(self): cursor = self.textCursor() if not cursor.hasSelection(): return if cursor.hasComplexSelection(): cursor.clearSelection() self.setTextCursor(cursor) return s = cursor.selectionStart() e = cursor.selectionEnd() sp = self.__positionPair(s) ep = self.__positionPair(e) traceLogger.debug("start=%d in %s, end=%d in %s" % (s,sp,e,ep)) if sp == ep: return c = cursor.position() cp = self.__positionPair(c) traceLogger.debug("cursor=%d in %s" % (c,cp)) cursor.clearSelection() self.setTextCursor(cursor) return
def pruneSelection(self): cursor = self.textCursor() if not cursor.hasSelection(): return if cursor.hasComplexSelection(): cursor.clearSelection() self.setTextCursor(cursor) return s = cursor.selectionStart() e = cursor.selectionEnd() sp = self.__positionPair(s) ep = self.__positionPair(e) traceLogger.debug("start=%d in %s, end=%d in %s" % (s, sp, e, ep)) if sp == ep: return c = cursor.position() cp = self.__positionPair(c) traceLogger.debug("cursor=%d in %s" % (c, cp)) cursor.clearSelection() self.setTextCursor(cursor) return
def __init__(self, parent=None): super(QtReduceMainWindow, self).__init__(parent) iconSize = QSettings().value("toolbar/iconsize", QtReduceDefaults.ICONSIZE) traceLogger.debug("0######### QtReduceDefaults.ICONSIZE is %s", QtReduceDefaults.ICONSIZE) traceLogger.debug("0######### iconSize is %s", iconSize) hugo = QSettings().value("toolbar/hugo", QtReduceDefaults.ICONSIZE) traceLogger.debug("0######### hugo is %s", hugo) if os.uname()[0] != "Darwin": # For the Mac the icon is set for the app in qreduce.py. self.setWindowIcon(QIcon(sys.path[0] + "/" + "Bumblebee.png")) self.setUnifiedTitleAndToolBarOnMac(True) self.controller = QtReduceController(self) self.setCentralWidget(self.controller.view) self.__createPreferences() self.__initTitleBar() self.__createStatusBar() self.recentFileMenu = QtRecentFileMenu(self) self.controller.fileNameChanged.connect(self.recentFileMenu.addFile) self.__createActions() self.__createMenus() self.__createToolBar() self.__resizeByFont(QtReduceDefaults.WIDTH, QtReduceDefaults.HEIGHT) self.raise_() self.show() self.rawModelView = QtReduceTableView(self) self.rawModelView.setModel(self.controller.model)
def setCell(self,row,computation): self.view.setCell(row, computation.c1, computation.command, computation.c2, computation.result, computation.c3) s = computation.status if s == QtReduceComputation.NotEvaluated: self.view.setNotEvaluated(row) elif s == QtReduceComputation.Evaluated: if computation.result: result = computation.result if not computation.symbolic: result = self.renderResult(result) self.view.setResult(row,result) else: self.view.setNoResult(row) elif s == QtReduceComputation.Error: self.view.setError(row,computation.errorText) elif s == QtReduceComputation.Aborted: self.view.setAborted(row) else: traceLogger.debug("Bad status: %d" % s)
def rowsRemovedM(self,parent,start,end): traceLogger.debug("start=%d, end=%d" % (start, end)) self.view.removeRows(start,end)
def rowsInsertedM(self,parent,start,end): traceLogger.debug("start=%d, end=%d" % (start, end)) self.view.insertRows(start,end)
def currentSizeChangedHandlerFs(self, newSize, fullScreen): newSize = int(newSize) traceLogger.debug("newSize=%s (%s)" % (newSize, type(newSize))) QSettings().setValue("worksheet/fontsizefs", newSize) if fullScreen: self.setupFont(newSize)
def run(self): traceLogger.debug("entering") c = self.computation.command traceLogger.debug("computing %s" % c) a = self.reduce.compute(c) traceLogger.debug("answer is %s" % a) self.computation.processAnswer(a,self.accTime,self.accGcTime) self.accTime = self.computation.accTime self.accGcTime = self.computation.accGcTime traceLogger.debug("processed computation is %s" % self.computation) self.finishedComputations.append(self.computation) traceLogger.debug("appended to finishedComputations") if self.computation.status == QtReduceComputation.Error: a = self.reduce.compute(" 0.0.") traceLogger.debug("error recovery %s" % a) traceLogger.debug("leaving")
def currentSizeChangedHandlerFs(self,newSize,fullScreen): newSize = int(newSize) traceLogger.debug("newSize=%s (%s)" % (newSize,type(newSize))) QSettings().setValue("worksheet/fontsizefs",newSize) if fullScreen: self.setupFont(newSize)
def addComputation(self,computation): traceLogger.debug("%s" % computation) self.insertRow(self.rowCount(QModelIndex()),QModelIndex()) self.model[-1] = computation