Macro Mouse Cross/cs: Difference between revisions

From FreeCAD Documentation
(Created page with "==Popis== Toto malé makro mění šipku kurzoru myši na jemný křížek.<br /> Malý příklad použití třídy '''ViewObserver()''' a použití klávesnice '''[[Code_snip...")
 
mNo edit summary
(31 intermediate revisions by 4 users not shown)
Line 1: Line 1:
<languages/>
{{Macro|Icon=Text-x-python|Name=Macro_Mouse_Cross|Description=This macro turns the arrow of the mouse in a precision cross.|Shortcut="C" "A" |Author=Mario52}}
{{Macro/cs
|Name=Macro_Mouse_Cross
|Icon=Macro_Mouse_Cross.png
|Translate=Macro Mouse Cross
|Description=Toto malé makro mění šipku kurzoru myši na jemný křížek.
|Shortcut=C, A, G, X, Q
|Author=Mario52
|Version=00.03
|Date=2016-01-25
|FCVersion=All
|Download=[https://www.freecadweb.org/wiki/images/f/ff/Macro_Mouse_Cross.png ToolBar icon]
}}


==Popis==
==Popis==
Toto malé makro mění šipku kurzoru myši na jemný křížek.<br />
Toto malé makro mění šipku kurzoru myši na jemný křížek.
Malý příklad použití třídy '''ViewObserver()''' a použití klávesnice '''[[Code_snippets#Observing_mouse_events_in_the_3D_viewer_via_Python|SoKeyboardEvent]]'''


[[File:Macro_Mouse_Cross_00.png|480px|Macro_Mouse_Cross]]
[[File:Macro_Mouse_Cross_00.png|480px|Macro_Mouse_Cross]]
{{Caption|Malý příklad použití třídy '''ViewObserver()''' a použití klávesnice '''[[Code_snippets#Observing_mouse_events_in_the_3D_viewer_via_Python|SoKeyboardEvent]]'''}}
{{clear}}


==How to use==
==Použití==
# Press the {{KEY|C}} button to activate the cross.
# Stiskněte klávesu {{KEY|C}} pro aktivaci křížku.
# Press the {{KEY|A}} button to activate the arrow.
# Stiskněte klávesu {{KEY|A}} pro aktivaci šipky.
# Stiskněte klávesu {{KEY|G}} pro aktivaci mřížky.
# Stiskněte klávesu {{KEY|X}} pro zobrazení všech kurzoru.
# Stiskněte klávesu {{KEY|Q}} pro ukončení makra.


==Script==
==Skript==
Macro_Mouse_Cross.FCMacro
ToolBar icon [[Image:Macro_Mouse_Cross.png]]

'''Macro_Mouse_Cross.FCMacro'''

{{Code|code=


<syntaxhighlight>
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# Macro_Mouse_Cross mouse cursor to cross or arrow
# mouse cursor to Cross or Arrow + Grig
# ver 0.2 08/08/2014 PyQt4 and PySide
from PyQt4 import QtCore, QtGui
# ver 0.4 07/06/2019 compatible Python 3.
#
__title__ = "Macro_Mouse_Cross"
__author__ = "Mario52"
__wiki__ = "https://www.freecadweb.org/wiki/Macro_Mouse_Cross"
__url__ = "http://www.freecadweb.org/index-fr.html"
__version__ = "00.04"
__date__ = "07/06/2019"

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:
class ViewObserver:
def logPosition(self, info):
def logPosition(self, info):
global xx
self.pos = info["Key"]
self.pos = info["Key"]
if (self.pos.upper() == "Q"):
v.removeEventCallback("SoKeyboardEvent",c)
FreeCAD.Console.PrintMessage("End Macro_Mouse_Cross"+"\n")
if (self.pos.upper() == "C"):
if (self.pos.upper() == "C"):
# change the cursor cross ( + )
# change the cursor cross ( + )
QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.CrossCursor))
QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.CrossCursor))
elif (self.pos.upper() == "A"):
elif (self.pos.upper() == "A"):
# change the cursor Arrow
# change the cursor in Arrow
QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
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()
v=Gui.activeDocument().activeView()
o = ViewObserver()
o = ViewObserver()
c = v.addEventCallback("SoKeyboardEvent",o.logPosition)
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")



