Exemplo n.º 1
0
class FlatCAMInfoBar(QWidget):
    def __init__(self, parent=None):
        super(FlatCAMInfoBar, self).__init__(parent=parent)

        self.icon = QLabel(self)
        self.icon.setGeometry(0, 0, 12, 12)
        self.pmap = QtGui.QPixmap('share/graylight12.png')
        self.icon.setPixmap(self.pmap)

        layout = QHBoxLayout()
        layout.setContentsMargins(5, 0, 5, 0)
        self.setLayout(layout)

        layout.addWidget(self.icon)

        self.text = QLabel(self)
        self.text.setText("Hello!")
        self.text.setToolTip("Hello!")

        layout.addWidget(self.text)

        layout.addStretch()

    def set_text_(self, text):
        self.text.setText(text)
        self.text.setToolTip(text)

    def set_status(self, text, level="info"):
        level = str(level)
        self.pmap.fill()
        if level == "error":
            self.pmap = QtGui.QPixmap('share/redlight12.png')
        elif level == "success":
            self.pmap = QtGui.QPixmap('share/greenlight12.png')
        elif level == "warning":
            self.pmap = QtGui.QPixmap('share/yellowlight12.png')
        else:
            self.pmap = QtGui.QPixmap('share/graylight12.png')

        self.icon.setPixmap(self.pmap)
        self.set_text_(text)
