Exemplo n.º 1
0
 def on_record_list_context_menu(self, point):
     """Show the context menu.
     
     Show path [0], [1], ...
     Or copy path coordinates.
     """
     row = self.record_list.currentRow()
     if row > -1:
         action = self.popMenu_record_list.addAction("Show all")
         action.index = -1
         name = self.record_list.item(row).text().split(":")[0]
         try:
             data = self.pathData[name]
         except KeyError:
             return
         for action_text in ("Show", "Copy data from"):
             self.popMenu_record_list.addSeparator()
             for i in range(len(data)):
                 if data[i]:
                     action = self.popMenu_record_list.addAction(
                         "{} Point{}".format(action_text, i))
                     action.index = i
     action = self.popMenu_record_list.exec_(
         self.record_list.mapToGlobal(point))
     if action:
         if "Copy data from" in action.text():
             QApplication.clipboard().setText('\n'.join(
                 "{},{}".format(x, y) for x, y in data[action.index]))
         elif "Show" in action.text():
             if action.index == -1:
                 self.record_show.setChecked(True)
             self.MainCanvas.setPathShow(action.index)
     self.popMenu_record_list.clear()
Exemplo n.º 2
0
 def savePMKS(self):
     """Output to PMKS as URL."""
     url = "http://designengrlab.github.io/PMKS/pmks.html?mech="
     url_table = []
     for row in range(self.EntitiesPoint.rowCount()):
         type_and_angle = self.EntitiesPoint.item(row, 2).text().split(':')
         point_data = [
             self.EntitiesPoint.item(row, 1).text(),
             type_and_angle[0],
             self.EntitiesPoint.item(row, 4).text(),
             self.EntitiesPoint.item(row, 5).text(),
         ]
         if len(type_and_angle) == 2:
             point_data.append(type_and_angle[1])
         point_data.append('tfff')
         url_table.append(','.join(point_data))
     url += '|'.join(url_table) + '|'
     text = '\n'.join(
         ("Copy and past this link to web browser:\n", url + '\n',
          "If you have installed Microsoft Silverlight in "
          "Internet Explorer as default browser, "
          "just click \"Open\" button to open it in PMKS website."))
     reply = QMessageBox.information(
         self, "PMKS web server", text,
         (QMessageBox.Save | QMessageBox.Open | QMessageBox.Close),
         QMessageBox.Save)
     if reply == QMessageBox.Open:
         _open_url(url)
     elif reply == QMessageBox.Save:
         QApplication.clipboard().setText(url)
Exemplo n.º 3
0
 def on_actionSave_Image_triggered(self):
     """
     Save Image to cilck board
     """
     # TODO: add save image files not on clickboard
     if self.tabWidget.currentWidget():
         QApplication.clipboard().setPixmap(
             self.tabWidget.currentWidget().grab())
Exemplo n.º 4
0
 def __save_picture_clipboard(self):
     """Capture the canvas image to clipboard."""
     QApplication.clipboard().setPixmap(self.main_canvas.grab())
     QMessageBox.information(
         self,
         "Captured!",
         "Canvas widget picture is copy to clipboard."
     )
Exemplo n.º 5
0
def on_action_Output_to_Expression_triggered(self):
    """Output as expression."""
    expr = "M[{}]".format(", ".join(vpoint.expr
                                    for vpoint in self.EntitiesPoint.data()))
    text = ("You can copy the expression and import to another workbook:" +
            "\n\n{}\n\nClick the save button to copy it.".format(expr))
    reply = QMessageBox.question(self, "Pyslvs Expression", text,
                                 (QMessageBox.Save | QMessageBox.Close),
                                 QMessageBox.Save)
    if reply == QMessageBox.Save:
        QApplication.clipboard().setText(expr)
Exemplo n.º 6
0
    def __record_list_context_menu(self, point):
        """Show the context menu.

        Show path [0], [1], ...
        Or copy path coordinates.
        """
        row = self.record_list.currentRow()
        if not row > -1:
            return
        showall_action = self.pop_menu_record_list.addAction("Show all")
        showall_action.index = -1
        copy_action = self.pop_menu_record_list.addAction("Copy as new")
        name = self.record_list.item(row).text().split(':')[0]
        try:
            data = self.__path_data[name]
        except KeyError:
            # Auto preview path.
            data = self.MainCanvas.Path.path
            showall_action.setEnabled(False)
        else:
            for action_text in ("Show", "Copy data from"):
                self.pop_menu_record_list.addSeparator()
                for i in range(len(data)):
                    if data[i]:
                        action = self.pop_menu_record_list.addAction(
                            f"{action_text} Point{i}"
                        )
                        action.index = i
        action_exec = self.pop_menu_record_list.exec(
            self.record_list.mapToGlobal(point)
        )
        if action_exec:
            if action_exec == copy_action:
                # Copy path data.
                num = 0
                name_copy = f"{name}_{num}"
                while name_copy in self.__path_data:
                    name_copy = f"{name}_{num}"
                    num += 1
                self.add_path(name_copy, data)
            elif "Copy data from" in action_exec.text():
                # Copy data to clipboard.
                QApplication.clipboard().setText('\n'.join(
                    f"{x},{y}" for x, y in data[action_exec.index]
                ))
            elif "Show" in action_exec.text():
                # Switch points enabled status.
                if action_exec.index == -1:
                    self.record_show.setChecked(True)
                self.MainCanvas.set_path_show(action_exec.index)
        self.pop_menu_record_list.clear()
