diff --git a/core/io/database.py b/core/io/database.py index 5be11ac75..0fd17ed6e 100644 --- a/core/io/database.py +++ b/core/io/database.py @@ -50,8 +50,6 @@ from core.info import logger from .overview import OverviewDialog from .Ui_database import Ui_Form -nan = float('nan') - if TYPE_CHECKING: from core.widgets import MainWindowBase @@ -63,7 +61,7 @@ def _compress(obj: Any) -> bytes: def _decompress(obj: Union[bytes, BlobField]) -> Any: """Use to decode the Python script.""" - return eval(decompress(obj).decode()) + return eval(decompress(obj).decode(), {'nan': float('nan')}) """Create a empty Sqlite database object.""" @@ -447,8 +445,7 @@ def __add_commit(self, commit: CommitModel): button.loaded.connect(self.__load_commit_id) self.load_id.connect(button.set_loaded) self.CommitTable.setCellWidget(row, 0, button) - - self.CommitTable.setItem(row, 2, QTableWidgetItem(commit.description)) + self.CommitTable.setItem(row, 2, QTableWidgetItem(str(commit.description))) author_name = commit.author.name for row in range(self.AuthorList.count()): diff --git a/core/io/pyslvs_yaml.py b/core/io/pyslvs_yaml.py index 197d9b522..9e0c0e059 100644 --- a/core/io/pyslvs_yaml.py +++ b/core/io/pyslvs_yaml.py @@ -26,7 +26,6 @@ QCoreApplication, ) from .overview import OverviewDialog - if TYPE_CHECKING: from core.widgets import MainWindowBase diff --git a/core/io/script.py b/core/io/script.py index e13abb05c..c3146346f 100644 --- a/core/io/script.py +++ b/core/io/script.py @@ -36,7 +36,6 @@ QWheelEvent, ) from .Ui_script import Ui_Dialog - if TYPE_CHECKING: from core.widgets import MainWindowBase diff --git a/core/main_window/__init__.py b/core/main_window/__init__.py index af12be3eb..8ba1e1c8a 100644 --- a/core/main_window/__init__.py +++ b/core/main_window/__init__.py @@ -52,15 +52,14 @@ def __init__(self): super(MainWindow, self).__init__() self.restore_settings() - # Console widget. + # Console widget self.console_error_option.setChecked(ARGUMENTS.debug_mode) if not ARGUMENTS.debug_mode: self.__console_connect() - # Start first solve function calling. + # Start first solve function calling self.solve() - - # Load workbook from argument. + # Load workbook from argument self.load_from_args() def closeEvent(self, event: QCloseEvent): @@ -128,8 +127,7 @@ def merge_result(self, expr: str, path: Sequence[Sequence[Tuple[float, float]]]) """Merge result function of dimensional synthesis.""" if not self.ask_add_storage(expr): return - - # Add the path. + # Add the path i = 0 while f"Algorithm_{i}" in self.inputs_widget.path_data(): i += 1 diff --git a/core/main_window/solver.py b/core/main_window/solver.py index d3a4e197a..bd6b56ec4 100644 --- a/core/main_window/solver.py +++ b/core/main_window/solver.py @@ -81,15 +81,15 @@ def slvs_solve( x, y = vpoint.c[0] if vpoint.type in {VJoint.P, VJoint.RP}: sliders[i] = len(slider_bases) - # Base point (slot) is fixed. + # Base point (slot) is fixed point = sys.add_point_2d(x, y, wp) sys.dragged(point, wp) slider_bases.append(point) - # Slot point (slot) is movable. + # Slot point (slot) is movable x += cos(vpoint.angle) y += sin(vpoint.angle) slider_slots.append(sys.add_point_2d(x, y, wp)) - # Pin is movable. + # Pin is movable x, y = vpoint.c[1] if vpoint.has_offset() and vpoint.true_offset() <= 0.1: if vpoint.offset() > 0: @@ -109,20 +109,20 @@ def slvs_solve( point = sys.add_point_2d(x, y, wp) if vpoint.type in {VJoint.P, VJoint.RP}: sliders[i] = len(slider_bases) - # Base point (slot) is movable. + # Base point (slot) is movable slider_bases.append(point) - # Slot point (slot) is movable. + # Slot point (slot) is movable x += cos(vpoint.angle) y += sin(vpoint.angle) slider_slots.append(sys.add_point_2d(x, y, wp)) if vpoint.pin_grounded(): - # Pin is fixed. + # Pin is fixed x, y = vpoint.c[1] point = sys.add_point_2d(x, y, wp) sys.dragged(point, wp) points.append(point) else: - # Pin is movable. + # Pin is movable x, y = vpoint.c[1] if vpoint.has_offset() and vpoint.true_offset() <= 0.1: if vpoint.offset() > 0: @@ -133,8 +133,7 @@ def slvs_solve( y -= 0.1 points.append(sys.add_point_2d(x, y, wp)) continue - - # Point is movable. + # Point is movable points.append(point) for vlink in vlinks.values(): @@ -178,7 +177,7 @@ def slvs_solve( # Base slot slider_slot = sys.add_line_2d(slider_bases[b], slider_slots[b], wp) if vp1.grounded(): - # Slot is grounded. + # Slot is grounded sys.angle(hv, slider_slot, vp1.angle, wp) sys.coincident(p1, slider_slot, wp) if vp1.has_offset(): @@ -188,14 +187,14 @@ def slvs_solve( else: sys.coincident(p2, p1, wp) else: - # Slider between links. + # Slider between links for name in vp1.links[:1]: # type: str vlink = vlinks[name] - # A base link friend. + # A base link friend c = vlink.points[0] if c == a: if len(vlink.points) < 2: - # If no any friend. + # If no any friend continue c = vlink.points[1] @@ -226,11 +225,11 @@ def slvs_solve( for name in vp1.links[1:]: vlink = vlinks[name] - # A base link friend. + # A base link friend c = vlink.points[0] if c == a: if len(vlink.points) < 2: - # If no any friend. + # If no any friend continue c = vlink.points[1] @@ -249,9 +248,9 @@ def slvs_solve( ) for (b, d), angle in inputs.items(): - # The constraints of drive shaft. - # Simulate the input variables to the mechanism. - # The 'base points' are shaft center. + # The constraints of drive shaft + # Simulate the input variables to the mechanism + # The 'base points' are shaft center if b == d: continue @@ -439,14 +438,14 @@ def preview_path( else: raise ValueError("incorrect kernel") except ValueError: - # Update with error sign. + # Update with error sign for i in range(vpoint_count): auto_preview[i].append((nan, nan)) - # Back to last feasible solution. + # Back to last feasible solution angles[dp] -= interval dp += 1 else: - # Update with result. + # Update with result for i in range(vpoint_count): if vpoints[i].type == VJoint.R: auto_preview[i].append(result[i]) @@ -483,7 +482,7 @@ def get_graph(self) -> Tuple[ for b, d, _ in self.inputs_widget.input_pairs(): input_pair.update({b, d}) - # links name for RP joint. + # links name for RP joint k = len(self.vlink_list) graph = Graph([]) @@ -492,7 +491,7 @@ def get_graph(self) -> Tuple[ same = {} used_point = set() mapping = {} - # Link names will change to index number. + # Link names will change to index number for i, vlink in enumerate(self.vlink_list): for p in vlink.points: if p in used_point: diff --git a/core/synthesis/collections/__init__.py b/core/synthesis/collections/__init__.py index 69a114a62..921c77425 100644 --- a/core/synthesis/collections/__init__.py +++ b/core/synthesis/collections/__init__.py @@ -28,7 +28,6 @@ from .structure_widget import StructureWidget from .configure_widget import ConfigureWidget from .dialogs import CollectionsDialog - if TYPE_CHECKING: from core.widgets import MainWindowBase diff --git a/core/synthesis/collections/configure_widget.py b/core/synthesis/collections/configure_widget.py index 30789d28b..89056244e 100644 --- a/core/synthesis/collections/configure_widget.py +++ b/core/synthesis/collections/configure_widget.py @@ -46,7 +46,6 @@ list_texts, ) from .Ui_configure_widget import Ui_Form - if TYPE_CHECKING: from core.widgets.main_base import MainWindowBase @@ -228,7 +227,7 @@ def set_graph( for link in links: self.grounded_list.addItem("(" + ", ".join(link) + ")") - # Point name as (P1, P2, P3, ...). + # Point name is (P1, P2, P3, ...) for node in pos: self.joint_name.addItem(f'P{node}') @@ -434,7 +433,7 @@ def __set_parm_bind(self, _=None): for row, gs in enumerate(list_texts(self.grounded_list)): try: link_expr = [] - # Links from grounded list. + # Links from grounded list for name in gs.replace('(', '').replace(')', '').split(", "): num = int(name.replace('P', '')) if num in self.configure_canvas.same: @@ -443,7 +442,7 @@ def __set_parm_bind(self, _=None): except KeyError: continue else: - # Customize joints. + # Customize joints for joint, link in self.configure_canvas.cus.items(): if row == link: link_expr.append(f"P{joint}") diff --git a/core/synthesis/collections/dialogs/customs.py b/core/synthesis/collections/dialogs/customs.py index 76d4235fb..6df644e7b 100644 --- a/core/synthesis/collections/dialogs/customs.py +++ b/core/synthesis/collections/dialogs/customs.py @@ -12,7 +12,6 @@ from typing import TYPE_CHECKING from core.QtModules import Slot, Qt, QDialog from .Ui_customs import Ui_Dialog - if TYPE_CHECKING: from core.synthesis.collections import ConfigureWidget diff --git a/core/synthesis/collections/structure_widget.py b/core/synthesis/collections/structure_widget.py index e451abf59..575c7e1b3 100644 --- a/core/synthesis/collections/structure_widget.py +++ b/core/synthesis/collections/structure_widget.py @@ -50,7 +50,6 @@ ) from .dialogs.targets import TargetsDialog from .Ui_structure_widget import Ui_Form - if TYPE_CHECKING: from core.widgets import MainWindowBase @@ -355,7 +354,7 @@ def __set_selection(self, item: QListWidgetItem): )) self.selection_window.addItem(item_preview) - # Set attributes. + # Set attributes self.edges_text.setText(str(list(g.edges))) self.nl_label.setText(str(len(g.nodes))) self.nj_label.setText(str(len(g.edges))) diff --git a/core/synthesis/dimensional_synthesis/__init__.py b/core/synthesis/dimensional_synthesis/__init__.py index 278fb1b62..399647e9a 100644 --- a/core/synthesis/dimensional_synthesis/__init__.py +++ b/core/synthesis/dimensional_synthesis/__init__.py @@ -63,7 +63,6 @@ ChartDialog, ) from .Ui_dimension_widget import Ui_Form - if TYPE_CHECKING: from core.widgets import MainWindowBase @@ -264,7 +263,7 @@ def __import_xlsx(self): wb = load_workbook(file_name) ws = wb.get_sheet_by_name(wb.get_sheet_names()[0]) data = [] - # Keep finding until there is no value. + # Keep finding until there is no value i = 1 while True: x = ws.cell(row=i, column=1).value @@ -403,14 +402,14 @@ def __synthesis(self): "The length of target paths should be the same." ) return - # Get the algorithm type. + # Get the algorithm type if self.type0.isChecked(): type_num = AlgorithmType.RGA elif self.type1.isChecked(): type_num = AlgorithmType.Firefly else: type_num = AlgorithmType.DE - # Deep copy it so the pointer will not the same. + # Deep copy it so the pointer will not the same mech_params = deepcopy(self.mech_params) mech_params['Expression'] = parse_vpoints(mech_params.pop('Expression', [])) mech_params['Target'] = deepcopy(self.path) @@ -431,7 +430,7 @@ def name_in_table(target_name: str) -> int: self.parameter_list.cellWidget(row, 4).value(), ) - # Start progress dialog. + # Start progress dialog dlg = ProgressDialog(type_num, mech_params, self.alg_options, self) dlg.show() if not dlg.exec(): diff --git a/core/synthesis/dimensional_synthesis/dialogs/chart.py b/core/synthesis/dimensional_synthesis/dialogs/chart.py index 7db1b7c28..f33caa054 100644 --- a/core/synthesis/dimensional_synthesis/dialogs/chart.py +++ b/core/synthesis/dimensional_synthesis/dialogs/chart.py @@ -70,10 +70,10 @@ def __set_chart(self, tab_name: str, pos_x: int, pos_y: int): axis_y.setTickCount(11) if self.__algorithm_data: - # Just copy references from algorithm data. + # Just copy references from algorithm data plot = [data['time_fitness'] for data in self.__algorithm_data] - # X max. + # X max max_x = int(max([max([tnf[pos_x] for tnf in data]) for data in plot]) * 100) axis_x.setMax(max_x) i10 = int(max_x / 10) @@ -84,11 +84,11 @@ def __set_chart(self, tab_name: str, pos_x: int, pos_y: int): for i in range(0, 1000, 100): axis_x.append(str(i / 100), i) - # Y max. + # Y max max_y = max(max([tnf[pos_y] for tnf in data]) for data in plot) + 10 else: plot = None - # Y max. + # Y max max_y = 100 max_y -= max_y % 10 diff --git a/core/synthesis/dimensional_synthesis/dialogs/options.py b/core/synthesis/dimensional_synthesis/dialogs/options.py index a796f0d7d..d204d269c 100644 --- a/core/synthesis/dimensional_synthesis/dialogs/options.py +++ b/core/synthesis/dimensional_synthesis/dialogs/options.py @@ -171,7 +171,7 @@ def __set_args(self, settings: Dict[str, Any]): self.min_fit.setValue(settings['min_fit']) elif 'max_time' in settings: self.max_time_option.setChecked(True) - # In second (int). + # In second (int) max_time = settings['max_time'] self.max_time_h.setValue(max_time // 3600) self.max_time_m.setValue((max_time % 3600) // 60) diff --git a/core/synthesis/dimensional_synthesis/dialogs/path_adjust.py b/core/synthesis/dimensional_synthesis/dialogs/path_adjust.py index ce2edb41f..0cf0c8ff9 100644 --- a/core/synthesis/dimensional_synthesis/dialogs/path_adjust.py +++ b/core/synthesis/dimensional_synthesis/dialogs/path_adjust.py @@ -18,7 +18,6 @@ QMessageBox, ) from .Ui_path_adjust import Ui_Dialog - if TYPE_CHECKING: from core.synthesis import DimensionalSynthesis diff --git a/core/synthesis/dimensional_synthesis/dialogs/progress.py b/core/synthesis/dimensional_synthesis/dialogs/progress.py index a1682fa27..96c19ac8f 100644 --- a/core/synthesis/dimensional_synthesis/dialogs/progress.py +++ b/core/synthesis/dimensional_synthesis/dialogs/progress.py @@ -45,7 +45,7 @@ def __init__( self.mechanisms: List[Dict[str, Any]] = [] - # Batch label. + # Batch label if 'max_gen' in setting: self.limit = setting['max_gen'] if self.limit > 0: @@ -71,14 +71,14 @@ def __init__( self.limit_mode = 'max_gen' self.loopTime.setEnabled(self.limit > 0) - # Timer. + # Timer self.time = 0 self.timer = QTimer() self.timer.setInterval(1000) self.timer.timeout.connect(self.__set_time) self.time_spend = 0. - # Worker thread. + # Worker thread self.work = WorkerThread(type_num, mech_params, setting, self) self.stop_signal.connect(self.work.stop) if self.work.is_two_kernel(): diff --git a/core/synthesis/dimensional_synthesis/dialogs/thread.py b/core/synthesis/dimensional_synthesis/dialogs/thread.py index 60c116c2e..8ca1d4a1f 100644 --- a/core/synthesis/dimensional_synthesis/dialogs/thread.py +++ b/core/synthesis/dimensional_synthesis/dialogs/thread.py @@ -72,7 +72,7 @@ def run(self): for self.current_loop in range(self.loop): logger.info(f"Algorithm [{self.current_loop + 1}]: {self.type_num}") if self.is_stop: - # Cancel the remaining tasks. + # Cancel the remaining tasks logger.info("Canceled.") continue self.result.emit(self.__algorithm()) diff --git a/core/synthesis/structure_synthesis/__init__.py b/core/synthesis/structure_synthesis/__init__.py index d9674bc88..d8be8a801 100644 --- a/core/synthesis/structure_synthesis/__init__.py +++ b/core/synthesis/structure_synthesis/__init__.py @@ -55,7 +55,6 @@ GraphEnumerateThread, ) from .Ui_structure_widget import Ui_Form - if TYPE_CHECKING: from core.widgets import MainWindowBase diff --git a/core/widgets/inputs.py b/core/widgets/inputs.py index 8afe09fce..2ed776edf 100644 --- a/core/widgets/inputs.py +++ b/core/widgets/inputs.py @@ -43,7 +43,6 @@ AddPath, DeletePath, ) - if TYPE_CHECKING: from core.widgets import MainWindowBase @@ -69,7 +68,7 @@ def __init__(self, parent: MainWindowBase): super(InputsWidget, self).__init__(parent) self.setupUi(self) - # parent's function pointer. + # parent's function pointer self.free_move_button = parent.free_move_button self.EntitiesPoint = parent.entities_point self.EntitiesLink = parent.entities_link @@ -93,17 +92,17 @@ def __init__(self, parent: MainWindowBase): self.dial_spinbox.valueChanged.connect(self.__set_var) self.inputs_dial_layout.addWidget(RotatableView(self.dial)) - # Play button. + # Play button action = QShortcut(QKeySequence("F5"), self) action.activated.connect(self.variable_play.click) self.variable_stop.clicked.connect(self.variable_value_reset) - # Timer for play button. + # Timer for play button self.inputs_play_shaft = QTimer() self.inputs_play_shaft.setInterval(10) self.inputs_play_shaft.timeout.connect(self.__change_index) - # Change the point coordinates with current position. + # Change the point coordinates with current position self.update_pos.clicked.connect(self.set_coords_as_current) # Inputs record context menu @@ -222,10 +221,10 @@ def __add_inputs_variable(self, p0: Optional[int] = None, p1: Optional[int] = No name = f'Point{p0}' self.CommandStack.beginMacro(f"Add variable of {name}") if p0 == p1: - # One joint by offset. + # One joint by offset value = self.vpoints[p0].true_offset() else: - # Two joints by angle. + # Two joints by angle value = self.vpoints[p0].slope_angle(self.vpoints[p1]) self.CommandStack.push(AddInput('->'.join(( name, @@ -273,8 +272,8 @@ def variable_excluding(self, row: Optional[int] = None): """Remove variable if the point was been deleted. Default: all.""" one_row: bool = row is not None for i, (b, d, a) in enumerate(self.input_pairs()): - # If this is not origin point any more. - if one_row and (row != b): + # If this is not origin point any more + if one_row and row != b: continue self.CommandStack.beginMacro(f"Remove variable of {{Point{row}}}") self.CommandStack.push(DeleteInput(i, self.variable_list)) @@ -497,7 +496,7 @@ def __record_list_context_menu(self, point): try: data = self.__path_data[name] except KeyError: - # Auto preview path. + # Auto preview path data = self.MainCanvas.Path.path showall_action.setEnabled(False) else: @@ -514,7 +513,7 @@ def __record_list_context_menu(self, point): ) if action_exec: if action_exec == copy_action: - # Copy path data. + # Copy path data num = 0 name_copy = f"{name}_{num}" while name_copy in self.__path_data: @@ -522,12 +521,12 @@ def __record_list_context_menu(self, point): num += 1 self.add_path(name_copy, data) elif "Copy data from" in action_exec.text(): - # Copy data to clipboard. + # 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. + # Switch points enabled status if action_exec.index == -1: self.record_show.setChecked(True) self.MainCanvas.set_path_show(action_exec.index) diff --git a/core/widgets/main_canvas.py b/core/widgets/main_canvas.py index 6612dff73..4e7cadda3 100644 --- a/core/widgets/main_canvas.py +++ b/core/widgets/main_canvas.py @@ -35,7 +35,6 @@ FreeMode, SelectMode, ) - if TYPE_CHECKING: from core.widgets import MainWindowBase diff --git a/core/widgets/main_canvas_method.py b/core/widgets/main_canvas_method.py index de1e2f2a6..97a51fb55 100644 --- a/core/widgets/main_canvas_method.py +++ b/core/widgets/main_canvas_method.py @@ -44,7 +44,6 @@ QMouseEvent, ) from core.graphics import convex_hull, BaseCanvas, color_qt - if TYPE_CHECKING: from core.widgets import MainWindowBase diff --git a/core/widgets/tables.py b/core/widgets/tables.py index a20bcdff6..f6213ceed 100644 --- a/core/widgets/tables.py +++ b/core/widgets/tables.py @@ -49,7 +49,6 @@ QKeyEvent, ) from core.graphics import color_icon - if TYPE_CHECKING: from core.widgets import MainWindowBase diff --git a/depend/pyslvs b/depend/pyslvs index 2e2873ca0..1883a6e21 160000 --- a/depend/pyslvs +++ b/depend/pyslvs @@ -1 +1 @@ -Subproject commit 2e2873ca0cc8fa916dc391978390d0ebc3afe0ef +Subproject commit 1883a6e21986b9f0df4d11519caa55611c413fb2 diff --git a/docs/changelog.md b/docs/changelog.md index 4a3075911..1eb5090a6 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -33,6 +33,7 @@ + Reformat the actions for all of context menus. + Use pyenv instead of MacPorts in Travis CI. + Remove USER_MODE option in the Makefile. ++ Remove the period after the comment if not too long. ## Version 19.07 diff --git a/launch_pyslvs.py b/launch_pyslvs.py index 0df9a65b8..fe8b9231a 100755 --- a/launch_pyslvs.py +++ b/launch_pyslvs.py @@ -9,6 +9,5 @@ from core import main - if __name__ == '__main__': main()