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)
class FlatCAMActivityView(QWidget): def __init__(self, parent=None): super(FlatCAMActivityView, self).__init__(parent=parent) self.setMinimumWidth(200) self.icon = QLabel(self) self.icon.setGeometry(0, 0, 12, 12) self.movie = QtGui.QMovie("share/active.gif") self.icon.setMovie(self.movie) #self.movie.start() layout = QHBoxLayout() layout.setContentsMargins(5, 0, 5, 0) layout.setAlignment(QtCore.Qt.AlignLeft) self.setLayout(layout) layout.addWidget(self.icon) self.text = QLabel(self) self.text.setText("Idle.") layout.addWidget(self.text) def set_idle(self): self.movie.stop() self.text.setText("Idle.") def set_busy(self, msg): self.movie.start() self.text.setText(msg)
class Measurement(FlatCAMTool): toolName = "Measurement Tool" def __init__(self, app): FlatCAMTool.__init__(self, app) self.setContentsMargins(0, 0, 0, 0) #self.layout.setMargin(0) self.layout.setContentsMargins(0, 0, 3, 0) self.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Maximum) self.point1 = None self.point2 = None self.label = QLabel("Click on a reference point ...") self.label.setFrameStyle(QFrame.StyledPanel | QFrame.Plain) self.label.setMargin(3) self.layout.addWidget(self.label) # self.layout.setMargin(0) self.setVisible(False) self.click_subscription = None self.move_subscription = None def install(self, icon=None, separator=None, **kwargs): FlatCAMTool.install(self, icon, separator, **kwargs) self.app.ui.right_layout.addWidget(self) self.app.plotcanvas.mpl_connect('key_press_event', self.on_key_press) def run(self): self.toggle() def on_click(self, event): if self.point1 is None: self.point1 = (event.xdata, event.ydata) else: self.point2 = copy(self.point1) self.point1 = (event.xdata, event.ydata) self.on_move(event) def on_key_press(self, event): if event.key == 'r': self.toggle() def toggle(self): if self.isVisible(): self.setVisible(False) self.app.plotcanvas.mpl_disconnect(self.move_subscription) self.app.plotcanvas.mpl_disconnect(self.click_subscription) else: self.setVisible(True) self.move_subscription = self.app.plotcanvas.mpl_connect( 'motion_notify_event', self.on_move) self.click_subscription = self.app.plotcanvas.mpl_connect( 'button_press_event', self.on_click) def on_move(self, event): if self.point1 is None: self.label.setText("Click on a reference point...") else: try: dx = event.xdata - self.point1[0] dy = event.ydata - self.point1[1] d = sqrt(dx**2 + dy**2) self.label.setText("D = %.4f D(x) = %.4f D(y) = %.4f" % (d, dx, dy)) except TypeError: pass if self.update is not None: self.update()