FlatCAMTool.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. ############################################################
  2. # FlatCAM: 2D Post-processing for Manufacturing #
  3. # http://flatcam.org #
  4. # Author: Juan Pablo Caram (c) #
  5. # Date: 2/5/2014 #
  6. # MIT Licence #
  7. ############################################################
  8. from PyQt4 import QtGui
  9. class FlatCAMTool(QtGui.QWidget):
  10. toolName = "FlatCAM Generic Tool"
  11. def __init__(self, app, parent=None):
  12. """
  13. :param app: The application this tool will run in.
  14. :type app: App
  15. :param parent: Qt Parent
  16. :return: FlatCAMTool
  17. """
  18. QtGui.QWidget.__init__(self, parent)
  19. # self.setSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Maximum)
  20. self.layout = QtGui.QVBoxLayout()
  21. self.setLayout(self.layout)
  22. self.app = app
  23. self.menuAction = None
  24. def install(self, icon=None, separator=None, **kwargs):
  25. before = None
  26. # 'pos' is the menu where the Action has to be installed
  27. # if no 'pos' kwarg is provided then by default our Action will be installed in the menutool
  28. # as it previously was
  29. if 'pos' in kwargs:
  30. pos = kwargs['pos']
  31. else:
  32. pos = self.app.ui.menutool
  33. # 'before' is the Action in the menu stated by 'pos' kwarg, before which we want our Action to be installed
  34. # if 'before' kwarg is not provided, by default our Action will be added in the last place.
  35. if 'before' in kwargs:
  36. before = (kwargs['before'])
  37. # create the new Action
  38. self.menuAction = QtGui.QAction(self)
  39. # if provided, add an icon to this Action
  40. if icon is not None:
  41. self.menuAction.setIcon(icon)
  42. # set the text name of the Action, which will be displayed in the menu
  43. self.menuAction.setText(self.toolName)
  44. # add a ToolTip to the new Action
  45. # self.menuAction.setToolTip(self.toolTip) # currently not available
  46. # insert the action in the position specified by 'before' and 'pos' kwargs
  47. pos.insertAction(before, self.menuAction)
  48. # if separator parameter is True add a Separator after the newly created Action
  49. if separator is True:
  50. pos.addSeparator()
  51. self.menuAction.triggered.connect(self.run)
  52. def run(self):
  53. # Remove anything else in the GUI
  54. self.app.ui.tool_scroll_area.takeWidget()
  55. # Put ourself in the GUI
  56. self.app.ui.tool_scroll_area.setWidget(self)
  57. # Switch notebook to tool page
  58. self.app.ui.notebook.setCurrentWidget(self.app.ui.tool_tab)
  59. self.show()