Skip to content

Commit

Permalink
Merge pull request #529 from kbwbe/tmp
Browse files Browse the repository at this point in the history
Remove python 2 support, work on translations
  • Loading branch information
kbwbe authored Oct 29, 2022
2 parents bfd6563 + f275b41 commit 2541401
Show file tree
Hide file tree
Showing 14 changed files with 353 additions and 382 deletions.
23 changes: 21 additions & 2 deletions CD_ConstraintViewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
# Tries to find constraints that are conflicting with each other.

import os
import sys
import FreeCAD
import FreeCADGui
import subprocess
Expand Down Expand Up @@ -142,6 +143,11 @@ def drt(self):
]
self.createButtonColumn(420, btnLabels)

btnLabels = [
['Close','Close this window'],
]
self.createButtonColumn(560, btnLabels)


def createButtonColumn(self, xloc, btnLabels):
for row in range(0, len(btnLabels)):
Expand Down Expand Up @@ -206,6 +212,9 @@ def button_pushed(self):
if buttext == 'Find Constraint':
search.startsearch(lastclc.cname, 0)

if buttext == 'Close':
self.Closeme()

def clearTable(self):
self.tm.setRowCount(0)

Expand All @@ -216,8 +225,18 @@ def process_menus(self, q):
if q.text() == "Delete labels":
CD_featurelabels.labels.deletelabels()
if q.text() == "Open Help":
path = a2plib.pathOfModule() + "\CD_Help for Diagnostic tools.pdf"
subprocess.Popen([path], shell = True)
pdf_file = os.path.join(os.path.dirname(os.path.dirname(__file__)),'CD_Help for Diagnostic tools.pdf')
# pdf_file = a2plib.pathOfModule() + "\CD_Help for Diagnostic tools.pdf"
# For Linux Mint 21 64-bit with XFCE
if sys.platform in ['linux', 'linux2', 'darwin', 'cygwin']:
import webbrowser
webbrowser.open_new_tab(pdf_file)
# For Windows 10 Pro 64-bit
elif sys.platform == 'win32':
subprocess.Popen([pdf_file], shell = True)
# For others OS
else:
print("Found platform %s, OS %s" % (sys.platform, os.name))

def process_misc_menus(self, q):
menutext = q.text()
Expand Down
52 changes: 22 additions & 30 deletions CD_checkconstraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import a2p_constraintServices
import CD_ConstraintViewer

translate = FreeCAD.Qt.translate

class globaluseclass:
def __init__(self):
self.checkingnum = 0
Expand All @@ -46,17 +48,17 @@ class mApp(QtGui.QWidget):
# for error messages
def __init__(self, msg):
super().__init__()
self.title = 'Information'
self.title = translate("A2plus", "Information")
self.initUI(msg)

def initUI(self, msg, msgtype = 'ok'):
self.setWindowTitle(self.title)
self.setGeometry(100, 100, 320, 200)
self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
if msgtype == 'ok':
buttonReply = QtGui.QMessageBox.question(self, 'Information', msg, QtGui.QMessageBox.Ok | QtGui.QMessageBox.Ok)
buttonReply = QtGui.QMessageBox.question(self, translate("A2plus", "Information"), msg, QtGui.QMessageBox.Ok | QtGui.QMessageBox.Ok)
if msgtype == 'yn':
buttonReply = QtGui.QMessageBox.question(self, 'Information', msg, QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No)
buttonReply = QtGui.QMessageBox.question(self, translate("A2plus", "Information"), msg, QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No)
if buttonReply == QtGui.QMessageBox.Yes:
pass
# print('Yes clicked.')
Expand All @@ -71,7 +73,7 @@ class formMain(QtGui.QMainWindow):
def __init__(self, name):
self.name = name
super(formMain, self).__init__()
self.setWindowTitle('Constraint Checker')
self.setWindowTitle(translate("A2plus", "Constraint Checker"))
self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
self.setGeometry(300, 100, 600, 140)
self.setStyleSheet("font:11pt arial MS")
Expand All @@ -81,7 +83,7 @@ def __init__(self, name):


self.lblviewlabel = QtGui.QLabel(self)
self.lblviewlabel.setText('To view the constraints, press "Open Viewer"')
self.lblviewlabel.setText(translate("A2plus", "To view the constraints, press 'Open Viewer'"))
self.lblviewlabel.move(5, 5)
self.lblviewlabel.setFixedWidth(350)
self.lblviewlabel.setFixedHeight(20)
Expand All @@ -91,16 +93,16 @@ def __init__(self, name):
self.btnOpenViewer.move(365, 5)
self.btnOpenViewer.setFixedWidth(100)
self.btnOpenViewer.setFixedHeight(28)
self.btnOpenViewer.setToolTip("View the listed constraints in the the Constraint Viewer.")
self.btnOpenViewer.setText("Open Viewer")
self.btnOpenViewer.setToolTip(translate("A2plus", "View the listed constraints in the the Constraint Viewer."))
self.btnOpenViewer.setText(translate("A2plus", "Open Viewer"))
self.btnOpenViewer.clicked.connect(lambda:self.openViewer())

