def uploadException(self,err): """Upload an exception to the website""" try: """Ask if the error can be uploaded. Unless the user doesn't want to be bothered with asking.""" if not redREnviron.settings['askToUploadError']: res = redREnviron.settings['uploadError'] else: import redRQTCore self.msg = redRQTCore.dialog(parent=qApp.canvasDlg,title='Red-R Error') error = redRQTCore.widgetBox(self.msg,orientation='vertical') redRQTCore.widgetLabel(error, label='Do you wish to report the Error Log?') buttons = redRQTCore.widgetBox(error,orientation='horizontal') redRQTCore.button(buttons, label = _('Yes'), callback = self.uploadYes) redRQTCore.button(buttons, label = _('No'), callback = self.uploadNo) self.checked = False self.remember = redRQTCore.checkBox(error,label='response', displayLabel=None, buttons=[_('Remember my Response')],callback=self.rememberResponse) res = self.msg.exec_() redREnviron.settings['uploadError'] = res """If errors can be uploaded then send them""" if res == 1: # print 'in res' err['version'] = redREnviron.version['SVNVERSION'] err['type'] = redREnviron.version['TYPE'] err['redRversion'] = redREnviron.version['REDRVERSION'] if os.name == 'nt': err['os'] = 'Windows' if redREnviron.settings['canContact']: err['email'] = redREnviron.settings['email'] params = urllib.urlencode(err) headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"} conn = httplib.HTTPConnection("red-r.org",80) conn.request("POST", "/errorReport.php", params,headers) log(REDRCORE, INFO, '<strong>Error data posted to the server</strong>') else: return except: pass
def mouseReleaseEvent(self, ev): point = self.mapToScene(ev.pos()) if self.widgetSelectionRect: # select widgets in rectangle widgets = self.getItemsAtPos(self.widgetSelectionRect, orngCanvasItems.CanvasWidget) for widget in self.doc.widgets(): widget.setSelected(widget in widgets) self.widgetSelectionRect.hide() self.widgetSelectionRect = None # if we are moving a widget if self.bWidgetDragging: validPos = True for item in self.getSelectedWidgets(): items = self.scene().collidingItems(item) validPos = validPos and (self.findItemTypeCount(items, orngCanvasItems.CanvasWidget) == 0) for item in self.getSelectedWidgets(): if not validPos: item.restorePosition() item.updateTooltip() item.setAllLinesFinished(True) # if we are drawing line elif self.tempLine: # show again the empty input/output boxes #redRLog.log(redRLog.REDRCORE, redRLog.INFO, 'setting line') for widget in self.doc.widgets(): widget.resetLeftRightEdges() start = self.tempLine.startWidget or self.tempLine.widget ## marks the starting of the tempLine end = self.tempLine.endWidget or self.tempLine.widget ## marks the ending of the tempLine self.tempLine.hide() self.tempLine = None # we must check if we have really connected some output to input if start and end and start != end: #redRLog.log(redRLog.REDRCORE, redRLog.INFO, 'setting start and end') self.doc.addLine(start, end) else: """If the user is drawing a line and simply drops the line on a point then we would like to place a widget there, as we assume that the user wanted to actually connect the line to something. There is a copy of the searchbar located in the redRCanvasToolbar.redRCanvasToolbarandMenu.SearchBox3 attribute. We simply want to show this toolbar at approximately the widget location.""" newCoords = QPoint(ev.globalPos()) # find where the pointer ended. import redRQTCore, redRCanvasToolbar dialog = redRQTCore.dialog(None, title = "Widget Lookup") def searchCallback(info, c, x = point.x(), y = point.y(), start = start, end = end, self = self, dialog = dialog): import redRObjects if c == 'w': newWidget = redRObjects.addWidget(redRObjects.widgetRegistry()['widgets'][info.fileName], x = x, y = y) # add the correct widget to the schema nw = redRObjects.getWidgetByIDActiveTabOnly(newWidget) self.doc.addLine(start or nw, end or nw) dialog.accept() return searchBox = redRCanvasToolbar.SearchBox2(dialog, width = 500, callback = searchCallback) searchBox.setItems(redRObjects.widgetRegistry()['widgets'], []) dialog.exec_() del searchBox del dialog ##state = [self.doc.widgets()[i].widgetInfo.name for i in range(min(len(self.doc.widgets()), 5))] ##predictedWidgets = orngHistory.predictWidgets(state, 20) #newCoords = QPoint(ev.globalPos()) #self.doc.widgetPopupMenu.updateMenu() #action = self.doc.widgetPopupMenu.exec_(newCoords- QPoint(0, self.doc.widgetPopupMenu.categoriesYOffset)) #if action and hasattr(action, "widgetInfo"): #xOff = -48 * bool(end) #newWidget = self.doc.addWidget(action.widgetInfo, point.x()+xOff, point.y()-24) #if newWidget != None: #nw = redRObjects.getWidgetByIDActiveTabOnly(newWidget) #if self.doc.signalManager.signalProcessingInProgress: #QMessageBox.information( self, _("Red-R Canvas"), _("Unable to connect widgets while signal processing is in progress. Please wait.")) #else: #self.doc.addLine(start or nw, end or nw) elif ev.button() == Qt.RightButton: activeItem = self.scene().itemAt(point) diff = self.mouseDownPosition - point if not activeItem and (diff.x()**2 + diff.y()**2) < 25: # if no active widgets and we pressed and released mouse at approx same position import redRQTCore, redRCanvasToolbar dialog = redRQTCore.dialog(None, title = "Widget Lookup") def searchCallback(info, c, x = point.x(), y = point.y(), self = self, dialog = dialog): import redRObjects if c == 'w': newWidget = redRObjects.addWidget(redRObjects.widgetRegistry()['widgets'][info.fileName], x = x, y = y) # add the correct widget to the schema #nw = redRObjects.getWidgetByIDActiveTabOnly(newWidget) #self.doc.addLine(start or nw, end or nw) dialog.accept() return searchBox = redRCanvasToolbar.SearchBox2(dialog, width = 500, callback = searchCallback) searchBox.setItems(redRObjects.widgetRegistry()['widgets'], []) dialog.exec_() #newCoords = QPoint(ev.globalPos()) #self.doc.widgetPopupMenu.showAllWidgets() ##state = [self.doc.widgets()[i].widgetInfo.name for i in range(min(len(self.doc.widgets()), 5))] ##predictedWidgets = orngHistory.predictWidgets(state, 20) ##self.doc.widgetPopupMenu.updatePredictedWidgets(predictedWidgets, 'inputClasses') #self.doc.widgetPopupMenu.updateMenu() #height = sum([self.doc.widgetPopupMenu.actionGeometry(action).height() for action in self.doc.widgetPopupMenu.actions()]) #action = self.doc.widgetPopupMenu.exec_(newCoords - QPoint(0, self.doc.widgetPopupMenu.categoriesYOffset)) #if action and hasattr(action, "widgetInfo"): #newWidget = self.doc.addWidget(action.widgetInfo, point.x(), point.y()) self.scene().update() self.bWidgetDragging = False self.doc.canvasDlg.widgetPopup.setEnabled(len(self.getSelectedWidgets()) == 1)
def createReportsMenu(self, widgets = None, schemaImage=True): qname = QFileDialog.getSaveFileName(self, _("Write Report to File"), redREnviron.directoryNames['documentsDir'] + "/Report-"+unicode(datetime.date.today())+".odt", "Open Office Text (*.odt);; HTML (*.html);; LaTeX (*.tex)") if qname.isEmpty(): return qname = unicode(qname) name = unicode(qname) # this is the file name of the Report # name = os.path.join(redREnviron.directoryNames['redRDir'],'restr.odt') if os.path.splitext(name)[1].lower() not in [".odt", ".html", ".tex"]: name = name + '.odt' fileDir = os.path.split(name)[0] try: fileDir2 = os.path.join(fileDir, os.path.splitext("Data-"+os.path.split(name)[1])[0]) fileDir2 = fileDir2.replace('\\', '/') fd3 = [] for p in fileDir2.split('/'): if len(p) > 8 and ' ' in p: fd3.append(p.replace(' ', '')[:6]+'~1') else: fd3.append(p) fileDir2 = '/'.join(fd3) if os.path.isdir(fileDir2): shutil.rmtree(fileDir2) # makes a file to place the temp data into. #This will be deleted once the odt file is made. os.mkdir(fileDir2) except Exception as inst: redRLog.log(redRLog.REDRCORE, redRLog.ERROR,redRLog.formatException()) # show the report list and allow the user to select widgets to include in the report. ## get the report info for the included widgets. # reportData = self.getReportData(fileDir2,name) if not widgets: import redRObjects import redRSignalManager widgets = redRObjects.instances() """The widgets may be stored in a seemingly random manner in the instances section. We would like to show the report in a way that makes sense. There is no real easy way to do this but the general plan that seems to work most often is to ensure that we don't make a report on a widget that has signaling widgets that aren't reported on yet. That is we report widgets as they send data. Note that this might not be the chronological order in which the analysis was carried out but it will be close to the order in which processing occurs from the data's point of view.""" widgetscopy = widgets widgetsnew = [] def copywidget(w, widgetscopy, widgetsnew): """Copies the widget to the right place.""" widgetscopy.remove(w) widgetsnew.append(w) def parentsIndexed(olist, widgetsnew): """Checks if the parent widgets have been indexed or not""" for o in olist: if o not in widgetsnew: return False return True while len(widgetscopy) > 0: for w in widgetscopy: if len(w.inputs.inputs.keys()) == 0 or len(redRSignalManager.getInputInstances(w)) == 0: copywidget(w, widgetscopy, widgetsnew) print 'Copy widget %s' % unicode(w) elif parentsIndexed(redRSignalManager.getInputInstances(w), widgetsnew): copywidget(w, widgetscopy, widgetsnew) print 'Copy widget %s' % unicode(w) print unicode(widgetsnew) print unicode(widgets) widgets = widgetsnew done = self.createReport(fileDir2,name,widgets,schemaImage) if not done: return if os.name =='nt': #os.startfile doneDialog = redRQTCore.dialog(self.schema,title=_("Report Generated")) redRQTCore.widgetLabel(doneDialog,label=_('Your report is ready to view.')) buttonBox = redRQTCore.widgetBox(doneDialog,orientation='horizontal') acceptButton = redRQTCore.button(buttonBox,_('View Report')) QObject.connect(acceptButton, SIGNAL("clicked()"), doneDialog.accept) acceptButton = redRQTCore.button(buttonBox,_('Done')) QObject.connect(acceptButton, SIGNAL("clicked()"), doneDialog.reject) if doneDialog.exec_() == QDialog.Accepted: try: os.startfile(name,'open') except: redRLog.log(redRLog.REDRCORE, redRLog.ERROR, redRLog.formatException()) mb = QMessageBox(_("Cannot Open File"), _("Red-R cannot open the reports file. Please open the file manually.\nThis is not a problem with Red-R, it is a problem with your document viewer."), QMessageBox.Information, QMessageBox.Ok | QMessageBox.Default, QMessageBox.NoButton, QMessageBox.NoButton,self) mb.exec_() else: QMessageBox.information(self, _("Red-R Canvas"), _("Your report is ready to view."), QMessageBox.Ok + QMessageBox.Default )