def toggleCursor(self): if self.cursor().shape() == QCursor(Qt.ArrowCursor).shape(): raw = QPixmap(":/gui/pics/pardusman-icon.png") raw.setMask(raw.mask()) self.setCursor(QCursor(raw, 2, 2)) else: self.unsetCursor()
def contextMenuEvent(self, event): #pos): popup_menu = self.textEdit.createStandardContextMenu() #pos) # Select the word under the cursor. cursor = self.textEdit.textCursor() cursor.select(QTextCursor.WordUnderCursor) self.textEdit.setTextCursor(cursor) # Check if the selected word is misspelled and offer spelling # suggestions if it is. if self.textEdit.textCursor().hasSelection(): text = unicode(self.textEdit.textCursor().selectedText()) if not self.dict.check(text): #print "o0mad to0 dict :D" spell_menu = QMenu(u'شاید منظورتان این بوده:') #print spell_menu for word in self.dict.suggest(text): action = SpellAction(word, spell_menu) action.correct.connect(self.correctWord) spell_menu.addAction(action) #print word # Only add the spelling suggests to the menu if there are # suggestions. print len(spell_menu.actions()) #print spell_menu.actions() if len(spell_menu.actions()) != 0: popup_menu.insertSeparator(popup_menu.actions()[0]) popup_menu.insertMenu(popup_menu.actions()[0], spell_menu) popup_menu.exec_(QCursor.pos( )) #self.textEdit.mapToGlobal(QPoint(0, 0)))#.globalPos())
def show_context_menu(self, point): idx = self.currentIndex() if idx and idx.isValid() and not idx.data(Qt.UserRole).toPyObject(): m = QMenu() m.addAction(QIcon(I('view.png')), _('View this cover at full size'), self.show_cover) m.exec_(QCursor.pos())
def show_context_menu(self, point): idx = self.currentIndex() if idx and idx.isValid() and not idx.data(Qt.UserRole).toPyObject(): m = QMenu() m.addAction(QIcon(I('view.png')), _('View this cover at full size'), self.show_cover) m.addAction(QIcon(I('edit-copy.png')), _('Copy this cover to clipboard'), self.copy_cover) m.exec_(QCursor.pos())
def contextMenuEvent(self, event):#pos): popup_menu = self.textEdit.createStandardContextMenu()#pos) # Select the word under the cursor. cursor = self.textEdit.textCursor() cursor.select(QTextCursor.WordUnderCursor) self.textEdit.setTextCursor(cursor) # Check if the selected word is misspelled and offer spelling # suggestions if it is. if self.textEdit.textCursor().hasSelection(): text = unicode(self.textEdit.textCursor().selectedText()) if not self.dict.check(text): #print "o0mad to0 dict :D" spell_menu = QMenu(u'شاید منظورتان این بوده:') #print spell_menu for word in self.dict.suggest(text): action = SpellAction(word, spell_menu) action.correct.connect(self.correctWord) spell_menu.addAction(action) #print word # Only add the spelling suggests to the menu if there are # suggestions. print len(spell_menu.actions()) #print spell_menu.actions() if len(spell_menu.actions()) != 0: popup_menu.insertSeparator(popup_menu.actions()[0]) popup_menu.insertMenu(popup_menu.actions()[0], spell_menu) popup_menu.exec_(QCursor.pos())#self.textEdit.mapToGlobal(QPoint(0, 0)))#.globalPos())
def start(self): self.setGeometry(0, 0, self.parent().width(), self.parent().height()) self.setVisible(True) # Prevent any actions from being triggerred by key presses self.parent().setEnabled(False) self.raise_() self.setFocus(Qt.OtherFocusReason) self.pi.startAnimation() QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
def showOrdContextMenu(self): menu = QMenu(self.segOrdListBox) if len(self.segOrdListBox.selectedItems())==0: return item = self.segOrdListBox.currentItem() deleteOrdMenuItem = menu.addAction("Delete Ordering") action = menu.exec_(QCursor.pos()) if action == deleteOrdMenuItem: self.deleteOrdItem(item)
def showSegContextMenu(self): menu = QMenu(self.segDefTableView) if len(self.segDefTableView.selectedIndexes())==0: return row = self.segDefTableView.selectedIndexes()[0].row() deleteSegMenuItem = menu.addAction("Delete Segment") action = menu.exec_(QCursor.pos()) if action == deleteSegMenuItem: self.deleteSegRow(row)
def set_waitcursor(self, on_or_off): """ For on_or_off True, set the main window waitcursor. For on_or_off False, revert to the prior cursor. """ if on_or_off: QApplication.setOverrideCursor( QCursor(Qt.WaitCursor) ) else: QApplication.restoreOverrideCursor() # Restore the cursor return
def updatepos(self): self.setUpdatesEnabled(False) pos = QCursor().pos() geometry = self.geometry() geometry.moveTo(pos.x() + self.CURSOR_OFFSET, pos.y() + self.CURSOR_OFFSET) intersected = geometry.intersected(self.screen_geometry) while True: if not intersected == geometry: #too big geometry = intersected self.isShrinked = True break if self.isShrinked: #enlarge geometry.setSize(self.orig_size) intersected = geometry.intersected(self.screen_geometry) if not intersected == geometry: self.isShrinked = True geometry = intersected else: self.isShrinked = False break break if geometry.intersects(self.screen_geometry): self.setGeometry(geometry) self.setUpdatesEnabled(True)
def showWaitCursor(on_or_off): """ Show the wait cursor or revert to the prior cursor if the current cursor is the wait cursor. For on_or_off True, set the main window waitcursor. For on_or_off False, revert to the prior cursor. [It might be necessary to always call it in matched pairs, I don't know [bruce 050401].] """ if on_or_off: QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) else: QApplication.restoreOverrideCursor() # Restore the cursor return
def _ok_or_preview(self, doneMsg=False, previewing=False): """ Private method. Do the Done or Preview operation (and set the Qt wait cursor while doing it), according to flags. """ ### REVIEW how to split this between GeneratorCommand and GeneratorPM, # and how to rename it then # [070724 code review] QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) self.win.assy.current_command_info(cmdname=self.cmdname) def aCallable(): self._build_struct(previewing=previewing) if doneMsg: env.history.message(self.cmd + self.done_msg()) self.handlePluginExceptions(aCallable) QApplication.restoreOverrideCursor() self.win.win_update()
def show_context_menu(self, point): item = self.currentItem() def key(k): sc = unicode( QKeySequence(k | Qt.CTRL).toString(QKeySequence.NativeText)) return ' [%s]' % sc if item is not None: m = QMenu() ci = unicode(item.data(0, Qt.DisplayRole).toString()) p = item.parent() or self.invisibleRootItem() idx = p.indexOfChild(item) if idx > 0: m.addAction(QIcon(I('arrow-up.png')), (_('Move "%s" up') % ci) + key(Qt.Key_Up), self.move_up) if idx + 1 < p.childCount(): m.addAction(QIcon(I('arrow-down.png')), (_('Move "%s" down') % ci) + key(Qt.Key_Down), self.move_down) m.addAction(QIcon(I('trash.png')), _('Remove all selected items'), self.del_items) if item.parent() is not None: m.addAction(QIcon(I('back.png')), (_('Unindent "%s"') % ci) + key(Qt.Key_Left), self.move_left) if idx > 0: m.addAction(QIcon(I('forward.png')), (_('Indent "%s"') % ci) + key(Qt.Key_Right), self.move_right) m.addAction(QIcon(I('edit_input.png')), _('Change the location this entry points to'), self.edit_item) m.addAction(_('Change all selected items to title case'), self.title_case) m.addAction(QIcon(I('modified.png')), _('Bulk rename all selected items'), self.bulk_rename) m.exec_(QCursor.pos())
def show_context_menu(self, point): item = self.currentItem() def key(k): sc = unicode(QKeySequence(k | Qt.CTRL).toString(QKeySequence.NativeText)) return ' [%s]'%sc if item is not None: m = QMenu() ci = unicode(item.data(0, Qt.DisplayRole).toString()) p = item.parent() or self.invisibleRootItem() idx = p.indexOfChild(item) if idx > 0: m.addAction(QIcon(I('arrow-up.png')), (_('Move "%s" up')%ci)+key(Qt.Key_Up), self.move_up) if idx + 1 < p.childCount(): m.addAction(QIcon(I('arrow-down.png')), (_('Move "%s" down')%ci)+key(Qt.Key_Down), self.move_down) m.addAction(QIcon(I('trash.png')), _('Remove all selected items'), self.del_items) if item.parent() is not None: m.addAction(QIcon(I('back.png')), (_('Unindent "%s"')%ci)+key(Qt.Key_Left), self.move_left) if idx > 0: m.addAction(QIcon(I('forward.png')), (_('Indent "%s"')%ci)+key(Qt.Key_Right), self.move_right) m.addAction(QIcon(I('edit_input.png')), _('Change the location this entry points to'), self.edit_item) m.addAction(_('Change all selected items to title case'), self.title_case) m.exec_(QCursor.pos())
def __enter__(self): QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
def update_cursor_for_no_MB(self): # Fixes bug 1693. mark 060321 """ Update the cursor for 'Movie Player' mode. """ self.o.setCursor(QCursor(Qt.ArrowCursor))
def createCompositeCursor(cursor, overlayCursor, hotX=None, hotY=None, offsetX=0, offsetY=0): """ Returns a composite 32x32 cursor using two other cursors. This is useful for creating composite cursor images from two (or more) cursors. For example, the pencil cursor includes a horizontal and vertical symbol when drawing a horizontal or vertical line. This function can be used to create these cursors without having to create each one by hand. The payoff is when the developer/artist wants to change the base cursor image (i.e. the pencil cursor) without having to redraw and save all the other versions of the cursor in the set. @param cursor: The main cursor. @type cursor: QCursor @param overlayCursor: The cursor to overlay on top of I{cursor}. @type overlayCursor: QCursor @param hotX: The X coordinate of the hotspot. If none is given, the hotspot of I{cursor} is used. @type hotX: int @param hotY: The Y coordinate of the hotspot. If none is given, the hotspot of I{cursor} is used. @type hotY: int @param offsetX: The X offset in which to draw the overlay cursor onto I{cursor}. The default is 0. @type offsetX: int @param offsetY: The Y offset in which to draw the overlay cursor onto I{cursor}. The default is 0. @type offsetY: int @return: The composite cursor. @rtype: QCursor @note: It would be easy and useful to allow overlayCursor to be a QPixmap. I'll add this when it becomes helpful. --Mark 2008-03-06. """ # Method: # 1. Get cursor's pixmap and create a painter from it. # 2. Get the pixmap from the overlay cursor and draw it onto the # cursor pixmap to create the composite pixmap. # 3. Create and return a new QCursor from the composite pixmap. # Mark 2008-03-05 assert isinstance(cursor, QCursor) assert isinstance(overlayCursor, QCursor) if hotX is None: hotX = cursor.hotSpot().x() if hotY is None: hotY = cursor.hotSpot().y() pixmap = cursor.pixmap() overlayPixmap = overlayCursor.pixmap() painter = QPainter(pixmap) painter.drawPixmap(offsetX, offsetY, overlayPixmap) painter.end() return QCursor(pixmap, hotX, hotY)
def loadCursors(w): """ This routine is called once to load all the custom cursors needed by NE1. """ filePath = os.path.dirname(os.path.abspath(sys.argv[0])) # Pencil symbols. w.addSymbol = QCursor(getCursorPixmap("symbols/PlusSign.png"), 0, 0) w.subtractSymbol = QCursor(getCursorPixmap("symbols/MinusSign.png"), 0, 0) # Selection lock symbol w.selectionLockSymbol = \ QCursor(getCursorPixmap("symbols/SelectionLock.png"), 0, 0) # Pencil symbols. horizontalSymbol = \ QCursor(getCursorPixmap("symbols/HorizontalSnap.png"), 0, 0) verticalSymbol = \ QCursor(getCursorPixmap("symbols/VerticalSnap.png"), 0, 0) # Pencil cursors w.colorPencilCursor = QCursor(getCursorPixmap("Pencil.png"), 0, 0) w.pencilHorizontalSnapCursor = \ createCompositeCursor(w.colorPencilCursor, horizontalSymbol, offsetX = 22, offsetY = 22) w.pencilVerticalSnapCursor = \ createCompositeCursor(w.colorPencilCursor, verticalSymbol, offsetX = 22, offsetY = 22) # Select Chunks cursors w.SelectArrowCursor = \ QCursor(getCursorPixmap("SelectArrowCursor.png"), 0, 0) w.SelectArrowAddCursor = \ createCompositeCursor(w.SelectArrowCursor, w.addSymbol, offsetX = 12, offsetY = 0) w.SelectArrowSubtractCursor = \ createCompositeCursor(w.SelectArrowCursor, w.subtractSymbol, offsetX = 12, offsetY = 0) # Build Atoms - normal cursors w.SelectAtomsCursor = \ QCursor(getCursorPixmap("SelectAtomsCursor.png"), 0, 0) w.SelectAtomsAddCursor = \ createCompositeCursor(w.SelectAtomsCursor, w.addSymbol, offsetX = 12, offsetY = 0) w.SelectAtomsSubtractCursor = \ createCompositeCursor(w.SelectAtomsCursor, w.subtractSymbol, offsetX = 12, offsetY = 0) w.DeleteCursor = \ QCursor(getCursorPixmap("DeleteCursor.png"), 0, 0) # Build Atoms - Atom Selection Filter cursors w.SelectAtomsFilterCursor = \ QCursor(getCursorPixmap("SelectAtomsFilterCursor.png"), 0, 0) w.SelectAtomsAddFilterCursor = \ createCompositeCursor(w.SelectAtomsFilterCursor, w.addSymbol, offsetX = 12, offsetY = 0) w.SelectAtomsSubtractFilterCursor = \ createCompositeCursor(w.SelectAtomsFilterCursor, w.subtractSymbol, offsetX = 12, offsetY = 0) w.DeleteAtomsFilterCursor = \ QCursor(getCursorPixmap("DeleteAtomsFilterCursor.png"), 0, 0) # Build Atoms - Bond Tool cursors with no modkey pressed w.BondToolCursor = [] w.BondToolCursor.append( QCursor(getCursorPixmap("SelectAtomsCursor.png"), 0, 0)) w.BondToolCursor.append( QCursor(getCursorPixmap("Bond1ToolCursor.png"), 0, 0)) w.BondToolCursor.append( QCursor(getCursorPixmap("Bond2ToolCursor.png"), 0, 0)) w.BondToolCursor.append( QCursor(getCursorPixmap("Bond3ToolCursor.png"), 0, 0)) w.BondToolCursor.append( QCursor(getCursorPixmap("BondAToolCursor.png"), 0, 0)) w.BondToolCursor.append( QCursor(getCursorPixmap("BondGToolCursor.png"), 0, 0)) w.BondToolCursor.append(QCursor(getCursorPixmap("CutBondCursor.png"), 0, 0)) # Build Atoms - Bond Tool cursors with Shift modkey pressed w.BondToolAddCursor = [] for cursor in w.BondToolCursor: w.BondToolAddCursor.append( createCompositeCursor(cursor, w.addSymbol, offsetX=12, offsetY=0)) # Build Atoms - Bond Tool cursors with Control/Cmd modkey pressed w.BondToolSubtractCursor = [] for cursor in w.BondToolCursor: w.BondToolSubtractCursor.append( createCompositeCursor(cursor, w.subtractSymbol, offsetX=12, offsetY=0)) # Translate selection cursors w.TranslateSelectionCursor = \ QCursor(getCursorPixmap("TranslateSelectionCursor.png"), 0, 0) w.TranslateSelectionAddCursor = \ createCompositeCursor(w.TranslateSelectionCursor, w.addSymbol, offsetX = 12, offsetY = 0) w.TranslateSelectionSubtractCursor = \ createCompositeCursor(w.TranslateSelectionCursor, w.subtractSymbol, offsetX = 12, offsetY = 0) # Rotate selection cursors w.RotateSelectionCursor = \ QCursor(getCursorPixmap("RotateSelectionCursor.png"), 0, 0) w.RotateSelectionAddCursor = \ createCompositeCursor(w.RotateSelectionCursor, w.addSymbol, offsetX = 12, offsetY = 0) w.RotateSelectionSubtractCursor = \ createCompositeCursor(w.RotateSelectionCursor, w.subtractSymbol, offsetX = 12, offsetY = 0) # Axis translation/rotation cursor w.AxisTranslateRotateSelectionCursor = \ QCursor(getCursorPixmap("AxisTranslateRotateSelectionCursor.png"), 0, 0) # Build Crystal cursors w.CookieCursor = QCursor(getCursorPixmap("Pencil.png"), 0, 0) w.CookieAddCursor = \ createCompositeCursor(w.colorPencilCursor, w.addSymbol, \ offsetX = 12, offsetY = 0) w.CookieSubtractCursor = \ createCompositeCursor(w.colorPencilCursor, w.subtractSymbol, \ offsetX = 12, offsetY = 0) # View Zoom, Pan, Rotate cursors w.ZoomCursor = QCursor(getCursorPixmap("ZoomCursor.png"), 0, 0) w.ZoomInOutCursor = QCursor(getCursorPixmap("ZoomInOutCursor.png"), 0, 0) w.PanViewCursor = QCursor(getCursorPixmap("PanViewCursor.png"), 0, 0) w.RotateViewCursor = QCursor(getCursorPixmap("RotateViewCursor.png"), 0, 0) # Miscellaneous cursors w.RotateZCursor = QCursor(getCursorPixmap("RotateZCursor.png"), 0, 0) w.ZoomPovCursor = QCursor(getCursorPixmap("ZoomPovCursor.png"), -1, -1) w.ArrowWaitCursor = QCursor(getCursorPixmap("ArrowWaitCursor.png"), 0, 0) w.ArrowCursor = QCursor(Qt.ArrowCursor) #bruce 070627 # Confirmation corner cursors [loaded by bruce 070626 from files committed by mark] w._confcorner_OKCursor = \ QCursor(getCursorPixmap("OKCursor.png"), 0, 0) w.confcorner_TransientDoneCursor = \ QCursor(getCursorPixmap("TransientDoneCursor.png"), 0, 0) w._confcorner_CancelCursor = \ QCursor(getCursorPixmap("CancelCursor.png"), 0, 0) # Some Build Dna mode cursors w.rotateAboutCentralAxisCursor = \ QCursor(getCursorPixmap("Rotate_About_Central_Axis.png"), 0, 0) w.translateAlongCentralAxisCursor = \ QCursor(getCursorPixmap("Translate_Along_Central_Axis.png"), 0, 0) #Rotate about a point cursors w.rotateAboutPointCursor = \ QCursor(getCursorPixmap("RotateAboutPointCursor.png"), 0, 0) w.rotateAboutPointHorizontalSnapCursor = \ createCompositeCursor(w.rotateAboutPointCursor, horizontalSymbol, offsetX = 22, offsetY = 22) w.rotateAboutPointVerticalSnapCursor = \ createCompositeCursor(w.rotateAboutPointCursor, verticalSymbol, offsetX = 22, offsetY = 22) #Add a segment to a list of segments to be resized (in Multiple_DnaSegments #command) w.addSegmentToResizeSegmentListCursor = \ QCursor(getCursorPixmap("AddSegment_To_ResizeSegmentListCursor.png"), 0, 0) w.removeSegmentFromResizeSegmentListCursor = \ QCursor(getCursorPixmap("RemoveSegment_From_ResizeSegmentList_Cursor.png"), 0, 0) w.specifyPlaneCursor = \ QCursor(getCursorPixmap("SpecifyPlaneCursor.png"), 0, 0) return # from loadCursors
def rehighlight(self): self.outlineexplorer_data = {} QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) QSyntaxHighlighter.rehighlight(self) QApplication.restoreOverrideCursor()
def collapse_menu_hovered(self, action): tip = action.toolTip() if tip == '*': tip = '' QToolTip.showText(QCursor.pos(), tip)
def launch_povray_or_megapov( win, info, povray_ini): #bruce 060707/11 revised this extensively for Mac A8 """ Try to launch POV-Ray or MegaPOV, as specified in <info> (as returned from decode_povray_prefs, assumed already checked), on the given <povray_ini> file (which should already exist), and running in the directory of that file (this is required, since it may contain relative pathnames). <win> must be the main window object (used for .glpane.is_animating). Returns (errorcode, errortext), where errorcode is one of the following: ###k 0 = successful 8 = POV-Ray or MegaPOV failed for an unknown reason. """ (program_nickname, program_path, include_dir) = info #e rename this arg renderer_info? exit = '' program = program_path if sys.platform == 'win32': program = "\"" + program + "\"" # Double quotes needed by Windows. Mark 060602. if program_nickname == 'POV-Ray': exit = "/EXIT" # Later we'll cd to the POV-Ray's INI file directory and use tmp_ini in the POV-Ray command-line. # This helps us get around POV-Ray's I/O Restrictions. Mark 060529. workdir, tmp_ini = os.path.split(povray_ini) # Render scene. try: args = [tmp_ini] if exit: args += [exit] if env.debug(): ## use env.history.message(_graymsg(msg)) ? print "debug: Launching %s: \n" % program_nickname,\ "working directory=",workdir,"\n program_path=", program_path, "\n args are %r" % (args,) arguments = QStringList() for arg in args: if arg != "": arguments.append(arg) from processes.Process import Process p = Process() #bruce 060707: this doesn't take advantage of anything not in QProcess, # unless it matters that it reads and discards stdout/stderr # (eg so large output would not block -- unlikely that this matters). # It doesn't echo stdout/stderr. See also blabout/blaberr in other files. Maybe fix this? ###@@@ p.setWorkingDirectory(workdir) p.start(program, arguments) # Put up hourglass cursor to indicate we are busy. Restore the cursor below. Mark 060621. QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) win.glpane.is_animating = True # This disables selection [do you mean highlighting? #k] while rendering the image. import time msg = "Rendering image" while p.state() == QProcess.Running: # Display a message on the status bar that POV-Ray/MegaPOV is rendering. # I'd much rather display a progressbar and stop button by monitoring the size of the output file. # This would require the output file to be written in PPM or BMP format, but not PNG format, since # I don't believe a PNG's final filesize can be predicted. # Check out monitor_progress_by_file_growth() in runSim.py, which does this. [mark] time.sleep(0.25) env.history.statusbar_msg(msg) env.call_qApp_processEvents() if 1: # Update the statusbar message while rendering. if len( msg ) > 40: #bruce changed 100 -> 40 in case of short statusbar msg = "Rendering image" else: #msg = msg + "." msg += "." except: #bruce 060707 moved print_compact_traceback earlier, and its import to toplevel (after Windows A8, before Linux/Mac A8) print_compact_traceback("exception in launch_povray_or_megapov(): ") QApplication.restoreOverrideCursor() win.glpane.is_animating = False return 8, "%s failed for an unknown reason." % program_nickname #bruce 060707 moved the following outside the above try clause, and revised it (after Windows A8, before Linux/Mac A8) QApplication.restoreOverrideCursor() # Restore the cursor. Mark 060621. ## env.history.statusbar_msg("Rendering finished!") # this is wrong if it was not a normal exit. [bruce 060707 removed it] win.glpane.is_animating = False if 1: #bruce 060707 added this (after Windows A8, before Linux/Mac A8): # set an appropriate exitcode and msg if p.exitStatus() == QProcess.NormalExit: exitcode = p.exitStatus() if not exitcode: msg = "Rendering finished!" else: msg = "Rendering program had exitcode %r" % exitcode # e.g. 126 for Mac failure; same as shell exitcode, which says "cannot execute binary file"; # but /usr/bin/open helps, so we'll try that above (but not in this commit, which is just to # improve error reporting). ###@@@ # [bruce 060707] else: exitcode = p.exitStatus() exitcode = -1 msg = "Abnormal exit (or failure to launch)" if exitcode or env.debug(): print msg env.history.statusbar_msg(msg) ## if env.debug(): ## env.history.message(_graymsg(msg)) # not needed, caller prints it if exitcode: return 8, "Error: " + msg # this breaks the convention of the other error returns pass # Display image in separate window here. [Actually I think this is done in the caller -- bruce 060707 comment] return 0, "Rendering finished" # from launch_povray_or_megapov
def __enter__(self): self.stacks.setCurrentIndex(0) self.busy.pi.startAnimation() QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) QApplication.processEvents(QEventLoop.ExcludeUserInputEvents | QEventLoop.ExcludeSocketNotifiers)
def rehighlight(self): QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) QSyntaxHighlighter.rehighlight(self) QApplication.restoreOverrideCursor()
def compute_memo(self, chunk): """If drawing chunk in this display mode can be optimized by precomputing some info from chunk's appearance, compute that info and return it. If this computation requires preference values, access them as env.prefs[key], and that will cause the memo to be removed (invalidated) when that preference value is changed by the user. This computation is assumed to also depend on, and only on, chunk's appearance in ordinary display modes (i.e. it's invalidated whenever havelist is). There is not yet any way to change that, so bugs will occur if any ordinarily invisible chunk info affects this rendering, and potential optimizations will not be done if any ordinarily visible info is not visible in this rendering. These can be fixed if necessary by having the real work done within class Chunk's _recompute_ rules, with this function or drawchunk just accessing the result of that (and sometimes causing its recomputation), and with whatever invalidation is needed being added to appropriate setter methods of class Chunk. If the real work can depend on more than chunk's ordinary appearance can, the access would need to be in drawchunk; otherwise it could be in drawchunk or in this method compute_memo. """ # for this example, we'll turn the chunk axes into a cylinder. # Since chunk.axis is not always one of the vectors chunk.evecs (actually chunk.poly_evals_evecs_axis[2]), # it's best to just use the axis and center, then recompute a bounding cylinder. if not chunk.atoms: return None # Put up hourglass cursor to indicate we are busy. Restore the cursor below. Mark 060621. QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) env.history.message( self.cmdname + "Computing surface. Please wait...") # Mark 060621. env.history.h_update( ) # Update history widget with last message. # Mark 060623. _report_psurface_import_status() # prints only once per session if _psurface_import_worked: # cpp surface stuff center = chunk.center bcenter = chunk.abs_to_base(center) rad = 0.0 margin = 0 radiuses = [] spheres = [] atoms = [] coltypes = [] for a in chunk.atoms.values(): col = a.drawing_color() ii = 0 for ic in range(len(coltypes)): ct = coltypes[ic] if ct == col: break ii += 1 if ii >= len(coltypes): coltypes.append(col) atoms.append(ii) dispjunk, ra = a.howdraw(diTrueCPK) if ra > margin: margin = ra radiuses.append(ra) p = a.posn() - center spheres.append(p) r = p[0]**2 + p[1]**2 + p[2]**2 if r > rad: rad = r rad = sqrt(rad) radius = rad + margin cspheres = [] from utilities.debug_prefs import debug_pref, Choice_boolean_True use_colors = debug_pref( "surface: use colors?", Choice_boolean_True ) #bruce 060927 (old code had 0 for use_colors) for i in range(len(spheres)): st = spheres[i] / radius rt = radiuses[i] / radius # cspheres.append((st[0],st[1],st[2],rt,use_colors)) cspheres.append((st[0], st[1], st[2], rt, atoms[i])) #cspheres.append((-0.3,0,0,0.3,1)) #cspheres.append((0.3,0,0,0.3,2)) color = chunk.drawing_color() if color is None: color = V(0.5, 0.5, 0.5) # create surface level = 3 if rad > 6: level = 4 ps = psurface # 0 - sphere triangles # 1 - torus rectangles # 2 - omega rectangles method = 2 ((em, pm, am), nm) = ps.CreateSurface(cspheres, level, method) cm = [] if True: # True for color for i in range(len(am)): cm.append(coltypes[am[i]]) else: for i in range(len(am)): cm.append((0.5, 0.5, 0.5)) tm = (em, pm, cm) else: # python surface stuff center = chunk.center bcenter = chunk.abs_to_base(center) rad = 0.0 s = Surface() margin = 0 for a in chunk.atoms.values(): dispjunk, ra = a.howdraw(diTrueCPK) if ra > margin: margin = ra s.radiuses.append(ra) p = a.posn() - center s.spheres.append(Triple(p[0], p[1], p[2])) r = p[0]**2 + p[1]**2 + p[2]**2 if r > rad: rad = r rad = sqrt(rad) radius = rad + margin for i in range(len(s.spheres)): s.spheres[i] /= radius s.radiuses[i] /= radius color = chunk.drawing_color() if color is None: color = V(0.5, 0.5, 0.5) # create surface level = 3 if rad > 6: level = 4 ts = getSphereTriangles(level) #ts = s.TorusTriangles(0.7, 0.3, 20) tm = s.SurfaceTriangles(ts) nm = s.SurfaceNormals() QApplication.restoreOverrideCursor( ) # Restore the cursor. Mark 060621. env.history.message(self.cmdname + "Done.") # Mark 060621. return (bcenter, radius, color, tm, nm)