draft: move translation to DraftGui
otherwiser there are some strange ImportEroors.
This commit is contained in:
@@ -40,12 +40,56 @@ Report to Draft.py for info
|
||||
'''
|
||||
|
||||
import FreeCAD, FreeCADGui, os, Draft, sys, DraftVecUtils, math
|
||||
from DraftTools import utf8_decode
|
||||
|
||||
try:
|
||||
from PySide import QtCore,QtGui,QtSvg
|
||||
from PySide import QtCore, QtGui, QtSvg
|
||||
except ImportError:
|
||||
FreeCAD.Console.PrintMessage("Error: Python-pyside package must be installed on your system to use the Draft module.")
|
||||
|
||||
|
||||
try:
|
||||
_encoding = QtGui.QApplication.UnicodeUTF8
|
||||
def translate(context, text, utf8_decode=False):
|
||||
"""convenience function for Qt translator
|
||||
context: str
|
||||
context is typically a class name (e.g., "MyDialog")
|
||||
text: str
|
||||
text which gets translated
|
||||
utf8_decode: bool [False]
|
||||
if set to true utf8 encoded unicode will be returned. This option does not have influence
|
||||
on python3 as for python3 we are returning utf-8 encoded unicode by default!
|
||||
"""
|
||||
if sys.version_info.major >= 3 or utf8_decode:
|
||||
return QtGui.QApplication.translate(context, text, None, _encoding)
|
||||
else:
|
||||
return QtGui.QApplication.translate(context, text, None, _encoding).encode("utf8")
|
||||
|
||||
except AttributeError:
|
||||
def translate(context, text, utf8_decode=False):
|
||||
"""convenience function for Qt translator
|
||||
context: str
|
||||
context is typically a class name (e.g., "MyDialog")
|
||||
text: str
|
||||
text which gets translated
|
||||
utf8_decode: bool [False]
|
||||
if set to true utf8 encoded unicode will be returned. This option does not have influence
|
||||
on python3 as for python3 we are returning utf-8 encoded unicode by default!
|
||||
"""
|
||||
if sys.version >= 3 or utf8_decode:
|
||||
return QtGui.QApplication.translate(context, text, None)
|
||||
else:
|
||||
return QtGui.QApplication.translate(context, text, None).encode("utf8")
|
||||
|
||||
def utf8_decode(text):
|
||||
"""py2: str -> unicode
|
||||
unicode -> unicode
|
||||
py3: str -> str
|
||||
bytes -> str
|
||||
"""
|
||||
try:
|
||||
return text.decode("utf-8")
|
||||
except AttributeError:
|
||||
return text
|
||||
|
||||
class todo:
|
||||
''' static todo class, delays execution of functions. Use todo.delay
|
||||
@@ -104,17 +148,6 @@ class todo:
|
||||
QtCore.QTimer.singleShot(0, todo.doTasks)
|
||||
todo.commitlist = cl
|
||||
|
||||
try:
|
||||
_encoding = QtGui.QApplication.UnicodeUTF8
|
||||
def translate(context, text):
|
||||
"convenience function for Qt translator"
|
||||
return QtGui.QApplication.translate(context, text, None, _encoding)
|
||||
except AttributeError:
|
||||
def translate(context, text):
|
||||
"convenience function for Qt translator"
|
||||
return QtGui.QApplication.translate(context, text, None)
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# UNITS handling
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
@@ -40,7 +40,7 @@ __url__ = "http://www.freecadweb.org"
|
||||
|
||||
import sys, os, FreeCAD, FreeCADGui, WorkingPlane, math, re, Draft, Draft_rc, DraftVecUtils
|
||||
from FreeCAD import Vector
|
||||
from DraftGui import todo,QtCore,QtGui
|
||||
from DraftGui import todo, QtCore, QtGui, translate, utf8_decode
|
||||
from DraftSnap import *
|
||||
from DraftTrackers import *
|
||||
from pivy import coin
|
||||
@@ -73,51 +73,6 @@ MODALT = MODS[Draft.getParam("modalt",2)]
|
||||
# General functions
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
try:
|
||||
_encoding = QtGui.QApplication.UnicodeUTF8
|
||||
def translate(context, text, utf8_decode=False):
|
||||
"""convenience function for Qt translator
|
||||
context: str
|
||||
context is typically a class name (e.g., "MyDialog")
|
||||
text: str
|
||||
text which gets translated
|
||||
utf8_decode: bool [False]
|
||||
if set to true utf8 encoded unicode will be returned. This option does not have influence
|
||||
on python3 as for python3 we are returning utf-8 encoded unicode by default!
|
||||
"""
|
||||
if sys.version_info.major >= 3 or utf8_decode:
|
||||
return QtGui.QApplication.translate(context, text, None, _encoding)
|
||||
else:
|
||||
return QtGui.QApplication.translate(context, text, None, _encoding).encode("utf8")
|
||||
|
||||
except AttributeError:
|
||||
def translate(context, text, utf8_decode=False):
|
||||
"""convenience function for Qt translator
|
||||
context: str
|
||||
context is typically a class name (e.g., "MyDialog")
|
||||
text: str
|
||||
text which gets translated
|
||||
utf8_decode: bool [False]
|
||||
if set to true utf8 encoded unicode will be returned. This option does not have influence
|
||||
on python3 as for python3 we are returning utf-8 encoded unicode by default!
|
||||
"""
|
||||
if sys.version >= 3 or utf8_decode:
|
||||
return QtGui.QApplication.translate(context, text, None)
|
||||
else:
|
||||
return QtGui.QApplication.translate(context, text, None).encode("utf8")
|
||||
|
||||
def utf8_decode(text):
|
||||
"""py2: str -> unicode
|
||||
unicode -> unicode
|
||||
py3: str -> str
|
||||
bytes -> str
|
||||
"""
|
||||
try:
|
||||
return text.decode("utf-8")
|
||||
except AttributeError:
|
||||
return text
|
||||
|
||||
def msg(text=None,mode=None):
|
||||
"prints the given message on the FreeCAD status bar"
|
||||
if not text: FreeCAD.Console.PrintMessage("")
|
||||
|
||||
@@ -36,6 +36,7 @@ __url__ = ["http://www.freecadweb.org"]
|
||||
## \addtogroup DRAFTVECUTILS
|
||||
# @{
|
||||
|
||||
import sys
|
||||
import math,FreeCAD
|
||||
from FreeCAD import Vector, Matrix
|
||||
|
||||
@@ -84,12 +85,18 @@ def equals(u,v):
|
||||
|
||||
def scale(u,scalar):
|
||||
"scale(Vector,Float) - scales (multiplies) a vector by a factor"
|
||||
typecheck ([(u,Vector), (scalar,(long,int,float))], "scale")
|
||||
if sys.version_info.major < 3:
|
||||
typecheck ([(u,Vector), (scalar,(long,int,float))], "scale")
|
||||
else:
|
||||
typecheck ([(u,Vector), (scalar,(int,int,float))], "scale")
|
||||
return Vector(u.x*scalar, u.y*scalar, u.z*scalar)
|
||||
|
||||
def scaleTo(u,l):
|
||||
"scaleTo(Vector,length) - scales a vector to a given length"
|
||||
typecheck ([(u,Vector),(l,(long,int,float))], "scaleTo")
|
||||
if sys.version_info.major < 3:
|
||||
typecheck ([(u,Vector),(l,(long,int,float))], "scaleTo")
|
||||
else:
|
||||
typecheck ([(u,Vector),(l,(int,int,float))], "scaleTo")
|
||||
if u.Length == 0:
|
||||
return Vector(u)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user