Mario Voigt 2022-01-31 23:11:46 +01:00
commit fbe42ace63

View File

@ -16,7 +16,13 @@ import tempfile
dirpathTempFolder = tempfile.TemporaryDirectory(suffix=str(random.randint(0,9)), prefix="output-")
dirpathSoftware = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'outputpro')
uuconv = {'in':90.0, 'pt':1.25, 'px':1, 'mm':3.5433070866, 'cm':35.433070866, 'pc':15.0}
uuconv = { #those values might be old/incorrect
'in':90.0,
'pt':1.25,
'px':1,
'mm':3.5433070866,
'cm':35.433070866,
'pc':15.0}
def unittouu(string):
'''Returns userunits given a string representation of units in another system'''
@ -39,6 +45,11 @@ def unittouu(string):
class OutputPro(inkex.EffectExtension):
def effect(self):
if "nt" in os.name:
icc_dir = 'C:\\Windows\\System32\\spool\\drivers\\color'
else:
icc_dir = '/usr/share/color/icc/colord/'
try:
with open(os.path.join(os.path.abspath(inkex.utils.get_user_directory() + "/../"), "preferences.xml"), 'r') as f:
inkscape_config = f.read()
@ -53,22 +64,15 @@ class OutputPro(inkex.EffectExtension):
list_of_area_to_export = [_(u"Page"), _(u"Drawing"), _(u"Object")]#, _(u"Área definida")]
if "nt" in os.name:
icc_dir = 'C:\\Windows\\System32\\spool\\drivers\\color'
shell = True
else:
icc_dir = '/usr/share/color/icc/colord/'
shell = False
list_of_profiles = os.listdir(icc_dir)
#inkex.utils.debug(list_of_profiles)
selected_screen_profile = inkscape_config.split('id="displayprofile"')[1].split('uri="')[1].split('" />')[0].split('/')[-1]
#if selected_screen_profile == '':
# inkex.utils.debug("Configured icc color profile (Inkscape) is not set. Configure it in preferences and restart Inkscape to apply changes.")
selected_print_profile = inkscape_config.split('id="softproof"')[1].split('uri="')[1].split('" />')[0].split('/')[-1]
rgb_profile = '"' + inkscape_config.split('id="displayprofile"')[1].split('uri="')[1].split('" />')[0] + '"'
#cmyk_profile = '"' + inkscape_config.split('id="softproof"')[1].split('uri="')[1].split('" />')[0] + '"'
list_of_selected_objects = []
for id, node in self.svg.selected.items():
list_of_selected_objects.append(node.get('id'))
@ -86,6 +90,8 @@ class OutputPro(inkex.EffectExtension):
page_height = unittouu(svg.attrib['height'])
class mainWindow(QtWidgets.QWidget):
def __init__(self, parent=None):
QtWidgets.QWidget.__init__(self, parent)
self.resize(950, 600)
@ -183,13 +189,6 @@ class OutputPro(inkex.EffectExtension):
self.view_image_info.setWordWrap(True)
self.view_image_info.setAlignment(QtCore.Qt.AlignTop)
#self.main_title = QtWidgets.QLabel(parent=self)
#self.main_title.setText(_(u"BITMAPS").upper())
#self.main_title.setGeometry(640, 30, 150, 30)
#self.main_title.setFont(QtWidgets.QFont('Ubuntu', 16, 75))
#self.main_title.setAlignment(QtCore.Qt.AlignRight)
#self.main_title.setForegroundRole(QtWidgets.QPalette.ColorRole(2))
self.format_title = QtWidgets.QLabel(parent=self)
self.format_title.setText(_(u"Format").upper())
self.format_title.setGeometry(320, 70, 200, 15)
@ -229,19 +228,12 @@ class OutputPro(inkex.EffectExtension):
self.icc_dir_textbox = QtWidgets.QLineEdit(parent=self.general_options_panel_jpeg)
self.icc_dir_textbox.setReadOnly(True)
self.icc_dir_textbox.setGeometry(130, 280, 140, 25)
self.icc_dir_textbox.setGeometry(130, 280, 260, 25)
self.icc_dir_textbox.setText(icc_dir)
self.icc_dir_button = QtWidgets.QPushButton(_("Change"), parent=self.general_options_panel_jpeg)
self.icc_dir_button.setGeometry(283, 280, 50, 25)
self.icc_dir_button.setGeometry(403, 280, 70, 25)
self.icc_dir_button.clicked.connect(self.change_icc_dir)
#self.icc_select = QtWidgets.QFileDialog()
#self.icc_select.setFileMode(QtGui.QFileDialog.DirectoryOnly)
#self.icc_select.setSidebarUrls([QtCore.QUrl.fromLocalFile(place)])
#icc_dir = self.icc_select.getExistingDirectory(self, 'ICC profile folder')
#inkex.utils.debug(icc_dir)
self.color_mode_title_jpeg = QtWidgets.QLabel(parent=self.general_options_panel_jpeg)
self.color_mode_title_jpeg.setText(_(u"Color mode").upper())
@ -256,7 +248,6 @@ class OutputPro(inkex.EffectExtension):
self.color_mode_title_tip_jpeg = QtWidgets.QLabel(parent=self.general_options_panel_jpeg)
self.color_mode_title_tip_jpeg.setGeometry(10, 50, 260, 15)
self.color_mode_title_tip_jpeg.setFont(QtGui.QFont('Ubuntu', 7))
#self.color_mode_title_tip.setAlignment(QtCore.Qt.AlignLeft)
self.quality_title_jpeg = QtWidgets.QLabel(parent=self.general_options_panel_jpeg)
self.quality_title_jpeg.setText(_(u"Quality").upper())
@ -272,13 +263,13 @@ class OutputPro(inkex.EffectExtension):
self.quality_percent_title_left_jpeg = QtWidgets.QLabel(parent=self.general_options_panel_jpeg)
self.quality_percent_title_left_jpeg.setText('Lower quality\nSmaller file')
self.quality_percent_title_left_jpeg.setGeometry(285, 40, 160, 25)
self.quality_percent_title_left_jpeg.setGeometry(285, 40, 160, 35)
self.quality_percent_title_left_jpeg.setFont(QtGui.QFont('Ubuntu', 7))
self.quality_percent_title_left_jpeg.setAlignment(QtCore.Qt.AlignLeft)
self.quality_percent_title_right_jpeg = QtWidgets.QLabel(parent=self.general_options_panel_jpeg)
self.quality_percent_title_right_jpeg.setText('Higher quality<br>Larger file')
self.quality_percent_title_right_jpeg.setGeometry(445, 40, 160, 25)
self.quality_percent_title_right_jpeg.setGeometry(445, 40, 160, 35)
self.quality_percent_title_right_jpeg.setFont(QtGui.QFont('Ubuntu', 7))
self.quality_percent_title_right_jpeg.setAlignment(QtCore.Qt.AlignRight)
@ -335,7 +326,7 @@ class OutputPro(inkex.EffectExtension):
self.jpeg_noise_choice_jpeg.activated.connect(self.generate_preview)
self.jpeg_noise_ammount_jpeg = QtWidgets.QSlider(QtCore.Qt.Horizontal, parent=self.general_options_panel_jpeg)
self.jpeg_noise_ammount_jpeg.setGeometry(15, 175, 260, 25)
self.jpeg_noise_ammount_jpeg.setGeometry(10, 170, 260, 25)
self.jpeg_noise_ammount_jpeg.setRange(0,100)
self.jpeg_noise_ammount_jpeg.setEnabled(False)
self.jpeg_noise_ammount_jpeg.setValue(0)
@ -577,7 +568,7 @@ class OutputPro(inkex.EffectExtension):
if self.color_profile_choice_jpeg.isChecked():
final_command.append('-profile')
final_command.append(os.path.join(icc_dir, selected_screen_profile))
final_command.append(os.path.join(self.icc_dir_textbox.getText(), selected_screen_profile))
final_command.append(os.path.join(dirpathTempFolder.name, 'result.png'))
subprocess.Popen(final_command, shell=shell).wait()
@ -672,9 +663,9 @@ class OutputPro(inkex.EffectExtension):
if list_of_color_modes_jpeg[self.color_mode_choice_jpeg.currentIndex()] == 'CMYK' or list_of_color_modes_jpeg[self.color_mode_choice_jpeg.currentIndex()] == 'RGB':
if self.color_profile_choice_jpeg.isChecked():
pre_command.append('-profile')
pre_command.append(os.path.join(icc_dir, selected_screen_profile))
pre_command.append(os.path.join(self.icc_dir_textbox.getText(), selected_screen_profile))
pre_command.append('-profile')
pre_command.append(os.path.join(icc_dir, selected_screen_profile))
pre_command.append(os.path.join(self.icc_dir_textbox.getText(), selected_screen_profile))
if list_of_color_modes_jpeg[self.color_mode_choice_jpeg.currentIndex()] == 'RGB':
pre_command.append(os.path.join(dirpathTempFolder.name, 'result.tiff'))
@ -683,7 +674,7 @@ class OutputPro(inkex.EffectExtension):
pre_command.append('convert')
pre_command.append(os.path.join(dirpathTempFolder.name, 'result.tiff'))
pre_command.append('-profile')
pre_command.append(os.path.join(icc_dir, selected_screen_profile))
pre_command.append(os.path.join(self.icc_dir_textbox.getText(), selected_screen_profile))
pre_command.append(os.path.join(dirpathTempFolder.name, 'result.tiff'))
subprocess.Popen(pre_command, shell=shell).wait()
@ -695,7 +686,7 @@ class OutputPro(inkex.EffectExtension):
pre_command = ['convert']
pre_command.append(os.path.join(dirpathTempFolder.name, 'result.tiff'))
pre_command.append('-profile')
pre_command.append(os.path.join(icc_dir, selected_screen_profile))
pre_command.append(os.path.join(self.icc_dir_textbox.getText(), selected_screen_profile))
pre_command.append(os.path.join(dirpathTempFolder.name, 'result.tiff'))
subprocess.Popen(pre_command, shell=shell).wait()
@ -1082,7 +1073,7 @@ class OutputPro(inkex.EffectExtension):
shutil.copy2(result_imp, target_imp)
def change_icc_dir(self):
inkex.utils.debug("change_icc_dir")
self.icc_dir_textbox.setText(QtWidgets.QFileDialog.getExistingDirectory(self, 'Select Folder'))
app = QtWidgets.QApplication(sys.argv)
app.main = mainWindow()