self.btnCloseForm = QtGui.QPushButton(self)
self.btnCloseForm.move(475, 5)
self.btnCloseForm.setFixedWidth(100)
self.btnCloseForm.setFixedHeight(28)
self.btnCloseForm.setToolTip("Close this form.")
self.btnCloseForm.setText("Close")
self.btnCloseForm.setToolTip(translate("A2plus", "Close this form."))
self.btnCloseForm.setText(translate("A2plus", "Close"))
self.btnCloseForm.clicked.connect(lambda:self.Closeme())

def openViewer(self):
Expand Down Expand Up @@ -142,7 +144,7 @@ def __init__(self):
def startcheck(self):
''' Check for opened file '''
if FreeCAD.activeDocument() is None:
msg = 'A A2plus file must be opened to start this checker\nPlease open a file and try again'
msg = translate("A2plus", "A A2plus file must be opened to start this checker") + "\n" + translate("A2plus", "Please open a file and try again")
mApp(msg)
return

Expand All @@ -157,10 +159,10 @@ def startcheck(self):

constraints = self.getallconstraints()
if len(constraints) == 0:
mApp('Cannot find any constraints in this file.')
mApp(translate("A2plus", "Cannot find any constraints in this file."))
return()

statusform.showme('Checking constraints')
statusform.showme(translate("A2plus", "Checking constraints"))
self.dir_errors = a2p_constraintServices.redAdjustConstraintDirections(FreeCAD.activeDocument())
print(self.dir_errors)
self.checkformovement(constraints, True)
Expand All @@ -171,8 +173,8 @@ def startcheck(self):
msg = msg + line + '\n'
form1.showme(msg)
else:
print()
print('No constraint errors found')
FreeCAD.Console.PrintMessage("")
FreeCAD.Console.PrintMessage(translate("A2plus", "No constraint errors found") + "\n")
statusform.Closeme()


Expand All @@ -188,7 +190,7 @@ def checkformovement(self, constraintlist, putPartBack = True):
self.p2fix = False
self.setfix = 0
cobj = constraintlist[checkingnum]
statusform.setWindowTitle('Checking ' + str(checkingnum) + ' of ' + str(len(constraintlist)))
statusform.setWindowTitle(translate("A2plus", "Checking ") + str(checkingnum) + translate("A2plus", " of ") + str(len(constraintlist)))


subobj1 = cobj.getPropertyByName('Object1')
Expand Down Expand Up @@ -280,7 +282,7 @@ class formReport(QtGui.QDialog):
def __init__(self, name):
self.name = name
super(formReport, self).__init__()
self.setWindowTitle('Checking Constraints')
self.setWindowTitle(translate("A2plus", "Checking Constraints"))
self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
self.setGeometry(300, 100, 300, 40) # xy , wh
self.setStyleSheet("font: 10pt arial MS")
Expand Down Expand Up @@ -310,9 +312,6 @@ def rondlist(list, inch = False):
return([x, y, z])





def rondnum(num, mmorin = 'mm'):
# round a number to digits in global
# left in mm for accuracy.
Expand All @@ -322,16 +321,9 @@ def rondnum(num, mmorin = 'mm'):
return(rn)







toolTipText = \
'''
This checks all constraints. After checking it will list all constraints that it found problems with./n
The list can then be opened in the Constraint viewer.
'''
translate("A2plus", "This checks all constraints. After checking it will list all constraints that it found problems with.") + "/n" +\
translate("A2plus", "The list can then be opened in the Constraint viewer.")

class rnp_Constraint_Checker:

Expand All @@ -350,8 +342,8 @@ def GetResources(self):
mypath = os.path.dirname(__file__)
return {
'Pixmap' : mypath + "/icons/CD_ConstraintChecker.svg",
'MenuText': 'Checks constraints',
'ToolTip': 'Checks constraints'
'MenuText': translate("A2plus", "Checks constraints"),
'ToolTip': translate("A2plus", "Checks constraints")
}

FreeCADGui.addCommand('rnp_Constraint_Checker', rnp_Constraint_Checker())
Expand Down
58 changes: 30 additions & 28 deletions CD_featurelabels.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,35 @@
# This is to be used with A2plus Assembly WorkBench
#

import FreeCADGui
import FreeCAD
from PySide.QtGui import *
import FreeCADGui
# from PySide.QtGui import *
from PySide import QtGui, QtCore

