8 """ |
8 """ |
9 |
9 |
10 import os |
10 import os |
11 import platform |
11 import platform |
12 |
12 |
13 from PyQt5.QtCore import QObject, QTranslator, QCoreApplication, QProcess |
13 from PyQt6.QtCore import QObject, QTranslator, QCoreApplication, QProcess |
14 from PyQt5.QtWidgets import QDialog |
14 from PyQt6.QtWidgets import QDialog |
15 |
15 |
16 from E5Gui import E5MessageBox |
16 from EricWidgets import EricMessageBox |
17 from E5Gui.E5Action import E5Action |
17 from EricGui.EricAction import EricAction |
18 from E5Gui.E5Application import e5App |
18 from EricWidgets.EricApplication import ericApp |
19 |
19 |
20 import Utilities |
20 import Utilities |
21 |
21 |
22 # Start-of-Header |
22 # Start-of-Header |
23 name = "CxFreeze Plugin" |
23 name = "CxFreeze Plugin" |
24 author = "Detlev Offenbach <detlev@die-offenbachs.de>" |
24 author = "Detlev Offenbach <detlev@die-offenbachs.de>" |
25 autoactivate = True |
25 autoactivate = True |
26 deactivateable = True |
26 deactivateable = True |
27 version = "7.2.0" |
27 version = "1.0.0" |
28 className = "CxFreezePlugin" |
28 className = "CxFreezePlugin" |
29 packageName = "CxFreeze" |
29 packageName = "CxFreeze" |
30 shortDescription = "Show the CxFreeze dialogs." |
30 shortDescription = "Show the CxFreeze dialogs." |
31 longDescription = ( |
31 longDescription = ( |
32 """This plugin implements the CxFreeze dialogs.""" |
32 """This plugin implements the CxFreeze dialogs.""" |
73 |
74 |
74 def _findExecutable(majorVersion): |
75 def _findExecutable(majorVersion): |
75 """ |
76 """ |
76 Restricted function to determine the names of the executable. |
77 Restricted function to determine the names of the executable. |
77 |
78 |
78 @param majorVersion major python version of the executables (int) |
79 @param majorVersion major Python version of the executables |
79 @return names of the executable (list) |
80 @type int |
|
81 @return names of the executable |
|
82 @rtype list of str |
80 """ |
83 """ |
81 # Determine Python Version |
84 # Determine Python Version |
82 if majorVersion == 3: |
85 if majorVersion == 3: |
83 minorVersions = range(10) |
86 minorVersions = range(10) |
84 else: |
87 else: |
261 |
267 |
262 # cxfreeze is only activated if it is available |
268 # cxfreeze is only activated if it is available |
263 if not _checkProgram(): |
269 if not _checkProgram(): |
264 return None, False |
270 return None, False |
265 |
271 |
266 project = e5App().getObject("Project") |
272 project = ericApp().getObject("Project") |
267 menu = project.getMenu("Packagers") |
273 menu = project.getMenu("Packagers") |
268 if menu: |
274 if menu: |
269 self.__projectAct = E5Action( |
275 self.__projectAct = EricAction( |
270 self.tr('Use cx_freeze'), |
276 self.tr('Use cx_freeze'), |
271 self.tr('Use cx_&freeze'), 0, 0, |
277 self.tr('Use cx_&freeze'), 0, 0, |
272 self, 'packagers_cxfreeze') |
278 self, 'packagers_cxfreeze') |
273 self.__projectAct.setStatusTip( |
279 self.__projectAct.setStatusTip( |
274 self.tr('Generate a distribution package using cx_freeze')) |
280 self.tr('Generate a distribution package using cx_freeze')) |
278 """ The command is executed in the project path. All""" |
284 """ The command is executed in the project path. All""" |
279 """ files and directories must be given absolute or""" |
285 """ files and directories must be given absolute or""" |
280 """ relative to the project directory.</p>""" |
286 """ relative to the project directory.</p>""" |
281 )) |
287 )) |
282 self.__projectAct.triggered.connect(self.__cxfreeze) |
288 self.__projectAct.triggered.connect(self.__cxfreeze) |
283 project.addE5Actions([self.__projectAct]) |
289 project.addEricActions([self.__projectAct]) |
284 self.__projectSeparator = menu.addSeparator() |
290 self.__projectSeparator = menu.addSeparator() |
285 menu.addAction(self.__projectAct) |
291 menu.addAction(self.__projectAct) |
286 project.showMenu.connect(self.__projectShowMenu) |
292 project.showMenu.connect(self.__projectShowMenu) |
287 |
293 |
288 error = "" |
294 error = "" |
290 |
296 |
291 def deactivate(self): |
297 def deactivate(self): |
292 """ |
298 """ |
293 Public method to deactivate this plugin. |
299 Public method to deactivate this plugin. |
294 """ |
300 """ |
295 menu = e5App().getObject("Project").getMenu("Packagers") |
301 menu = ericApp().getObject("Project").getMenu("Packagers") |
296 if menu: |
302 if menu: |
297 if self.__projectAct: |
303 if self.__projectAct: |
298 menu.removeAction(self.__projectAct) |
304 menu.removeAction(self.__projectAct) |
299 e5App().getObject("Project").removeE5Actions( |
305 ericApp().getObject("Project").removeEricActions( |
300 [self.__projectAct]) |
306 [self.__projectAct]) |
301 if self.__projectSeparator: |
307 if self.__projectSeparator: |
302 menu.removeAction(self.__projectSeparator) |
308 menu.removeAction(self.__projectSeparator) |
303 |
309 |
304 self.__initialize() |
310 self.__initialize() |
306 def __projectShowMenu(self, menuName, menu): |
312 def __projectShowMenu(self, menuName, menu): |
307 """ |
313 """ |
308 Private slot called, when the the project menu or a submenu is |
314 Private slot called, when the the project menu or a submenu is |
309 about to be shown. |
315 about to be shown. |
310 |
316 |
311 @param menuName name of the menu to be shown (string) |
317 @param menuName name of the menu to be shown |
312 @param menu reference to the menu (QMenu) |
318 @type str |
|
319 @param menu reference to the menu |
|
320 @type QMenu |
313 """ |
321 """ |
314 if ( |
322 if ( |
315 menuName == "Packagers" and |
323 menuName == "Packagers" and |
316 self.__projectAct is not None |
324 self.__projectAct is not None |
317 ): |
325 ): |
318 self.__projectAct.setEnabled( |
326 self.__projectAct.setEnabled( |
319 e5App().getObject("Project").getProjectLanguage() == |
327 ericApp().getObject("Project").getProjectLanguage() == |
320 "Python3" |
328 "Python3" |
321 ) |
329 ) |
322 |
330 |
323 def __loadTranslator(self): |
331 def __loadTranslator(self): |
324 """ |
332 """ |
332 translation = "cxfreeze_{0}".format(loc) |
340 translation = "cxfreeze_{0}".format(loc) |
333 translator = QTranslator(None) |
341 translator = QTranslator(None) |
334 loaded = translator.load(translation, locale_dir) |
342 loaded = translator.load(translation, locale_dir) |
335 if loaded: |
343 if loaded: |
336 self.__translator = translator |
344 self.__translator = translator |
337 e5App().installTranslator(self.__translator) |
345 ericApp().installTranslator(self.__translator) |
338 else: |
346 else: |
339 print("Warning: translation file '{0}' could not be" |
347 print("Warning: translation file '{0}' could not be" |
340 " loaded.".format(translation)) |
348 " loaded.".format(translation)) |
341 print("Using default.") |
349 print("Using default.") |
342 |
350 |
343 def __cxfreeze(self): |
351 def __cxfreeze(self): |
344 """ |
352 """ |
345 Private slot to handle the cxfreeze execution. |
353 Private slot to handle the cxfreeze execution. |
346 """ |
354 """ |
347 project = e5App().getObject("Project") |
355 project = ericApp().getObject("Project") |
348 if not project.getMainScript(): |
356 if not project.getMainScript(): |
349 # no main script defined |
357 # no main script defined |
350 E5MessageBox.critical( |
358 EricMessageBox.critical( |
351 self.__ui, |
359 self.__ui, |
352 self.tr("cxfreeze"), |
360 self.tr("cxfreeze"), |
353 self.tr( |
361 self.tr( |
354 """There is no main script defined for the current""" |
362 """There is no main script defined for the current""" |
355 """ project."""), |
363 """ project."""), |
356 E5MessageBox.StandardButtons(E5MessageBox.Abort)) |
364 EricMessageBox.StandardButtons(EricMessageBox.Abort)) |
357 return |
365 return |
358 |
366 |
359 majorVersionStr = project.getProjectLanguage() |
367 majorVersionStr = project.getProjectLanguage() |
360 exe = {"Python3": exePy3}.get(majorVersionStr) |
368 exe = {"Python3": exePy3}.get(majorVersionStr) |
361 if exe == []: |
369 if exe == []: |
362 E5MessageBox.critical( |
370 EricMessageBox.critical( |
363 self.__ui, |
371 self.__ui, |
364 self.tr("cxfreeze"), |
372 self.tr("cxfreeze"), |
365 self.tr("""The cxfreeze executable could not be found.""")) |
373 self.tr("""The cxfreeze executable could not be found.""")) |
366 return |
374 return |
367 |
375 |
370 return |
378 return |
371 |
379 |
372 from CxFreeze.CxfreezeConfigDialog import CxfreezeConfigDialog |
380 from CxFreeze.CxfreezeConfigDialog import CxfreezeConfigDialog |
373 parms = project.getData('PACKAGERSPARMS', "CXFREEZE") |
381 parms = project.getData('PACKAGERSPARMS', "CXFREEZE") |
374 dlg = CxfreezeConfigDialog(project, exe, parms) |
382 dlg = CxfreezeConfigDialog(project, exe, parms) |
375 if dlg.exec() == QDialog.Accepted: |
383 if dlg.exec() == QDialog.DialogCode.Accepted: |
376 args, parms = dlg.generateParameters() |
384 args, parms = dlg.generateParameters() |
377 project.setData('PACKAGERSPARMS', "CXFREEZE", parms) |
385 project.setData('PACKAGERSPARMS', "CXFREEZE", parms) |
378 |
386 |
379 # now do the call |
387 # now do the call |
380 from CxFreeze.CxfreezeExecDialog import CxfreezeExecDialog |
388 from CxFreeze.CxfreezeExecDialog import CxfreezeExecDialog |
383 res = dia.start(args, parms, project.ppath, |
391 res = dia.start(args, parms, project.ppath, |
384 project.getMainScript()) |
392 project.getMainScript()) |
385 if res: |
393 if res: |
386 dia.exec() |
394 dia.exec() |
387 |
395 |
|
396 |
|
397 def installDependencies(pipInstall): |
|
398 """ |
|
399 Function to install dependencies of this plug-in. |
|
400 |
|
401 @param pipInstall function to be called with a list of package names. |
|
402 @type function |
|
403 """ |
|
404 try: |
|
405 import cx_Freeze # __IGNORE_WARNING__ |
|
406 except ImportError: |
|
407 pipInstall(["cx-Freeze"]) |
|
408 |
388 # |
409 # |
389 # eflag: noqa = M801 |
410 # eflag: noqa = M801 |