</syntaxhighlight>
}}
===Cursors that can be used===
===Kurzory, které mohou být používány===
ArrowCursor, UpArrowCursor, CrossCursor, WaitCursor, IBeamCursor, SizeVerCursor, SizeHorCursor
ArrowCursor, UpArrowCursor, CrossCursor, WaitCursor, IBeamCursor, SizeVerCursor, SizeHorCursor
SizeBDiagCursor, SizeFDiagCursor, SizeAllCursor, BlankCursor, SplitVCursor, SplitHCursor
SizeBDiagCursor, SizeFDiagCursor, SizeAllCursor, BlankCursor, SplitVCursor, SplitHCursor
PointingHandCursor, ForbiddenCursor, OpenHandCursor, ClosedHandCursor, WhatsThisCursor, BusyCursor, BitmapCursor
PointingHandCursor, ForbiddenCursor, OpenHandCursor, ClosedHandCursor, WhatsThisCursor, BusyCursor, BitmapCursor
==Limitation==
The cursor can change appearance depending on the used Workbench, he must repeat the operation.<br />
The cursor can be subtituer to the other sliders (ex: expansion of a window, corner...).<br />
The rest resident macro.


==Omezení==
[[Category:Poweruser Documentation]]
Kurzor může měnit vzhled v závislosti na používané pracovní ploše, musí opakovat funkci.<br />
[[Category:Python Code]]
Kurzor může být nahrazen jiným posuvníkem (např. rozšíření okna, rohu, ...).<br />
<languages/>
Mřížka je permanentní.<br />
Zbytek rezidentního makra.

Revision as of 16:03, 25 July 2019

Macro Mouse Cross

Popis
Toto malé makro mění šipku kurzoru myši na jemný křížek.

Version macro : 00.03
Date last modification : 2016-01-25
FreeCAD version : All
Download : ToolBar icon
Autor: Mario52
Autor
Mario52
Download
ToolBar icon
Odkazy
Verze
00.03
Datum poslední úpravy
2016-01-25
Verze FreeCAD
All
Výchozí zástupce
C, A, G, X, Q
Viz též
None

Popis

Toto malé makro mění šipku kurzoru myši na jemný křížek.

Macro_Mouse_Cross

Malý příklad použití třídy ViewObserver() a použití klávesnice SoKeyboardEvent

Použití

  1. Stiskněte klávesu C pro aktivaci křížku.
  2. Stiskněte klávesu A pro aktivaci šipky.
  3. Stiskněte klávesu G pro aktivaci mřížky.
  4. Stiskněte klávesu X pro zobrazení všech kurzoru.
  5. Stiskněte klávesu Q pro ukončení makra.

Skript

ToolBar icon

Macro_Mouse_Cross.FCMacro

# -*- coding: utf-8 -*-
# mouse cursor to Cross or Arrow + Grig 
# ver 0.2 08/08/2014  PyQt4 and PySide
# ver 0.4 07/06/2019 compatible Python 3.
#
__title__   = "Macro_Mouse_Cross"
__author__  = "Mario52"
__wiki__    = "https://www.freecadweb.org/wiki/Macro_Mouse_Cross"
__url__     = "http://www.freecadweb.org/index-fr.html"
__version__ = "00.04"
__date__    = "07/06/2019"

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)
           FreeCAD.Console.PrintMessage("End Macro_Mouse_Cross"+"\n")
       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")

Kurzory, které mohou být používány

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

Omezení

Kurzor může měnit vzhled v závislosti na používané pracovní ploše, musí opakovat funkci.
Kurzor může být nahrazen jiným posuvníkem (např. rozšíření okna, rohu, ...).
Mřížka je permanentní.
Zbytek rezidentního makra.