translate = FreeCAD.Qt.translate

class formMain(QtGui.QMainWindow):
def __init__(self, name):
self.name = name
super(formMain, self).__init__()
self.setWindowTitle('Create Labels')
self.setWindowTitle(translate("A2plus", "Create Labels"))
self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
self.setGeometry(300, 200, 200, 200)
self.setGeometry(300, 200, 260, 200)
self.setStyleSheet("font: 11pt arial MS")

self.btnLabels = [['Add Face Labels', 'Add labels to all of the faces on a selected part'],
['Add Edge Labels', 'Add labels to all of the edges on a selected part'],
['Add Vertex Labels', 'Add labels to all of the vertices on a selected part'],
['Delete Labels', 'Delete all labels'],
['Close', '']
self.btnLabels = [[translate("A2plus", "Add Face Labels"), translate("A2plus", "Add labels to all of the faces on a selected part")],
[translate("A2plus", "Add Edge Labels"), translate("A2plus", "Add labels to all of the edges on a selected part")],
[translate("A2plus", "Add Vertex Labels"), translate("A2plus", "Add labels to all of the vertices on a selected part")],
[translate("A2plus", "Delete Labels"), translate("A2plus", "Delete all labels")],
[translate("A2plus", "Close"), '']
]
self.btns=[]
BtnNum = 0
for row in range(0, len(self.btnLabels)) :
btny = 20 +(28*row)
self.btn = QtGui.QPushButton( str(self.btnLabels[row][0]), self)
self.btn.move(5, btny)
self.btn.setFixedWidth(190)
self.btn.setFixedWidth(250)
self.btn.setFixedHeight(25)
self.btn.setToolTip(self.btnLabels[row][1])
self.btn.released.connect(self.button_pushed) # pressed
Expand All @@ -57,28 +59,28 @@ def __init__(self, name):
def button_pushed(self):
index = self.btns.index(self.sender())
btext = self.btns[index].text()
if btext == 'Add Face Labels':
labels.addlabels('Face')
if btext == 'Add Edge Labels':
labels.addlabels('Edge')
if btext == 'Add Vertex Labels':
labels.addlabels('Vertex')

if btext == 'Delete Labels':
if btext == translate("A2plus", "Add Face Labels"):
labels.addlabels(translate("A2plus", "Face"))
if btext == translate("A2plus", "Add Edge Labels"):
labels.addlabels(translate("A2plus", "Edge"))
if btext == translate("A2plus", "Add Vertex Labels"):
labels.addlabels(translate("A2plus", "Vertex"))

if btext == translate("A2plus", "Delete Labels"):
labels.deletelabels()
if btext == translate("A2plus", "Close"):
self.Closeme()

# Not present?
if btext == 'Attach to':
labels.attachto()
if btext == 'Close':
self.Closeme()
if btext == 'Selected Labels':
labels.selectedlabels()


def hideMe(self):
QtGui.Selection.clearSelection()
self.close()


def showme(self):
self.show()

Expand All @@ -102,7 +104,7 @@ def checkselection(self):
if self.labelGroup is None:
self.labelGroup = doc.addObject("App::DocumentObjectGroup", "partLabels")
if len(FreeCADGui.Selection.getSelection()) == 0:
mApp('One part must be selected.\nPlease select One part and try again')
mApp(translate("A2plus", "One part must be selected.") + "\n" + translate("A2plus", "Please select One part and try again"))
return(False)
return(True)

Expand All @@ -111,16 +113,16 @@ def addlabels(self, feat):
if not sel:
return
sel = FreeCADGui.Selection.getSelection() # Select an object
if feat == 'Face':
if feat == translate("A2plus", "Face"):
features = sel[0].Shape.Faces
if feat == 'Edge':
if feat == translate("A2plus", "Edge"):
features = sel[0].Shape.Edges
if feat == 'Vertex':
if feat == translate("A2plus", "Vertex"):
features = sel[0].Shape.Vertexes

for num in range(0, len(features)):
ent = features[num]
if feat == 'Vertex':
if feat == translate("A2plus", "Vertex"):
loc = ent.Point
else:
loc = ent.CenterOfMass
Expand Down Expand Up @@ -195,5 +197,5 @@ def __init__(self,msg):
def initUI(self,msg):
self.setGeometry(100, 100, 400, 300)
self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
QtGui.QMessageBox.question(self, 'Info', msg, QtGui.QMessageBox.Ok|QtGui.QMessageBox.Ok)
QtGui.QMessageBox.question(self, translate("A2plus", "Info"), msg, QtGui.QMessageBox.Ok|QtGui.QMessageBox.Ok)
self.show()
Loading

0 comments on commit 2541401

Please sign in to comment.