Exemplo n.º 2
0
class FlatCAMGUI(QMainWindow):

    # Emitted when persistent window geometry needs to be retained
    geom_update = QtCore.pyqtSignal(int, int, int, int, name='geomUpdate')

    def __init__(self, version, name=None):
        super(FlatCAMGUI, self).__init__()

        # Divine icon pack by Ipapun @ finicons.com

        ############
        ### Menu ###
        ############
        self.menu = self.menuBar()

        ### File ###
        self.menufile = self.menu.addMenu('&File')

        # New
        self.menufilenew = QAction(QtGui.QIcon('share/file16.png'),
                                   '&New project', self)
        self.menufile.addAction(self.menufilenew)

        # Recent
        self.recent = self.menufile.addMenu(QtGui.QIcon('share/folder16.png'),
                                            "Open recent ...")

        # Separator
        self.menufile.addSeparator()

        # Open gerber ...
        self.menufileopengerber = QAction(QtGui.QIcon('share/folder16.png'),
                                          'Open &Gerber ...', self)
        self.menufile.addAction(self.menufileopengerber)

        # Open Excellon ...
        self.menufileopenexcellon = QAction(QtGui.QIcon('share/folder16.png'),
                                            'Open &Excellon ...', self)
        self.menufile.addAction(self.menufileopenexcellon)

        # Open G-Code ...
        self.menufileopengcode = QAction(QtGui.QIcon('share/folder16.png'),
                                         'Open G-&Code ...', self)
        self.menufile.addAction(self.menufileopengcode)

        # Open Project ...
        self.menufileopenproject = QAction(QtGui.QIcon('share/folder16.png'),
                                           'Open &Project ...', self)
        self.menufile.addAction(self.menufileopenproject)

        # Separator
        self.menufile.addSeparator()

        # Import SVG ...
        self.menufileimportsvg = QAction(QtGui.QIcon('share/folder16.png'),
                                         'Import &SVG ...', self)
        self.menufile.addAction(self.menufileimportsvg)

        # Export SVG ...
        self.menufileexportsvg = QAction(QtGui.QIcon('share/folder16.png'),
                                         'Export &SVG ...', self)
        self.menufile.addAction(self.menufileexportsvg)

        # Separator
        self.menufile.addSeparator()

        # Save Project
        self.menufilesaveproject = QAction(QtGui.QIcon('share/floppy16.png'),
                                           '&Save Project', self)
        self.menufile.addAction(self.menufilesaveproject)

        # Save Project As ...
        self.menufilesaveprojectas = QAction(QtGui.QIcon('share/floppy16.png'),
                                             'Save Project &As ...', self)
        self.menufile.addAction(self.menufilesaveprojectas)

        # Save Project Copy ...
        self.menufilesaveprojectcopy = QAction(
            QtGui.QIcon('share/floppy16.png'), 'Save Project C&opy ...', self)
        self.menufile.addAction(self.menufilesaveprojectcopy)

        # Save Defaults
        self.menufilesavedefaults = QAction(QtGui.QIcon('share/floppy16.png'),
                                            'Save &Defaults', self)
        self.menufile.addAction(self.menufilesavedefaults)

        # Separator
        self.menufile.addSeparator()

        # Quit
        self.exit_action = QAction(QtGui.QIcon('share/power16.png'), '&Exit',
                                   self)
        self.menufile.addAction(self.exit_action)
        # exitAction.setShortcut('Ctrl+Q')
        # exitAction.setStatusTip('Exit application')
        #self.exit_action.triggered.connect(QtGui.qApp.quit)

        ### Edit ###
        self.menuedit = self.menu.addMenu('&Edit')
        self.menueditnew = self.menuedit.addAction(
            QtGui.QIcon('share/new_geo16.png'), 'New Geometry')
        self.menueditedit = self.menuedit.addAction(
            QtGui.QIcon('share/edit16.png'), 'Edit Geometry')
        self.menueditok = self.menuedit.addAction(
            QtGui.QIcon('share/edit_ok16.png'), 'Update Geometry')
        # Separator
        self.menuedit.addSeparator()
        self.menueditjoin = self.menuedit.addAction(
            QtGui.QIcon('share/join16.png'), 'Join Geometry')
        self.menueditdelete = self.menuedit.addAction(
            QtGui.QIcon('share/trash16.png'), 'Delete')
        self.menuedit.addSeparator()

        ### Options ###
        self.menuoptions = self.menu.addMenu('&Options')
        self.menuoptions_transfer = self.menuoptions.addMenu(
            QtGui.QIcon('share/transfer.png'), 'Transfer options')
        self.menuoptions_transfer_a2p = self.menuoptions_transfer.addAction(
            "Application to Project")
        self.menuoptions_transfer_p2a = self.menuoptions_transfer.addAction(
            "Project to Application")
        self.menuoptions_transfer_p2o = self.menuoptions_transfer.addAction(
            "Project to Object")
        self.menuoptions_transfer_o2p = self.menuoptions_transfer.addAction(
            "Object to Project")
        self.menuoptions_transfer_a2o = self.menuoptions_transfer.addAction(
            "Application to Object")
        self.menuoptions_transfer_o2a = self.menuoptions_transfer.addAction(
            "Object to Application")

        ### View ###
        self.menuview = self.menu.addMenu('&View')
        self.menuviewdisableall = self.menuview.addAction(
            QtGui.QIcon('share/clear_plot16.png'), 'Disable all plots')
        self.menuviewdisableother = self.menuview.addAction(
            QtGui.QIcon('share/clear_plot16.png'),
            'Disable all plots but this one')
        self.menuviewenable = self.menuview.addAction(
            QtGui.QIcon('share/replot16.png'), 'Enable all plots')

        ### Tool ###

        self.menutool = QMenu('&Tool')
        self.menutoolaction = self.menu.addMenu(self.menutool)
        self.menutoolshell = self.menutool.addAction(
            QtGui.QIcon('share/shell16.png'), '&Command Line')

        ### Help ###
        self.menuhelp = self.menu.addMenu('&Help')
        self.menuhelp_about = self.menuhelp.addAction(
            QtGui.QIcon('share/tv16.png'), 'About FlatCAM')
        self.menuhelp_home = self.menuhelp.addAction(
            QtGui.QIcon('share/home16.png'), 'Home')
        self.menuhelp_manual = self.menuhelp.addAction(
            QtGui.QIcon('share/globe16.png'), 'Manual')

        ###############
        ### Toolbar ###
        ###############
        self.toolbarfile = QToolBar('File Toolbar')
        self.addToolBar(self.toolbarfile)
        self.open_gerber_btn = self.toolbarfile.addAction(
            QtGui.QIcon('share/flatcam_icon32.png'), "Open &Gerber")
        self.open_exc_btn = self.toolbarfile.addAction(
            QtGui.QIcon('share/drill32.png'), "Open &Excellon")
        self.open_gcode_btn = self.toolbarfile.addAction(
            QtGui.QIcon('share/cnc32.png'), "Open Gco&de")
        self.save_btn = self.toolbarfile.addAction(
            QtGui.QIcon('share/floppy32.png'), 'Save Project &As ...')

        self.toolbarview = QToolBar('View Toolbar')
        self.addToolBar(self.toolbarview)
        self.zoom_fit_btn = self.toolbarview.addAction(
            QtGui.QIcon('share/zoom_fit32.png'), "&Zoom Fit")
        self.zoom_out_btn = self.toolbarview.addAction(
            QtGui.QIcon('share/zoom_out32.png'), "&Zoom Out")
        self.zoom_in_btn = self.toolbarview.addAction(
            QtGui.QIcon('share/zoom_in32.png'), "&Zoom In")
        # Separator
        self.toolbarview.addSeparator()
        self.clear_plot_btn = self.toolbarview.addAction(
            QtGui.QIcon('share/clear_plot32.png'), "&Clear Plot")
        self.replot_btn = self.toolbarview.addAction(
            QtGui.QIcon('share/replot32.png'), "&Replot")

        self.toolbareditobj = QToolBar('Obj.Editor Toolbar')
        self.addToolBar(self.toolbareditobj)
        self.newgeo_btn = self.toolbareditobj.addAction(
            QtGui.QIcon('share/new_geo32.png'), "New Blank Geometry")
        self.editgeo_btn = self.toolbareditobj.addAction(
            QtGui.QIcon('share/edit32.png'), "Edit Geometry")
        self.updategeo_btn = self.toolbareditobj.addAction(
            QtGui.QIcon('share/edit_ok32.png'), "Update Geometry")
        self.updategeo_btn.setEnabled(False)

        self.toolbaredit = QToolBar('Edit Toolbar')
        self.addToolBar(self.toolbaredit)
        self.delete_btn = self.toolbaredit.addAction(
            QtGui.QIcon('share/delete32.png'), "&Delete")

        self.toolbartools = QToolBar('Tools Toolbar')
        self.addToolBar(self.toolbartools)
        self.shell_btn = self.toolbartools.addAction(
            QtGui.QIcon('share/shell32.png'), "&Command Line")
        self.measure_btn = self.toolbartools.addAction(
            QtGui.QIcon('share/measure32.png'), "&Measurement Tool")

        ################
        ### Splitter ###
        ################
        self.splitter = QSplitter()
        self.setCentralWidget(self.splitter)

        ################
        ### Notebook ###
        ################
        self.notebook = QTabWidget()

        # self.notebook.setMinimumWidth(250)

        ### Project ###
        project_tab = QWidget()
        project_tab.setMinimumWidth(250)  # Hack
        self.project_tab_layout = QVBoxLayout(project_tab)
        self.project_tab_layout.setContentsMargins(2, 2, 2, 2)
        self.notebook.addTab(project_tab, "Project")

        ### Selected ###
        self.selected_tab = QWidget()
        self.selected_tab_layout = QVBoxLayout(self.selected_tab)
        self.selected_tab_layout.setContentsMargins(2, 2, 2, 2)
        self.selected_scroll_area = VerticalScrollArea()
        self.selected_tab_layout.addWidget(self.selected_scroll_area)
        self.notebook.addTab(self.selected_tab, "Selected")

        ### Options ###
        self.options_tab = QWidget()
        self.options_tab.setContentsMargins(0, 0, 0, 0)
        self.options_tab_layout = QVBoxLayout(self.options_tab)
        self.options_tab_layout.setContentsMargins(2, 2, 2, 2)

        hlay1 = QHBoxLayout()
        self.options_tab_layout.addLayout(hlay1)

        self.icon = QLabel()
        self.icon.setPixmap(QtGui.QPixmap('share/gear48.png'))
        hlay1.addWidget(self.icon)

        self.options_combo = QComboBox()
        self.options_combo.addItem("APPLICATION DEFAULTS")
        self.options_combo.addItem("PROJECT OPTIONS")
        hlay1.addWidget(self.options_combo)
        hlay1.addStretch()

        self.options_scroll_area = VerticalScrollArea()
        self.options_tab_layout.addWidget(self.options_scroll_area)

        self.notebook.addTab(self.options_tab, "Options")

        ### Tool ###
        self.tool_tab = QWidget()
        self.tool_tab_layout = QVBoxLayout(self.tool_tab)
        self.tool_tab_layout.setContentsMargins(2, 2, 2, 2)
        self.notebook.addTab(self.tool_tab, "Tool")
        self.tool_scroll_area = VerticalScrollArea()
        self.tool_tab_layout.addWidget(self.tool_scroll_area)

        self.splitter.addWidget(self.notebook)

        ######################
        ### Plot and other ###
        ######################
        right_widget = QWidget()
        # right_widget.setContentsMargins(0, 0, 0, 0)
        self.splitter.addWidget(right_widget)
        self.right_layout = QVBoxLayout()
        #self.right_layout.setMargin(0)
        self.right_layout.setContentsMargins(0, 0, 0, 0)
        right_widget.setLayout(self.right_layout)

        ################
        ### Info bar ###
        ################
        infobar = self.statusBar()

        #self.info_label = QLabel("Welcome to FlatCAM.")
        #self.info_label.setFrameStyle(QtGui.QFrame.StyledPanel | QtGui.QFrame.Plain)
        #infobar.addWidget(self.info_label, stretch=1)
        self.fcinfo = FlatCAMInfoBar()
        infobar.addWidget(self.fcinfo, stretch=1)

        self.position_label = QLabel("")
        #self.position_label.setFrameStyle(QtGui.QFrame.StyledPanel | QtGui.QFrame.Plain)
        self.position_label.setMinimumWidth(110)
        infobar.addWidget(self.position_label)

        self.units_label = QLabel("[in]")
        # self.units_label.setFrameStyle(QtGui.QFrame.StyledPanel | QtGui.QFrame.Plain)
        self.units_label.setMargin(2)
        infobar.addWidget(self.units_label)

        self.progress_bar = QProgressBar()
        self.progress_bar.setMinimum(0)
        self.progress_bar.setMaximum(100)
        #infobar.addWidget(self.progress_bar)

        self.activity_view = FlatCAMActivityView()
        infobar.addWidget(self.activity_view)

        #############
        ### Icons ###
        #############
        self.app_icon = QtGui.QIcon()
        self.app_icon.addFile('share/flatcam_icon16.png', QtCore.QSize(16, 16))
        self.app_icon.addFile('share/flatcam_icon24.png', QtCore.QSize(24, 24))
        self.app_icon.addFile('share/flatcam_icon32.png', QtCore.QSize(32, 32))
        self.app_icon.addFile('share/flatcam_icon48.png', QtCore.QSize(48, 48))
        self.app_icon.addFile('share/flatcam_icon128.png',
                              QtCore.QSize(128, 128))
        self.app_icon.addFile('share/flatcam_icon256.png',
                              QtCore.QSize(256, 256))
        self.setWindowIcon(self.app_icon)

        self.setGeometry(100, 100, 1024, 650)
        title = 'FlatCAM {}'.format(version)
        if name is not None:
            title += ' - {}'.format(name)
        self.setWindowTitle(title)
        self.show()

    def closeEvent(self, event):
        grect = self.geometry()
        self.geom_update.emit(grect.x(), grect.y(), grect.width(),
                              grect.height())
        QtGui.qApp.quit()