def insertWidgets(canvasDlg, catmenu, categoriesPopup, catName): #print 'Widget Registry is \n\n' + unicode(widgetRegistry) + '\n\n' widgets = None #print unicode(canvasDlg.widgetRegistry['templates']) try: for wName in redRObjects.widgetRegistry()['widgets'].keys( ): ## move across all of the widgets in the widgetRegistry. This is different from the templates that are tagged as templates widgetInfo = redRObjects.widgetRegistry()['widgets'][wName] try: if unicode( catName ) in widgetInfo.tags: # add the widget, wtags is the list of tags in the widget, catName is the name of the category that we are adding icon = QIcon(widgetInfo.icon) act = catmenu.addAction(icon, widgetInfo.name) act.widgetInfo = widgetInfo act.category = catmenu if not widgetInfo.name in categoriesPopup.widgetActionNameList: categoriesPopup.allActions.append(act) categoriesPopup.widgetActionNameList.append( widgetInfo.name) except Exception as inst: redRLog.log(redRLog.REDRCORE, redRLog.ERROR, redRLog.formatException()) pass except Exception as inst: redRLog.log(redRLog.REDRCORE, redRLog.ERROR, 'Exception in Tabs with widgetRegistry %s' % inst)
def constructCategoriesPopup(canvasDlg): global categoriesPopup categoriesPopup = CanvasPopup(canvasDlg) categoriesPopup.setStyleSheet( """ QMenu { background-color: #fffff0; selection-background-color: blue; } QMenu::item:disabled { color: #dddddd } QMenu::separator {height: 1px; background: #dddddd; margin-left: 3px; margin-right: 4px;}""" ) # tfile = os.path.abspath(redREnviron.directoryNames['redRDir'] + '/tagsSystem/tags.xml') # f = open(tfile, 'r') # mainTabs = xml.dom.minidom.parse(f) # f.close() mainTabs = redRObjects.widgetRegistry()['tags'] treeXML = mainTabs.childNodes[0] #print treeXML.childNodes for itab in treeXML.childNodes: if itab.nodeName == 'group': #picked a group element catmenu = categoriesPopup.addMenu( unicode(itab.getAttribute('name'))) categoriesPopup.catActions.append( catmenu) # put the catmenu in the categoriespopup insertChildActions(canvasDlg, catmenu, categoriesPopup, itab) insertWidgets(canvasDlg, catmenu, categoriesPopup, unicode(itab.getAttribute('name'))) # print redREnviron.settings["WidgetTabs"] try: for category, show in redREnviron.settings["WidgetTabs"]: if not show or not redRObjects.widgetRegistry().has_key(category): continue catmenu = categoriesPopup.addMenu(category) categoriesPopup.catActions.append(catmenu) #print canvasDlg.widgetRegistry[category] for widgetInfo in sorted( redRObjects.widgetRegistry()[category].values(), key=lambda x: x.priority): icon = QIcon(widgetInfo.icon) act = catmenu.addAction(icon, widgetInfo.name) act.widgetInfo = widgetInfo act.category = catmenu #categoriesPopup.allActions.append(act) except Exception as inst: redRLog.log(redRLog.REDRCORE, redRLog.ERROR, redRLog.formatException()) ### Add the templates to the popup, these should be actions with a function that puts a templates icon and loads the template for template in redRObjects.widgetRegistry()['templates']: try: icon = QIcon( os.path.join(redREnviron.directoryNames['picsDir'], 'Default.png')) act = catmenu.addAction(icon, template.name) act.templateInfo = template categoriesPopup.templateActions.append(act) except Exception as inst: redRLog.log(redRLog.REDRCORE, redRLog.ERROR, redRLog.formatException())
def reloadWidgets(self): # should have a way to set the desired tab location redRObjects.readCategories(force=True) redREnviron.addOrangeDirectoriesToPath(redREnviron.directoryNames) signals.registerRedRSignals() redRGUI.registerQTWidgets() self.canvas.createWidgetsToolbar(redRObjects.widgetRegistry()) self.searchBox2.setItems(redRObjects.widgetRegistry()['widgets'], redRObjects.widgetRegistry()['templates']) self.searchBox3.setItems(redRObjects.widgetRegistry()['widgets'], redRObjects.widgetRegistry()['templates'])
def __init__(self, widget, label=_('Search'),orientation='horizontal', items = {}, toolTip = None, width = -1, callback = None, **args): redRlineEdit.__init__(self, widget = widget, label = label, displayLabel=False, orientation = orientation, toolTip = toolTip, width = width, **args) self.setStyleSheet("QLineEdit {border: 2px solid grey; border-radius: 10px; padding: 0 8px;margin-right:60px; selection-background-color: darkgray;}") self.listWidget = myQListView() self.listWidget.setMouseTracking(1) self.listWidget.installEventFilter(self) self.listWidget.setWindowFlags(Qt.Popup) self.listWidget.setFocusPolicy(Qt.NoFocus) self.listWidget.setResizeMode(QListView.Fixed) self.listWidget.setUniformItemSizes(True) de = HTMLDelegate(self) self.model = QStandardItemModel(self) self.listWidget.setModel(self.model) self.listWidget.setItemDelegate(de) self.listWidget.setSelectionMode(QAbstractItemView.SingleSelection) self.listWidget.setSelectionBehavior(QAbstractItemView.SelectItems) # QObject.connect(self.listWidget, SIGNAL("itemClicked (QListWidgetItem *)"), self.doneCompletion) QObject.connect(self.listWidget, SIGNAL("activated ( QModelIndex )"), self.doneCompletion) QObject.connect(self.listWidget, SIGNAL("selectionChanged ( QItemSelection , QItemSelection ) "), self.doneCompletion) QObject.connect(self, SIGNAL('returnPressed()'), self.doneCompletion) QObject.connect(self, SIGNAL("textEdited(const QString &)"), self.textEdited) self.enteredText = "" self.itemList = [] self.useRE = 0 if not callback: self.callbackOnComplete = self.searchCallback else: self.callbackOnComplete = callback self.listUpdateCallback = None self.autoSizeListWidget = 0 self.nrOfSuggestions = 10 self.minTextLength = 1 self.caseSensitive = 0 self.matchAnywhere = 1 self.autoSizeListWidget = 1 self.useRE=0 self.maxResults = 10 self.descriptionSize = 100 self.listWidget.setAlternatingRowColors(True) self.delimiters = ' ' # by default, we only allow selection of one element self.itemsAsStrings = [] # a list of strings that appear in the list widget self.itemsAsItems = {} # can be a list of QListWidgetItems or a list of strings (the same as self.itemsAsStrings) self.setToolTip(_('Search for widgets and templates by typing directly.')) self.setItems(redRObjects.widgetRegistry()['widgets'], redRObjects.widgetRegistry()['templates'])
def searchCallback(self, widgetInfo): print widgetInfo qApp.canvasDlg.schema.addWidget( redRObjects.widgetRegistry()['widgets'][ widgetInfo.fileName]) # add the correct widget to the schema self.clear() # clear the line edit for the next widget return
def constructCategoriesPopup(canvasDlg): global categoriesPopup categoriesPopup = CanvasPopup(canvasDlg) categoriesPopup.setStyleSheet(""" QMenu { background-color: #fffff0; selection-background-color: blue; } QMenu::item:disabled { color: #dddddd } QMenu::separator {height: 1px; background: #dddddd; margin-left: 3px; margin-right: 4px;}""") # tfile = os.path.abspath(redREnviron.directoryNames['redRDir'] + '/tagsSystem/tags.xml') # f = open(tfile, 'r') # mainTabs = xml.dom.minidom.parse(f) # f.close() mainTabs = redRObjects.widgetRegistry()['tags'] treeXML = mainTabs.childNodes[0] #print treeXML.childNodes for itab in treeXML.childNodes: if itab.nodeName == 'group': #picked a group element catmenu = categoriesPopup.addMenu(unicode(itab.getAttribute('name'))) categoriesPopup.catActions.append(catmenu) # put the catmenu in the categoriespopup insertChildActions(canvasDlg, catmenu, categoriesPopup, itab) insertWidgets(canvasDlg, catmenu, categoriesPopup, unicode(itab.getAttribute('name'))) # print redREnviron.settings["WidgetTabs"] try: for category, show in redREnviron.settings["WidgetTabs"]: if not show or not redRObjects.widgetRegistry().has_key(category): continue catmenu = categoriesPopup.addMenu(category) categoriesPopup.catActions.append(catmenu) #print canvasDlg.widgetRegistry[category] for widgetInfo in sorted(redRObjects.widgetRegistry()[category].values(), key=lambda x:x.priority): icon = QIcon(widgetInfo.icon) act = catmenu.addAction(icon, widgetInfo.name) act.widgetInfo = widgetInfo act.category = catmenu #categoriesPopup.allActions.append(act) except Exception as inst: redRLog.log(redRLog.REDRCORE, redRLog.ERROR,redRLog.formatException()) ### Add the templates to the popup, these should be actions with a function that puts a templates icon and loads the template for template in redRObjects.widgetRegistry()['templates']: try: icon = QIcon(os.path.join(redREnviron.directoryNames['picsDir'], 'Default.png')) act = catmenu.addAction(icon, template.name) act.templateInfo = template categoriesPopup.templateActions.append(act) except Exception as inst: redRLog.log(redRLog.REDRCORE, redRLog.ERROR,redRLog.formatException())
def searchCallback(self, info, c): """The default search callback, this is run when the return or enter key is pressed after passing through the doneCompletion argument""" if c == 't': redRSaveLoad.loadTemplate(info.file) elif c == 'w': redRObjects.addWidget(redRObjects.widgetRegistry()['widgets'][info.fileName]) # add the correct widget to the schema self.clear() # clear the line edit for the next widget return
def addWidgetInstanceByFileName(name, settings=None, inputs=None, outputs=None, id=None): widget = redRObjects.widgetRegistry()['widgets'][name] return redRObjects.addInstance(signalManager, widget, settings, inputs, outputs, id)
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
def reloadWidgets( self): # should have a way to set the desired tab location self.widgetRegistry = orngRegistry.readCategories() redREnviron.addOrangeDirectoriesToPath(redREnviron.directoryNames) signals.registerRedRSignals() redRGUI.registerQTWidgets() self.canvas.createWidgetsToolbar(self.widgetRegistry) self.searchBox2.setItems(redRObjects.widgetRegistry()['widgets'])
def updateMenu(self): self.clear() self.addWidgetSuggest() for c in self.candidates: for category, show in redREnviron.settings["WidgetTabs"]: if not show or not redRObjects.widgetRegistry().has_key(category): continue if c in redRObjects.widgetRegistry()[category]: widgetInfo = redRObjects.widgetRegistry()[category][c] icon = QIcon(widgetInfo.icon) act = self.addAction(icon, widgetInfo.name) act.widgetInfo = widgetInfo self.quickActions.append(act) break self.categoriesYOffset = self.sizeHint().height() self.addSeparator() for m in self.catActions: self.addMenu(m)
def insertWidgets(canvasDlg, catmenu, categoriesPopup, catName): #print 'Widget Registry is \n\n' + unicode(widgetRegistry) + '\n\n' widgets = None #print unicode(canvasDlg.widgetRegistry['templates']) try: for wName in redRObjects.widgetRegistry()['widgets'].keys(): ## move across all of the widgets in the widgetRegistry. This is different from the templates that are tagged as templates widgetInfo = redRObjects.widgetRegistry()['widgets'][wName] try: if unicode(catName) in widgetInfo.tags: # add the widget, wtags is the list of tags in the widget, catName is the name of the category that we are adding icon = QIcon(widgetInfo.icon) act = catmenu.addAction(icon, widgetInfo.name) act.widgetInfo = widgetInfo act.category = catmenu if not widgetInfo.name in categoriesPopup.widgetActionNameList: categoriesPopup.allActions.append(act) categoriesPopup.widgetActionNameList.append(widgetInfo.name) except Exception as inst: redRLog.log(redRLog.REDRCORE, redRLog.ERROR,redRLog.formatException()) pass except Exception as inst: redRLog.log(redRLog.REDRCORE, redRLog.ERROR, 'Exception in Tabs with widgetRegistry %s' % inst)
def __init__(self, canvasDlg): QMenu.__init__(self, canvasDlg) self.allActions = [] self.templateActions = [] self.widgetActionNameList = [] self.catActions = [] self.quickActions = [] self.candidates = [] self.canvasDlg = canvasDlg cats = redRObjects.widgetRegistry() self.suggestDict = {} #dict([(widget.name, widget) for widget in reduce(lambda x,y: x+y, [cat.values() for cat in cats.values()])]) ## gives an error in linux self.suggestItems = [QListWidgetItem(QIcon(widget.info), widget.name) for widget in self.suggestDict.values()] self.categoriesYOffset = 0
def loadWidgets180(widgets, loadingProgressBar, loadedSettingsDict, tmp): print 'loading widget using 1.80 settings' lpb = 0 loadedOk = 1 failureText = '' addY = minimumY() for widget in widgets.getElementsByTagName("widget"): try: name = widget.getAttribute("widgetName") if name in redRObjects.widgetRegistry()['widgets']: widgetInfo = redRObjects.widgetRegistry()['widgets'][name] else: widgetInfo = redRObjects.widgetRegistry()['widgets']['base_dummy'] widgetID = widget.getAttribute('widgetID') settings = cPickle.loads(loadedSettingsDict[widgetID]['settings']) inputs = cPickle.loads(loadedSettingsDict[widgetID]['inputs']) outputs = cPickle.loads(loadedSettingsDict[widgetID]['outputs']) xPos = int(widget.getAttribute('xPos')) yPos = int(widget.getAttribute('yPos')) caption = unicode(widget.getAttribute('caption')) ## for backward compatibility we need to make both the widgets and the instances. #addWidgetInstanceByFileName(name, settings, inputs, outputs) widgetInfo = redRObjects.widgetRegistry()['widgets'][name] if tmp: widgetID += '_'+str(sessionID) #schemaDoc.addWidget(widgetInfo, x= xPos, y= yPos, caption = caption, widgetSettings = settings, forceInSignals = inputs, forceOutSignals = outputs, id = widgetID) newwidget = redRObjects.addWidget(widgetInfo, x = xPos, y = yPos, caption = caption, widgetSettings = settings, forceInSignals = inputs, forceOutSignals = outputs, wid = widgetID) #instanceID = redRObjects.addInstance(widgetInfo, settings = settings, insig = inputs, outsig = outputs, wid = widgetID) #newwidget = redRObjects.newIcon(redRObjects.activeCanvas(), redRObjects.activeTab(), widgetInfo, redRStyle.defaultWidgetIcon, canvasDlg, instanceID = instanceID, tabName = redRObjects.activeTabName()) if newwidget not in redRObjects._widgetInstances.keys(): raise Exception('widget instance not in instance keys') lpb += 1 loadingProgressBar.setValue(lpb) except Exception as inst: redRLog.log(redRLog.REDRCORE, redRLog.ERROR, redRLog.formatException()) print unicode(inst), _('Widget load failure 180') return (loadedOk, failureText)
def getSuggestWidgets(outWidget): # import pprint # pp = pprint.PrettyPrinter(indent=4) # pp.pprint(hDict) actions = [] try: topCons = getTopConnections(outWidget) #print topCons widgets = redRObjects.widgetRegistry()['widgets'] for con in topCons: if con in widgets.keys(): wInfo = widgets[con] actions.append(wInfo) except: redRLog.log(redRLog.REDRCORE,redRLog.WARNING,_('The widget use history is corrupt. Please delete it.')) redRLog.log(redRLog.REDRCORE,redRLog.DEBUG,redRLog.formatException()) return actions
def searchCallback(self): qApp.canvasDlg.schema.addWidget( redRObjects.widgetRegistry()['widgets'][unicode( self.text())]) # add the correct widget to the schema self.clear() # clear the line edit for the next widget #text = unicode(self.widgetSuggestEdit.text()) # if '.rrts' in text: ## this is a template, we should load this and not add the widget # for action in self.templateActions: # if action.templateInfo.name == text: # redRSaveLoad.loadTemplate(action.templateInfo.file) # return # else: ## if there isn't a .rrts in the filename then we should proceed as normal # for action in self.actions: # move through all of the actions in the actions list # if action.widgetInfo.name == text: # find the widget (action) that has the correct name, note this finds the first instance. Widget names must be unique ??? should we allow multiple widgets with the same name ??? probably not. # self.widgetInfo = action.widgetInfo # self.canvas.schema.addWidget(action.widgetInfo) # add the correct widget to the schema # self.widgetSuggestEdit.clear() # clear the line edit for the next widget # return return
def loadWidgets180(widgets, loadingProgressBar, loadedSettingsDict, tmp): lpb = 0 loadedOk = 1 failureText = '' addY = minimumY() for widget in widgets.getElementsByTagName("widget"): try: name = widget.getAttribute("widgetName") widgetID = widget.getAttribute('widgetID') settings = cPickle.loads(loadedSettingsDict[widgetID]['settings']) inputs = cPickle.loads(loadedSettingsDict[widgetID]['inputs']) outputs = cPickle.loads(loadedSettingsDict[widgetID]['outputs']) xPos = int(widget.getAttribute('xPos')) yPos = int(widget.getAttribute('yPos')) caption = unicode(widget.getAttribute('caption')) ## for backward compatibility we need to make both the widgets and the instances. #addWidgetInstanceByFileName(name, settings, inputs, outputs) widgetInfo = redRObjects.widgetRegistry()['widgets'][name] if tmp: widgetID += '_' + str(sessionID) schemaDoc.addWidget(widgetInfo, x=xPos, y=yPos, caption=caption, widgetSettings=settings, forceInSignals=inputs, forceOutSignals=outputs, id=widgetID) #print _('Settings'), settings lpb += 1 loadingProgressBar.setValue(lpb) except Exception as inst: redRLog.log(redRLog.REDRCORE, redRLog.ERROR, redRLog.formatException()) print unicode(inst), _('Widget load failure 180') return (loadedOk, failureText)
def __init__(self, widget, label=_('Search'), orientation='horizontal', items=[], toolTip=None, width=-1, callback=None, **args): redRlineEditHint.__init__(self, widget=widget, label=label, displayLabel=True, orientation=orientation, items=items, toolTip=toolTip, width=width, callback=self.searchCallback, **args) self.setStyleSheet( "QLineEdit {border: 2px solid grey; border-radius: 10px; padding: 0 8px;margin-right:60px; selection-background-color: darkgray;}" ) self.searchBox = redRSearchDialog() QObject.connect(self, SIGNAL('returnPressed()'), self.searchDialog) self.caseSensitive = 0 self.matchAnywhere = 1 self.autoSizeListWidget = 1 widgetList = [] for wName, widgetInfo in redRObjects.widgetRegistry()['widgets'].items( ): x = QListWidgetItem(QIcon(widgetInfo.icon), unicode(wName)) widgetList.append(x) self.setItems(widgetList)
def __init__(self, app, parent = None, flags = 0): QMainWindow.__init__(self, parent) print "starting canvas dlg" self.setWindowTitle(_("Red-R Canvas %s") % redREnviron.version['REDRVERSION']) if os.path.exists(redRStyle.canvasIcon): self.setWindowIcon(QIcon(redRStyle.canvasIcon)) ############################### #####Start splashWindow#### ############################### logo = QPixmap(redRStyle.redRLogo) splashWindow = QSplashScreen(logo, Qt.WindowStaysOnTopHint) splashWindow.setMask(logo.mask()) splashWindow.show() ############################### #####Notes and output Docks#### ############################### self.notesDock = QDockWidget(_('Notes')) self.notesDock.setObjectName(_('CanvasNotes')) self.notes = redRTextEdit(None, label = _('Notes')) self.notes.setMinimumWidth(200) redRSaveLoad.setNotesWidget(self.notes) self.notesDock.setWidget(self.notes) self.addDockWidget(Qt.RightDockWidgetArea, self.notesDock) self.connect(self.notesDock,SIGNAL('visibilityChanged(bool)'),self.updateDock) print "connected notes dock" self.outputDock = QDockWidget(_('Output')) self.outputDock.setObjectName(_('CanvasOutput')) outbox = redRwidgetBox(None) self.printOutput = redRTextEdit(outbox, label = _('Output'),displayLabel=False, editable=False) hbox = redRwidgetBox(outbox,orientation='horizontal',alignment=Qt.AlignLeft) redRbutton(hbox, label = _('Save Output'), callback = self.saveOutputToFile) redRbutton(hbox, label = _('Clear Output'), callback = lambda: self.printOutput.clear()) if redREnviron.settings["writeLogFile"]: redRbutton(hbox, label = _('Show in Browser'), callback = lambda: redRLog.fileLogger.showLogFile()) self.outputDock.setWidget(outbox) self.addDockWidget(Qt.BottomDockWidgetArea, self.outputDock) self.connect(self.outputDock,SIGNAL('visibilityChanged(bool)'),self.updateDock) #redRLog.setOutputWindow(self.printOutput) redRLog.setOutputManager('dock', self.dockOutputManger) ####################### #####Output Manager#### ####################### # self.output = redROutput.OutputWindow(self) # redRLog.setOutputManager('window', self.output.outputManager) ################### #Register Widgets## ################### self.widgetRegistry = redRObjects.widgetRegistry() # the widget registry has been created print 'Register widgets' import redRGUI redRGUI.registerQTWidgets() # signals.registerRedRSignals() ################### #Main Cavas######## ################### splashWindow.showMessage(_("Main Cavas"), Qt.AlignHCenter + Qt.AlignBottom) self.schema = orngDoc.SchemaDoc(self) self.setCentralWidget(self.schema) self.schema.setFocus() ################### #Toolbar and Menu## ################### splashWindow.showMessage(_("Creating Menu and Toolbar"), Qt.AlignHCenter + Qt.AlignBottom) self.toolbar = self.addToolBar(_("Toolbar")) self.toolbarFunctions = redRCanvasToolbar.redRCanvasToolbarandMenu(self,self.toolbar) self.toolbarFunctions.updateStyle() ###################### #Create Widgets Dock## ###################### self.widgetDock = QDockWidget(_('Widgets')) self.widgetDock.setObjectName('widgetDock') self.widgetDockBox = redRwidgetBox(None) self.widgetDockBox.setMinimumWidth(200) self.widgetDock.setWidget(self.widgetDockBox) self.addDockWidget(Qt.LeftDockWidgetArea, self.widgetDock) self.connect(self.widgetDock,SIGNAL('visibilityChanged(bool)'),self.updateDock) self.widgetsToolBar = redRWidgetsTree.WidgetTree(self.widgetDockBox, self, self.widgetRegistry) self.suggestButtonsList = redRWidgetsTree.widgetSuggestions(self.widgetDockBox,self) # self.createWidgetsToolbar() # also creates the categories popup # self.toolbar.addWidget(self.widgetsToolBar.widgetSuggestEdit) ## kind of a hack but there you are. ################### #####Status Bar#### ################### splashWindow.showMessage(_("Creating Status Bar"), Qt.AlignHCenter + Qt.AlignBottom) self.statusBar = QStatusBar() self.statusBar.setSizeGripEnabled(False) self.setStatusBar(self.statusBar) docBox = redRwidgetBox(None,orientation='horizontal',spacing=4) self.showWidgetToolbar = redRbutton(docBox, '',toggleButton=True, icon=redRStyle.defaultWidgetIcon, toolTip=_('Widget Tree'), callback = self.updateDockState) self.showROutputButton = redRbutton(docBox, '',toggleButton=True, icon=redRStyle.canvasIcon, toolTip=_('Log'), callback = self.updateDockState) self.showNotesButton = redRbutton(docBox, '',toggleButton=True, icon=redRStyle.notesIcon, toolTip=_('Notes'), callback = self.updateDockState) self.statusBar.addPermanentWidget(docBox) if 'dockState' in redREnviron.settings.keys() and 'widgetBox' in redREnviron.settings['dockState'].keys(): self.showNotesButton.setChecked(redREnviron.settings['dockState']['notesBox']) self.showROutputButton.setChecked(redREnviron.settings['dockState']['outputBox']) self.showWidgetToolbar.setChecked(redREnviron.settings['dockState']['widgetBox']) ################### ##Reports########## ################### splashWindow.showMessage(_("Creating Reports"), Qt.AlignHCenter + Qt.AlignBottom) self.reports = redRReports.reports(self,self.schema) ################### ##Update Manager### ################### # splashWindow.showMessage(_("Creating Update Manager"), Qt.AlignHCenter + Qt.AlignBottom) # self.updateManager = redRUpdateManager.updateManager(self) ######################## #Load Windows Settings## ######################## splashWindow.showMessage(_("Setting States"), Qt.AlignHCenter + Qt.AlignBottom) if 'windowState' in redREnviron.settings.keys(): self.restoreState(redREnviron.settings['windowState']) if 'geometry' in redREnviron.settings.keys(): self.restoreGeometry(redREnviron.settings['geometry']) if 'size' in redREnviron.settings.keys(): self.resize(redREnviron.settings['size']) else: # center window in the desktop # in newer versions of Qt we can also find the center of a primary screen # on multiheaded desktops width, height = redREnviron.settings.get("canvasWidth", 700), redREnviron.settings.get("canvasHeight", 600) desktop = app.desktop() deskH = desktop.screenGeometry(desktop.primaryScreen()).height() deskW = desktop.screenGeometry(desktop.primaryScreen()).width() h = max(0, deskH/2 - height/2) # if the window is too small, resize the window to desktop size w = max(0, deskW/2 - width/2) self.move(w,h+2) self.resize(width,height) if 'pos' in redREnviron.settings.keys(): self.move(redREnviron.settings['pos']) ######################### #Show Main Red-R window## ######################### self.show() redRSaveLoad.setCanvasDlg(self) redRObjects.setCanvasDlg(self) if splashWindow: splashWindow.hide() ######################### #First Load## ######################### try: if 'firstLoad' not in redREnviron.settings.keys(): redREnviron.settings['firstLoad'] = True if redREnviron.settings['firstLoad']: redRInitWizard.startSetupWizard() except: redRLog.log(redRLog.REDRCORE, redRLog.ERROR, redRLog.formatException()) pass ####################### #####packageManager#### ####################### self.packageManager = redRPackageManager.packageManager(self) if redREnviron.settings['checkForPackageUpdates'] and self.packageManager.updatesAvailable(auto=True): self.packageManager.exec_() print "Processing events" #qApp.processEvents() print "events processed"
def __init__(self, widget, label=_('Search'), orientation='horizontal', items={}, toolTip=None, width=-1, callback=None, **args): lineEdit.__init__(self, widget=widget, label=label, displayLabel=False, orientation=orientation, toolTip=toolTip, width=width, **args) QObject.connect(self, SIGNAL("textEdited(const QString &)"), self.textEdited) self.setStyleSheet( "QLineEdit {border: 2px solid grey; border-radius: 10px; padding: 0 8px;margin-right:60px; selection-background-color: darkgray;}" ) self.listWidget = myQListView() self.listWidget.setMouseTracking(1) self.listWidget.installEventFilter(self) self.listWidget.setWindowFlags(Qt.Popup) self.listWidget.setFocusPolicy(Qt.NoFocus) self.listWidget.setResizeMode(QListView.Fixed) self.listWidget.setUniformItemSizes(True) de = HTMLDelegate(self) self.model = QStandardItemModel(self) self.listWidget.setModel(self.model) self.listWidget.setItemDelegate(de) self.listWidget.setSelectionMode(QAbstractItemView.SingleSelection) self.listWidget.setSelectionBehavior(QAbstractItemView.SelectItems) # QObject.connect(self.listWidget, SIGNAL("itemClicked (QListWidgetItem *)"), self.doneCompletion) QObject.connect(self.listWidget, SIGNAL("activated ( QModelIndex )"), self.doneCompletion) QObject.connect( self.listWidget, SIGNAL("selectionChanged ( QItemSelection , QItemSelection ) "), self.doneCompletion) QObject.connect(self, SIGNAL("textEdited(const QString &)"), self.textEdited) self.enteredText = "" self.itemList = [] self.useRE = 0 self.callbackOnComplete = self.searchCallback self.listUpdateCallback = None self.autoSizeListWidget = 0 self.nrOfSuggestions = 10 self.minTextLength = 1 self.caseSensitive = 0 self.matchAnywhere = 1 self.autoSizeListWidget = 1 self.useRE = 0 self.maxResults = 10 self.descriptionSize = 100 self.listWidget.setAlternatingRowColors(True) self.delimiters = ' ' # by default, we only allow selection of one element self.itemsAsStrings = [ ] # a list of strings that appear in the list widget self.itemsAsItems = { } # can be a list of QListWidgetItems or a list of strings (the same as self.itemsAsStrings) self.setItems(redRObjects.widgetRegistry()['widgets'])
def addWidgetInstanceByFileName(name, settings = None, inputs = None, outputs = None, wid = None): widget = redRObjects.widgetRegistry()['widgets'][name] return redRObjects.addInstance(widget, settings, inputs, outputs, wid)
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)