Exemplo n.º 7
0
 def Topologic_result_context_menu(self, point):
     """Context menu for the type synthesis results."""
     index = self.Topologic_result.currentIndex().row()
     self.add_collection.setEnabled(index>-1)
     self.copy_edges.setEnabled(index>-1)
     self.copy_image.setEnabled(index>-1)
     action = self.popMenu_topo.exec_(self.Topologic_result.mapToGlobal(point))
     if not action:
         return
     clipboard = QApplication.clipboard()
     if action==self.add_collection:
         self.addCollection(self.answer[index].edges)
     elif action==self.copy_edges:
         clipboard.setText(str(self.answer[index].edges))
     elif action==self.copy_image:
         #Turn the transparent background to white.
         image1 = self.atlas_image()
         image2 = QImage(image1.size(), image1.format())
         image2.fill(QColor(Qt.white).rgb())
         painter = QPainter(image2)
         painter.drawImage(QPointF(0, 0), image1)
         painter.end()
         pixmap = QPixmap()
         pixmap.convertFromImage(image2)
         clipboard.setPixmap(pixmap)
Exemplo n.º 8
0
 def current_selection(self) -> Tuple[int, ...]:
     if QApplication.keyboardModifiers() in {
             Qt.ControlModifier, Qt.ShiftModifier
     }:
         return tuple(set(self.selection_old + self.selection_rect))
     else:
         return tuple(self.selection_rect)
Exemplo n.º 9
0
    def mouseReleaseEvent(self, event):
        """Release mouse button.

        + Alt & Left button: Add a point.
        + Left button: Select a point.
        + Free move mode: Edit the point(s) coordinate.
        """
        if self.selector.left_dragged:
            km = QApplication.keyboardModifiers()
            self.selector.selection_old = list(self.selections)
            if (self.select_mode == SelectMode.Joint
                    and self.free_move != FreeMode.NoFreeMove):
                x, y = self.__mouse_pos(event)
                if self.selector.x != x and self.selector.y != y:
                    # Edit point coordinates.
                    self.__emit_free_move(self.selections)
                elif ((not self.selector.selection_rect)
                      and km != Qt.ControlModifier and km != Qt.ShiftModifier):
                    self.noselected.emit()
            else:
                if km == Qt.AltModifier:
                    # Add Point
                    self.alt_add.emit(
                        self.__snap(self.selector.x, is_zoom=False),
                        self.__snap(self.selector.y, is_zoom=False))
                elif ((not self.selector.selection_rect)
                      and km != Qt.ControlModifier and km != Qt.ShiftModifier):
                    self.noselected.emit()
        self.selected_tips_hide.emit()
        self.selector.release()
        self.update()
Exemplo n.º 10
0
 def mouseReleaseEvent(self, event):
     """Release mouse button.
     
     + Alt & Left button: Add a point.
     + Left button: Select a point.
     + Free move mode: Edit the point(s) coordinate.
     """
     if self.Selector.LeftButtonDrag:
         self.Selector.selection_old = list(self.pointsSelection)
         km = QApplication.keyboardModifiers()
         #Add Point
         if km == Qt.AltModifier:
             self.mouse_getAltAdd.emit()
         #Only one clicked.
         elif ((abs(event.x() - self.ox - self.Selector.x) <
                self.selectionRadius / 2)
               and (abs(event.y() - self.oy - self.Selector.y) <
                    self.selectionRadius / 2)):
             if ((not self.Selector.selection) and km != Qt.ControlModifier
                     and km != Qt.ShiftModifier):
                 self.mouse_noSelection.emit()
         #Edit point coordinates.
         elif (self.freemove != FreeMode.NoFreeMove):
             self.mouse_freemoveSelection.emit(
                 tuple((row, (self.Points[row].cx, self.Points[row].cy))
                       for row in self.pointsSelection))
     self.Selector.selection_rect.clear()
     self.Selector.MiddleButtonDrag = False
     self.Selector.LeftButtonDrag = False
     self.Selector.RectangularSelection = False
     self.update()
