[ Bug ] Draft preferences: problems with font settings
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Re: Draft preferences: problems with font settings
IIRC for the Draft ShapeString, the font handling is done by freefont. I don't know why the fonts are locked that way on windows, nor why freefont wouln't be able to access them read-only somehow... This needs further investigation
I'd really like to be able to get rid of that need to specify Draft ShapeString fonts by file path, and use the same Qt system as the rest of FreeCAD... Unfortunately I didn't find yet a reliable, multi-platform way of relating a Qt font with a file path...
I'd really like to be able to get rid of that need to specify Draft ShapeString fonts by file path, and use the same Qt system as the rest of FreeCAD... Unfortunately I didn't find yet a reliable, multi-platform way of relating a Qt font with a file path...
- wandererfan
- Veteran
- Posts: 6324
- Joined: Tue Nov 06, 2012 5:42 pm
- Contact:
Re: Draft preferences: problems with font settings
If there's a Windows user out there that hasn't messed too much with attributes, permissions, etc, on the Fonts directory, could they try the following please?
In Tools>Edit parameters, add a parameter to the Dialog section as shown in this screen grab:
On my Windows box, setting this parameter to true allows access to the Windows/Fonts directory. I'm not sure my machine is a valid test environment anymore since I've set and reset the Fonts properties so often.
Thanks,
wf
In Tools>Edit parameters, add a parameter to the Dialog section as shown in this screen grab:
On my Windows box, setting this parameter to true allows access to the Windows/Fonts directory. I'm not sure my machine is a valid test environment anymore since I've set and reset the Fonts properties so often.
Thanks,
wf
Re: Draft preferences: problems with font settings
@wandererfan:
Yes, it works! I'll have to get used to the dialog, but I can live with that. Thank you!
Yes, it works! I'll have to get used to the dialog, but I can live with that. Thank you!
Re: Draft preferences: problems with font settings
I've made a crude hack to only have the non-native dialog for the ShapeString Task Panel by changing src\Mod\Draft\DraftGui.py around line 2460 from:
Code: Select all
self.stringText = translate("draft","Default")
self.task.leString.setText(self.stringText)
self.task.fcFontFile.setFileName(Draft.getParam("FontFile",""))
self.fileSpec = Draft.getParam("FontFile","")
self.point = FreeCAD.Vector(0.0,0.0,0.0)
self.pointPicked = False
QtCore.QObject.connect(self.task.fcFontFile,QtCore.SIGNAL("fileNameSelected(const QString&)"),self.fileSelect)
QtCore.QObject.connect(self.task.pbReset,QtCore.SIGNAL("clicked()"),self.resetPoint)
self.point = None
self.view = Draft.get3DView()
self.call = self.view.addEventCallback("SoEvent",self.action)
FreeCAD.Console.PrintMessage(translate("draft", "Pick ShapeString location point:")+"\n")
def fileSelect(self, fn):
self.fileSpec = fn
def resetPoint(self):
self.pointPicked = False
origin = FreeCAD.Vector(0.0,0.0,0.0)
self.setPoint(origin)
def action(self,arg):
"""scene event handler"""
import DraftTools
if arg["Type"] == "SoKeyboardEvent":
if arg["Key"] == "ESCAPE":
self.reject()
elif arg["Type"] == "SoLocation2Event": #mouse movement detection
self.point,ctrlPoint,info = DraftTools.getPoint(self.sourceCmd,arg,noTracker=True)
if not self.pointPicked:
self.setPoint(self.point)
elif arg["Type"] == "SoMouseButtonEvent":
if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"):
self.setPoint(self.point)
self.pointPicked = True
def setPoint(self, point):
self.task.sbX.setProperty('rawValue',point.x)
self.task.sbY.setProperty('rawValue',point.y)
self.task.sbZ.setProperty('rawValue',point.z)
def createObject(self):
"""creates object in the current doc"""
dquote = '"'
if sys.version_info.major < 3: # Python3: no more unicode
String = 'u' + dquote + str(self.task.leString.text().encode('unicode_escape')) + dquote
else:
String = dquote + self.task.leString.text() + dquote
FFile = dquote + str(self.fileSpec) + dquote
Size = str(FreeCAD.Units.Quantity(self.task.sbHeight.text()).Value)
Tracking = str(0.0)
x = FreeCAD.Units.Quantity(self.task.sbX.text()).Value
y = FreeCAD.Units.Quantity(self.task.sbY.text()).Value
z = FreeCAD.Units.Quantity(self.task.sbZ.text()).Value
ssBase = FreeCAD.Vector(x,y,z)
# this try block is almost identical to the one in DraftTools
try:
qr,sup,points,fil = self.sourceCmd.getStrings()
FreeCADGui.addModule("Draft")
self.sourceCmd.commit(translate("draft","Create ShapeString"),
['ss=Draft.makeShapeString(String='+String+',FontFile='+FFile+',Size='+Size+',Tracking='+Tracking+')',
'plm=FreeCAD.Placement()',
'plm.Base='+DraftVecUtils.toString(ssBase),
'plm.Rotation.Q='+qr,
'ss.Placement=plm',
'ss.Support='+sup,
'Draft.autogroup(ss)'])
except Exception as e:
FreeCAD.Console.PrintError("Draft_ShapeString: error delaying commit\n")
def accept(self):
self.createObject();
if self.call: self.view.removeEventCallback("SoEvent",self.call)
FreeCADGui.ActiveDocument.resetEdit()
FreeCADGui.Snapper.off()
self.sourceCmd.creator.finish(self.sourceCmd)
return True
def reject(self):
if self.call: self.view.removeEventCallback("SoEvent",self.call)
FreeCADGui.ActiveDocument.resetEdit()
FreeCADGui.Snapper.off()
self.sourceCmd.creator.finish(self.sourceCmd)
return True
Code: Select all
self.stringText = translate("draft","Default")
self.task.leString.setText(self.stringText)
tDialog = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Dialog")
import platform
if platform.system() == 'Windows':
tDialog.SetBool("DontUseNativeDialog", True)
self.task.fcFontFile.setFileName(Draft.getParam("FontFile",""))
self.fileSpec = Draft.getParam("FontFile","")
self.point = FreeCAD.Vector(0.0,0.0,0.0)
self.pointPicked = False
QtCore.QObject.connect(self.task.fcFontFile,QtCore.SIGNAL("fileNameSelected(const QString&)"),self.fileSelect)
QtCore.QObject.connect(self.task.pbReset,QtCore.SIGNAL("clicked()"),self.resetPoint)
self.point = None
self.view = Draft.get3DView()
self.call = self.view.addEventCallback("SoEvent",self.action)
FreeCAD.Console.PrintMessage(translate("draft", "Pick ShapeString location point:")+"\n")
def fileSelect(self, fn):
self.fileSpec = fn
def resetPoint(self):
self.pointPicked = False
origin = FreeCAD.Vector(0.0,0.0,0.0)
self.setPoint(origin)
def action(self,arg):
"""scene event handler"""
import DraftTools
if arg["Type"] == "SoKeyboardEvent":
if arg["Key"] == "ESCAPE":
self.reject()
elif arg["Type"] == "SoLocation2Event": #mouse movement detection
self.point,ctrlPoint,info = DraftTools.getPoint(self.sourceCmd,arg,noTracker=True)
if not self.pointPicked:
self.setPoint(self.point)
elif arg["Type"] == "SoMouseButtonEvent":
if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"):
self.setPoint(self.point)
self.pointPicked = True
def setPoint(self, point):
self.task.sbX.setProperty('rawValue',point.x)
self.task.sbY.setProperty('rawValue',point.y)
self.task.sbZ.setProperty('rawValue',point.z)
def createObject(self):
"""creates object in the current doc"""
dquote = '"'
if sys.version_info.major < 3: # Python3: no more unicode
String = 'u' + dquote + str(self.task.leString.text().encode('unicode_escape')) + dquote
else:
String = dquote + self.task.leString.text() + dquote
FFile = dquote + str(self.fileSpec) + dquote
Size = str(FreeCAD.Units.Quantity(self.task.sbHeight.text()).Value)
Tracking = str(0.0)
x = FreeCAD.Units.Quantity(self.task.sbX.text()).Value
y = FreeCAD.Units.Quantity(self.task.sbY.text()).Value
z = FreeCAD.Units.Quantity(self.task.sbZ.text()).Value
ssBase = FreeCAD.Vector(x,y,z)
# this try block is almost identical to the one in DraftTools
try:
qr,sup,points,fil = self.sourceCmd.getStrings()
FreeCADGui.addModule("Draft")
self.sourceCmd.commit(translate("draft","Create ShapeString"),
['ss=Draft.makeShapeString(String='+String+',FontFile='+FFile+',Size='+Size+',Tracking='+Tracking+')',
'plm=FreeCAD.Placement()',
'plm.Base='+DraftVecUtils.toString(ssBase),
'plm.Rotation.Q='+qr,
'ss.Placement=plm',
'ss.Support='+sup,
'Draft.autogroup(ss)'])
except Exception as e:
FreeCAD.Console.PrintError("Draft_ShapeString: error delaying commit\n")
def accept(self):
self.createObject();
if self.call: self.view.removeEventCallback("SoEvent",self.call)
FreeCADGui.ActiveDocument.resetEdit()
FreeCADGui.Snapper.off()
self.sourceCmd.creator.finish(self.sourceCmd)
tDialog = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Dialog")
import platform
if platform.system() == 'Windows':
tDialog.SetBool("DontUseNativeDialog", False)
return True
def reject(self):
if self.call: self.view.removeEventCallback("SoEvent",self.call)
FreeCADGui.ActiveDocument.resetEdit()
FreeCADGui.Snapper.off()
self.sourceCmd.creator.finish(self.sourceCmd)
tDialog = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Dialog")
import platform
if platform.system() == 'Windows':
tDialog.SetBool("DontUseNativeDialog", False)
return True
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.18504 (Git)
Build type: Release
Branch: master
Hash: f66023a646db4b2502bb3637897443b3525ca3c7
Python version: 3.6.8
Qt version: 5.12.1
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/United Kingdom (en_GB)
- wandererfan
- Veteran
- Posts: 6324
- Joined: Tue Nov 06, 2012 5:42 pm
- Contact:
Re: Draft preferences: problems with font settings
Nice. I've been fixated on the Preferences aspect, haven't really thought about the dialog.
I don't see your PR in the Q?
Re: Draft preferences: problems with font settings
PR with slightly nicer code https://github.com/FreeCAD/FreeCAD/pull/2610
Re: Draft preferences: problems with font settings
Just stumbled over new behaviour since this commit.Syres wrote: ↑Fri Oct 11, 2019 2:27 pm PR with slightly nicer code https://github.com/FreeCAD/FreeCAD/pull/2610
Unfortunately user parameter "DontUseNativeDialog" is overwritten after first call of "platWinDialog" and not restored.
So user settings are lost afterwards.
This is rude behaviour!
Please see my proposal: https://github.com/UR-0/FreeCAD/commit/ ... a0922cea29
Another user parameter "DontUseNativeFontDialog" is introduced and "DontUseNativeDialog" is restored to previous state after usage.
What's your opinion about this?
Re: Draft preferences: problems with font settings
My testing wasn't thorough enough to have highlighted my major flaw!!
I've tested your DraftGui.py as an existing user and as a brand new user and I've not been able to break it. I did notice that you didn't have the Windows OS check
Code: Select all
if platform.system() == 'Windows':
In either case, if you're happy to submit the PR it's fine with me, thanks for the efforts.
Re: Draft preferences: problems with font settings
Then I'll merge it and we fix things afterwards if it breaks for linux