Macro Mouse Cross/it


Text-x-python.png Mouse di precisione

Descrizione
Questa macro cambia la forma del mouse in una croce di precisione.
Autore
Mario52
Link
Esempi di macro
Come installare le Macro
Personalizzare la barra degli strumenti
Versione
00.03
Data ultima modifica
2016-01-25


Descrizione

Questa macro cambia la forma del mouse in una croce di precisione
Breve esempio di utilizzo della classe ViewObserver() e della procedura d'uso. SoKeyboardEvent

Macro_Mouse_Cross


Utilizzo

  1. Premere C per attivare la croce.
  2. Premere A per attivare la freccia.
  3. Premere G per attivare la griglia.
  4. Premere X per scorrere tutti i cursori.
  5. Premere Q per uscire dalla macro.

Script

Macro_Mouse_Cross.FCMacro

# -*- coding: utf-8 -*-
# mouse cursor to Cross or Arrow + Grig 
# ver 0.2 08/08/2014  PyQt4 and PySide
__title__   = "Macro_Mouse_Cross"
__author__  = "Mario52"
__url__     = "http://www.freecadweb.org/index-fr.html"
__version__ = "00.03"
__date__    = "25/01/2016"

try:
    from PyQt4 import QtCore, QtGui
except Exception:
    from PySide import QtCore, QtGui
from pivy import coin

global xx ;xx = -1

#################### create document if not exist #######################
doc = FreeCAD.ActiveDocument                                         ####
if doc == None:                                                      ####
    doc = FreeCAD.newDocument()                                      ####
#########################################################################
class ViewObserver:
   def logPosition(self, info):
       global xx
       self.pos = info["Key"]
       if (self.pos.upper() == "Q"):
           v.removeEventCallback("SoKeyboardEvent",c)
           print "End Macro_Mouse_Cross"
       if (self.pos.upper() == "C"):
           # change the cursor cross ( + )
           QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.CrossCursor))
       elif (self.pos.upper() == "A"):
           # change the cursor in Arrow
           QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
       elif (self.pos.upper() == "X") and (info["State"] == "DOWN"):
           # change the cursor and visualise all model 
           xx += 1
           if xx == 0:
               QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
               FreeCAD.Console.PrintMessage("ArrowCursor"+"\n")
           if xx == 1:
               QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.UpArrowCursor))
               FreeCAD.Console.PrintMessage("UpArrowCursor"+"\n")
           if xx == 2:
               QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.CrossCursor))
               FreeCAD.Console.PrintMessage("CrossCursor"+"\n")
           if xx == 3:
               QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
               FreeCAD.Console.PrintMessage("WaitCursor"+"\n")
           if xx == 4:
               QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.IBeamCursor))
               FreeCAD.Console.PrintMessage("IBeamCursor"+"\n")
           if xx == 5:
               QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.SizeVerCursor))
               FreeCAD.Console.PrintMessage("SizeVerCursor"+"\n")
           if xx == 6:
               QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.SizeHorCursor))
               FreeCAD.Console.PrintMessage("SizeHorCursor"+"\n")
           if xx == 7:
               QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.SizeBDiagCursor))
               FreeCAD.Console.PrintMessage("SizeBDiagCursor"+"\n")
           if xx == 8:
               QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.SizeFDiagCursor))
               FreeCAD.Console.PrintMessage("SizeFDiagCursor"+"\n")
           if xx == 9:
               QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.SizeAllCursor))
               FreeCAD.Console.PrintMessage("SizeAllCursor"+"\n")
           if xx == 10:
               QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.BlankCursor))
               FreeCAD.Console.PrintMessage("BlankCursor"+"\n")
           if xx == 11:
               QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.SplitVCursor))
               FreeCAD.Console.PrintMessage("SplitVCursor"+"\n")
           if xx == 12:
               QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.SplitHCursor))
               FreeCAD.Console.PrintMessage("SplitHCursor"+"\n")
           if xx == 13:
               QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
               FreeCAD.Console.PrintMessage("PointingHandCursor"+"\n")
           if xx == 14:
               QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.ForbiddenCursor))
               FreeCAD.Console.PrintMessage("ForbiddenCursor"+"\n")
           if xx == 15:
               QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.OpenHandCursor))
               FreeCAD.Console.PrintMessage("OpenHandCursor"+"\n")
           if xx == 16:
               QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.ClosedHandCursor))
               FreeCAD.Console.PrintMessage("ClosedHandCursor"+"\n")
           if xx == 17:
               QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WhatsThisCursor))
               FreeCAD.Console.PrintMessage("WhatsThisCursor"+"\n")
           if xx == 18:
               QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.BusyCursor))
               FreeCAD.Console.PrintMessage("BusyCursor"+"\n")
           if xx == 19:
               QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.BitmapCursor))
               FreeCAD.Console.PrintMessage("BitmapCursor"+"\n")
               xx = -1
       elif (self.pos.upper() == "G"):
           # "wmayer" http://forum.freecadweb.org/viewtopic.php?f=3&t=1065&hilit=cross#p8818
           # Create Grida
           grid=coin.SoType.fromName("SoDrawingGrid").createInstance()
           Gui.ActiveDocument.ActiveView.getSceneGraph().addChild(grid)
xx = -1 

try:
    v=Gui.activeDocument().activeView()
    o = ViewObserver()
    c = v.addEventCallback("SoKeyboardEvent",o.logPosition)
    App.Console.PrintMessage("Type Key C to Cross"+"\n")
    App.Console.PrintMessage("Type Key A to Arrow"+"\n")
    App.Console.PrintMessage("Type Key X to Visualise all cursor"+"\n")
    App.Console.PrintMessage("Type Key G to Grid (not editable)"+"\n")
    App.Console.PrintMessage("Type Key Q to Quit"+"\n")
except Exception:
    FreeCAD.Console.PrintError("\n"+"Not document open"+"\n") 

Cursori che è possibile usare

ArrowCursor, UpArrowCursor, CrossCursor, WaitCursor, IBeamCursor, SizeVerCursor, SizeHorCursor SizeBDiagCursor, SizeFDiagCursor, SizeAllCursor, BlankCursor, SplitVCursor, SplitHCursor PointingHandCursor, ForbiddenCursor, OpenHandCursor, ClosedHandCursor, WhatsThisCursor, BusyCursor, BitmapCursor

Limiti

Il cursore può cambiare aspetto a seconda dell'ambiente di lavoro usato, quindi ripetere l'operazione.
Il cursore può essere sostituito con altri cursori (es: durante l'espansione di una finestra, gli angoli...).
La griglia resta permanante.

Online version: "http://www.freecadweb.org/wiki/index.php?title=Macro_Mouse_Cross/it&oldid=239843"

Navigation menu