Exemplo n.º 11
0
 def setSelections(self, selections: Tuple[int], keyDetect: bool):
     """Auto select function, get the signal from canvas."""
     self.setFocus()
     keyboardModifiers = QApplication.keyboardModifiers()
     if keyDetect:
         if keyboardModifiers == Qt.ShiftModifier:
             self.__setSelectedRanges(selections,
                                      continueSelect=True,
                                      UnSelect=False)
         elif keyboardModifiers == Qt.ControlModifier:
             self.__setSelectedRanges(selections,
                                      continueSelect=True,
                                      UnSelect=True)
         else:
             self.__setSelectedRanges(selections,
                                      continueSelect=False,
                                      UnSelect=False)
     else:
         continueSelect = (keyboardModifiers == Qt.ShiftModifier)
         self.__setSelectedRanges(selections,
                                  continueSelect=continueSelect,
                                  UnSelect=False)
     distance = []
     selectedRows = self.selectedRows()
     if len(selectedRows) > 1:
         data = self.dataTuple()
         for i, row in enumerate(selectedRows):
             if i == len(selectedRows) - 1:
                 break
             distance.append(
                 round(data[row].distance(data[selectedRows[i + 1]]), 4))
     self.selectionLabelUpdate.emit(selectedRows, distance)
Exemplo n.º 12
0
 def wheelEvent(self, event):
     super(_ScriptBrowser, self).wheelEvent(event)
     if QApplication.keyboardModifiers() == Qt.ControlModifier:
         if event.angleDelta().y() > 0:
             self.zoomIn(1)
         else:
             self.zoomOut(1)
Exemplo n.º 13
0
        def save_chart(pos: QPoint):
            self.chart_menu.popup(chart.mapToGlobal(pos))
            action = self.chart_menu.exec()
            if action not in {self.save_chart_action, self.copy_chart_action}:
                return

            pixmap: QPixmap = chart.grab()
            if action == self.copy_chart_action:
                QApplication.clipboard().setPixmap(pixmap)
                return

            file_name = self.output_to("Image", qt_image_format)
            if not file_name:
                return

            pixmap.save(file_name)
Exemplo n.º 14
0
 def wheelEvent(self, event):
     """Mouse wheel event."""
     if QApplication.keyboardModifiers() != Qt.ControlModifier:
         super(TextEditor, self).wheelEvent(event)
         return
     if event.angleDelta().y() >= 0:
         self.zoomIn()
     else:
         self.zoomOut()
Exemplo n.º 15
0
    def wheelEvent(self, event):
        """Switch function by mouse wheel.

        + Set zoom bar value.
        + Set select mode.
        """
        value = event.angleDelta().y()
        if QApplication.keyboardModifiers() == Qt.ControlModifier:
            self.__set_selection_mode(self.__selection_mode() + (-1 if value > 0 else 1))
            i = self.__selection_mode()
            icons = ''.join(
                f"<img width=\"{70 if i == j else 40}\" src=\":icons/{icon}.png\"/>"
                for j, icon in enumerate(('bearing', 'link', 'triangular-iteration'))
            )
            QToolTip.showText(event.globalPos(), f"<p style=\"background-color: # 77abff\">{icons}</p>", self)
        else:
            self.__set_zoom(self.__zoom() + self.__zoom_factor() * (1 if value > 0 else -1))
        event.accept()
Exemplo n.º 16
0
 def setSelections(self,
                   selections: Sequence[int],
                   key_detect: bool = False):
     """Auto select function, get the signal from canvas."""
     self.setFocus()
     keyboard_modifiers = QApplication.keyboardModifiers()
     if key_detect:
         continue_select, not_select = {
             Qt.ShiftModifier: (True, False),
             Qt.ControlModifier: (True, True),
         }.get(keyboard_modifiers, (False, False))
         self.__setSelectedRanges(selections,
                                  continue_select=continue_select,
                                  un_select=not_select)
     else:
         self.__setSelectedRanges(
             selections,
             continue_select=(keyboard_modifiers == Qt.ShiftModifier),
             un_select=False)
Exemplo n.º 17
0
 def on_path_paste_clicked(self):
     """Paste path data from clipboard."""
     self.readPathFromCSV(charSplit(";|,|\n", QApplication.clipboard().text()))
Exemplo n.º 18
0
 def on_path_copy_clicked(self):
     """Copy the current path coordinates to clipboard."""
     QApplication.clipboard().setText('\n'.join(
         "{},{}".format(x, y)
         for x, y in self.currentPath()
     ))
Exemplo n.º 19
0
def _copy_table_data(table):
    """Copy item text to clipboard."""
    text = table.currentItem().text()
    if text:
        QApplication.clipboard().setText(text)
Exemplo n.º 20
0
 def copyCoord(self):
     """Copy the current coordinate of the point."""
     pos = self.EntitiesPoint.currentPosition(
         self.EntitiesPoint.currentRow())
     text = str(pos[0] if (len(pos) == 1) else pos)
     QApplication.clipboard().setText(text)
