-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathLoadLicenseForm_Ribbon.py
More file actions
171 lines (141 loc) · 5.94 KB
/
LoadLicenseForm_Ribbon.py
File metadata and controls
171 lines (141 loc) · 5.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# *************************************************************************
# * *
# * Copyright (c) 2019-2024 Paul Ebbers *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
# * as published by the Free Software Foundation; either version 3 of *
# * the License, or (at your option) any later version. *
# * for detail see the LICENCE text file. *
# * *
# * This program is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# * GNU Library General Public License for more details. *
# * *
# * You should have received a copy of the GNU Library General Public *
# * License along with this program; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# *************************************************************************
import FreeCAD as App
import FreeCADGui as Gui
import os
from PySide.QtCore import Qt, SIGNAL
from PySide.QtWidgets import (
QTabWidget,
QSlider,
QSpinBox,
QCheckBox,
QComboBox,
QLabel,
QDialogButtonBox,
QApplication,
QPushButton,
QDialog,
)
from PySide.QtGui import QIcon, QPixmap
import sys
import Standard_Functions_Ribbon as StandardFunctions
import Parameters_Ribbon
# Get the resources
pathIcons = Parameters_Ribbon.ICON_LOCATION
pathStylSheets = Parameters_Ribbon.STYLESHEET_LOCATION
pathUI = Parameters_Ribbon.UI_LOCATION
pathBackup = Parameters_Ribbon.BACKUP_LOCATION
sys.path.append(pathIcons)
sys.path.append(pathStylSheets)
sys.path.append(pathUI)
sys.path.append(pathBackup)
# import graphical created Ui. (With QtDesigner or QtCreator)
import LicenseForm_ui as LicenseForm_ui
# Define the translation
translate = App.Qt.translate
class LoadDialog(LicenseForm_ui.Ui_Dialog):
FormLoaded = False
def __init__(self):
# Makes "self.on_CreateBOM_clicked" listen to the changed control values instead initial values
super(LoadDialog, self).__init__()
# # this will create a Qt widget from our ui file
self.form = Gui.PySideUic.loadUi(os.path.join(pathUI, "LicenseForm.ui"))
# Make sure that the dialog stays on top
# self.form.setWindowFlags(Qt.WindowType.WindowStaysOnTopHint)
self.form.setWindowFlags(Qt.WindowType.Tool)
self.form.setWindowModality(Qt.WindowModality.WindowModal)
# Get the style from the main window and use it for this form
mw = Gui.getMainWindow()
palette = mw.palette()
self.form.setPalette(palette)
Style = mw.style()
self.form.setStyle(Style)
GitData = StandardFunctions.GetGitData()
PackageXML = os.path.join(os.path.dirname(__file__), "package.xml")
version = StandardFunctions.ReturnXML_Value(PackageXML, "version")
Maintainer = StandardFunctions.ReturnXML_Value(PackageXML, "maintainer")
CommitID = GitData[0]
if CommitID is None:
CommitID = "-"
branch = GitData[1]
if branch is None:
branch = "-"
# Add a logo
pixmap = QPixmap(os.path.join(pathIcons, "FreecadNew.svg"))
self.form.LogoHolder.setFixedSize(pixmap.height(), pixmap.width())
self.form.LogoHolder.setPixmap(pixmap)
if QLabel(self.form.LogoHolder).pixmap() is None:
self.form.LogoHolder.setHidden(True)
self.form.LogoHolder.setDisabled(True)
# set the title text
self.form.TitleText.setText("Ribbon UI")
# Write here the introduction text and include the version
self.form.Introduction.setText(
translate(
"FreeCAD Ribbon",
f"""
A customizable ribbon UI for FreeCAD.
Developed by Paul Ebbers.
Current maintainer: {Maintainer}
Version information:
Installed version: {version}
Branch: {branch}
CommitID: {CommitID}
""",
)
)
# Add the copybutton
self.form.CopyVersionInfo.clicked.connect(
lambda: self.on_CopyVersionInfo_Clicked(
self,
f"Installed version: {version}\nBranch: {branch}\nCommit ID: {CommitID}",
),
)
# Write the text for credits
Contributers = GitData[2]
if len(Contributers) > 0:
text = translate("FreeCAD Ribbon", "Contributors:\n")
for Contributor in Contributers:
text = text + " - " + Contributor + "\n"
self.form.ContributersText.setText(text)
else:
self.form.groupBox.setDisabled(True)
self.form.groupBox.setHidden(True)
# Read the license file from the add-on directory
file_path = os.path.join(os.path.dirname(__file__), "LICENSE")
with open(file_path, "r") as file:
LICENSE = file.read()
self.form.LicenseText.setText(LICENSE)
# set only the ok button
self.form.buttonBox.setStandardButtons(self.form.buttonBox.StandardButton.Ok)
return
@staticmethod
def on_CopyVersionInfo_Clicked(self, Text):
StandardFunctions.AddToClipboard(Text)
print(Text)
return
def main():
# Get the form
Dialog = LoadDialog().form
# Show the form
Dialog.show()
return