Exemplo n.º 21
0
def on_action_Output_to_Picture_clipboard_triggered(self):
    """Capture the canvas image to clipboard."""
    QApplication.clipboard().setPixmap(self.MainCanvas.grab())
    QMessageBox.information(self, "Captured!",
                            "Canvas widget picture is copy to clipboard.")
Exemplo n.º 22
0
 def __copy(self):
     """Copy to clipboard."""
     QApplication.clipboard().setText(self.script_view.toPlainText())
Exemplo n.º 23
0
 def __copy(self):
     """Copy the mechanism params."""
     QApplication.clipboard().setText(
         pprint.pformat(self.__get_current_mechanism_params()))
Exemplo n.º 24
0
 def on_Result_clipboard_clicked(self):
     """Copy pretty print result as text."""
     QApplication.clipboard().setText(
         pprint.pformat(self.mechanism_data[self.Result_list.currentRow()])
     )
Exemplo n.º 25
0
def on_mechanism_storage_copy_clicked(self):
    """Copy the expression from a storage data."""
    item = self.mechanism_storage.currentItem()
    if item:
        QApplication.clipboard().setText(item.expr)
Exemplo n.º 26
0
 def mouseMoveEvent(self, event):
     """Move mouse.
     
     + Middle button: Translate canvas view.
     + Left button: Free move mode / Rectangular selection.
     """
     x = (event.x() - self.ox) / self.zoom
     y = (event.y() - self.oy) / -self.zoom
     if self.Selector.MiddleButtonDrag:
         self.ox = event.x() - self.Selector.x
         self.oy = event.y() - self.Selector.y
         self.update()
     elif self.Selector.LeftButtonDrag:
         if self.freemove != FreeMode.NoFreeMove:
             if self.pointsSelection:
                 if self.freemove == FreeMode.Translate:
                     #Free move translate function.
                     mouse_x = x - self.Selector.x / self.zoom
                     mouse_y = y - self.Selector.y / -self.zoom
                     for row in self.pointsSelection:
                         vpoint = self.Points[row]
                         vpoint.move(
                             (mouse_x + vpoint.x, mouse_y + vpoint.y))
                 elif self.freemove == FreeMode.Rotate:
                     #Free move rotate function.
                     alpha = atan2(y, x) - atan2(
                         self.Selector.y / -self.zoom,
                         self.Selector.x / self.zoom)
                     for row in self.pointsSelection:
                         vpoint = self.Points[row]
                         r = hypot(vpoint.x, vpoint.y)
                         beta = atan2(vpoint.y, vpoint.x)
                         vpoint.move(
                             (r * cos(alpha + beta), r * sin(alpha + beta)))
                 elif self.freemove == FreeMode.Reflect:
                     #Free move reflect function.
                     fx = 1 if (x > 0) else -1
                     fy = 1 if (y > 0) else -1
                     for row in self.pointsSelection:
                         vpoint = self.Points[row]
                         if vpoint.type == 0:
                             vpoint.move((vpoint.x * fx, vpoint.y * fy))
                         else:
                             vpoint.move((vpoint.x * fx, vpoint.y * fy),
                                         (vpoint.x * fx, vpoint.y * fy))
         else:
             #Rectangular selection
             self.Selector.RectangularSelection = True
             self.Selector.sx = event.x() - self.ox
             self.Selector.sy = event.y() - self.oy
             self.__rectangularSelectedPoint()
             km = QApplication.keyboardModifiers()
             if self.Selector.selection_rect:
                 if km == Qt.ControlModifier or km == Qt.ShiftModifier:
                     self.mouse_getSelection.emit(
                         tuple(
                             set(self.Selector.selection_old +
                                 self.Selector.selection_rect)), False)
                 else:
                     self.mouse_getSelection.emit(
                         tuple(self.Selector.selection_rect), False)
             else:
                 self.mouse_noSelection.emit()
         self.update()
     self.mouse_track.emit(x, y)
Exemplo n.º 27
0
 def on_Link_Expression_copy_clicked(self):
     """Copy profile linkage expression."""
     text = self.Link_Expression.text()
     if text:
         QApplication.clipboard().setText(text)
Exemplo n.º 28
0
 def on_clipboard_button_clicked(self):
     """Copy the mechanism params."""
     QApplication.clipboard().setText(
         pprint.pformat(self.get_currentMechanismParams()))
Exemplo n.º 29
0
 def on_copy_clicked(self):
     """Copy to clipboard."""
     QApplication.clipboard().setText(self.script.toPlainText())
Exemplo n.º 30
0
 def on_Expression_copy_clicked(self):
     """Copy expression button."""
     string = self.Expression_edges.text()
     if string:
         QApplication.clipboard().setText(string)
         self.Expression_edges.selectAll()