molde 0.1.1__py3-none-any.whl → 0.1.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,13 @@
1
1
  from .lines_data import LinesData
2
2
  from .vertices_data import VerticesData
3
+ from .arrows import (
4
+ create_arrow_source,
5
+ create_long_arrow_source,
6
+ create_double_arrow_source,
7
+ create_outwards_arrow_source,
8
+ )
9
+
10
+ from .simple_shapes import (
11
+ create_cone_source,
12
+ create_cube_source,
13
+ )
@@ -0,0 +1,54 @@
1
+ from vtkmodules.vtkFiltersSources import vtkArrowSource
2
+ from vtkmodules.vtkFiltersCore import vtkAppendPolyData
3
+ from molde.utils.poly_data_utils import transform_polydata
4
+
5
+
6
+ def create_arrow_source():
7
+ source = vtkArrowSource()
8
+ source.SetTipLength(0.25)
9
+ source.Update()
10
+
11
+ return transform_polydata(
12
+ source.GetOutput(),
13
+ position=(-1, 0, 0),
14
+ )
15
+
16
+
17
+ def create_long_arrow_source():
18
+ source = vtkArrowSource()
19
+ source.SetTipResolution(4)
20
+ source.SetShaftResolution(4)
21
+ source.SetTipLength(0.85)
22
+ source.Update()
23
+
24
+ return transform_polydata(
25
+ source.GetOutput(),
26
+ position=(-1, 0, 0),
27
+ )
28
+
29
+
30
+ def create_double_arrow_source():
31
+ arrow1 = vtkArrowSource()
32
+ arrow1.SetTipLength(0.45)
33
+ arrow1.Update()
34
+
35
+ arrow2 = vtkArrowSource()
36
+ arrow2.SetTipLength(0.3)
37
+ arrow2.Update()
38
+
39
+ source = vtkAppendPolyData()
40
+ source.AddInputData(arrow1.GetOutput())
41
+ source.AddInputData(arrow2.GetOutput())
42
+ source.Update()
43
+
44
+ return transform_polydata(
45
+ source.GetOutput(),
46
+ position=(-1, 0, 0),
47
+ )
48
+
49
+
50
+ def create_outwards_arrow_source():
51
+ source = vtkArrowSource()
52
+ source.SetTipLength(0.25)
53
+ source.Update()
54
+ return source.GetOutput()
@@ -0,0 +1,22 @@
1
+ from molde.utils.poly_data_utils import transform_polydata
2
+ from vtkmodules.vtkFiltersSources import (
3
+ vtkConeSource,
4
+ vtkCubeSource,
5
+ )
6
+
7
+ def create_cone_source():
8
+ source = vtkConeSource()
9
+ source.SetHeight(1)
10
+ source.SetRadius(0.5)
11
+ source.SetResolution(12)
12
+ source.Update()
13
+ return transform_polydata(
14
+ source.GetOutput(),
15
+ position=(-0.5, 0, 0),
16
+ )
17
+
18
+ def create_cube_source():
19
+ source = vtkCubeSource()
20
+ source.SetBounds(0, 1, 0, 1, 0, 1)
21
+ source.Update()
22
+ return source.GetOutput()
@@ -0,0 +1,73 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <ui version="4.0">
3
+ <class>loading_window</class>
4
+ <widget class="QWidget" name="loading_window">
5
+ <property name="windowModality">
6
+ <enum>Qt::ApplicationModal</enum>
7
+ </property>
8
+ <property name="geometry">
9
+ <rect>
10
+ <x>0</x>
11
+ <y>0</y>
12
+ <width>377</width>
13
+ <height>145</height>
14
+ </rect>
15
+ </property>
16
+ <property name="windowTitle">
17
+ <string>Loading Window</string>
18
+ </property>
19
+ <layout class="QVBoxLayout" name="verticalLayout">
20
+ <item>
21
+ <spacer name="verticalSpacer_2">
22
+ <property name="orientation">
23
+ <enum>Qt::Vertical</enum>
24
+ </property>
25
+ <property name="sizeHint" stdset="0">
26
+ <size>
27
+ <width>20</width>
28
+ <height>40</height>
29
+ </size>
30
+ </property>
31
+ </spacer>
32
+ </item>
33
+ <item>
34
+ <widget class="QLabel" name="progress_label">
35
+ <property name="text">
36
+ <string>Loading ...</string>
37
+ </property>
38
+ <property name="alignment">
39
+ <set>Qt::AlignCenter</set>
40
+ </property>
41
+ </widget>
42
+ </item>
43
+ <item>
44
+ <widget class="QProgressBar" name="progress_bar">
45
+ <property name="value">
46
+ <number>10</number>
47
+ </property>
48
+ <property name="textVisible">
49
+ <bool>true</bool>
50
+ </property>
51
+ <property name="textDirection">
52
+ <enum>QProgressBar::TopToBottom</enum>
53
+ </property>
54
+ </widget>
55
+ </item>
56
+ <item>
57
+ <spacer name="verticalSpacer">
58
+ <property name="orientation">
59
+ <enum>Qt::Vertical</enum>
60
+ </property>
61
+ <property name="sizeHint" stdset="0">
62
+ <size>
63
+ <width>20</width>
64
+ <height>40</height>
65
+ </size>
66
+ </property>
67
+ </spacer>
68
+ </item>
69
+ </layout>
70
+ </widget>
71
+ <resources/>
72
+ <connections/>
73
+ </ui>
molde/utils/__init__.py CHANGED
@@ -1,5 +1,5 @@
1
1
  from .format_sequences import format_long_sequence
2
- from .poly_data_utils import set_polydata_colors, set_polydata_property
2
+ from .poly_data_utils import set_polydata_colors, set_polydata_property, read_obj_file, read_stl_file, transform_polydata
3
3
  from .tree_info import TreeInfo
4
4
 
5
5
 
@@ -1,5 +1,10 @@
1
+ from pathlib import Path
2
+
1
3
  from vtkmodules.vtkCommonCore import vtkUnsignedCharArray, vtkUnsignedIntArray
2
4
  from vtkmodules.vtkCommonDataModel import vtkPolyData
5
+ from vtkmodules.vtkCommonTransforms import vtkTransform
6
+ from vtkmodules.vtkFiltersGeneral import vtkTransformPolyDataFilter
7
+ from vtkmodules.vtkIOGeometry import vtkOBJReader, vtkSTLReader
3
8
 
4
9
 
5
10
  def set_polydata_colors(data: vtkPolyData, color: tuple) -> vtkUnsignedCharArray:
@@ -15,11 +20,47 @@ def set_polydata_colors(data: vtkPolyData, color: tuple) -> vtkUnsignedCharArray
15
20
  return cell_colors
16
21
 
17
22
 
18
- def set_polydata_property(data: vtkPolyData, property_data: int, property_name: str) -> vtkUnsignedIntArray:
23
+ def set_polydata_property(
24
+ data: vtkPolyData, property_data: int, property_name: str
25
+ ) -> vtkUnsignedIntArray:
19
26
  n_cells = data.GetNumberOfCells()
20
27
  cell_identifier = vtkUnsignedIntArray()
21
28
  cell_identifier.SetName(property_name)
22
29
  cell_identifier.SetNumberOfTuples(n_cells)
23
30
  cell_identifier.Fill(property_data)
24
31
  data.GetCellData().AddArray(cell_identifier)
25
- return cell_identifier
32
+ return cell_identifier
33
+
34
+
35
+ def read_obj_file(path: str | Path) -> vtkPolyData:
36
+ reader = vtkOBJReader()
37
+ reader.SetFileName(str(path))
38
+ reader.Update()
39
+ return reader.GetOutput()
40
+
41
+
42
+ def read_stl_file(path: str | Path) -> vtkPolyData:
43
+ reader = vtkSTLReader()
44
+ reader.SetFileName(str(path))
45
+ reader.Update()
46
+ return reader.GetOutput()
47
+
48
+
49
+ def transform_polydata(
50
+ polydata: vtkPolyData,
51
+ position=(0, 0, 0),
52
+ rotation=(0, 0, 0),
53
+ scale=(1, 1, 1),
54
+ ) -> vtkPolyData:
55
+ transform = vtkTransform()
56
+ transform.Translate(position)
57
+ transform.Scale(scale)
58
+ transform.RotateX(rotation[0])
59
+ transform.RotateY(rotation[1])
60
+ transform.RotateZ(rotation[2])
61
+ transform.Update()
62
+ transformation = vtkTransformPolyDataFilter()
63
+ transformation.SetTransform(transform)
64
+ transformation.SetInputData(polydata)
65
+ transformation.Update()
66
+ return transformation.GetOutput()
@@ -0,0 +1,189 @@
1
+ import logging
2
+ import re
3
+ from time import sleep
4
+
5
+ from PyQt5.QtCore import Qt
6
+ from PyQt5.QtWidgets import QApplication, QLabel, QProgressBar, QWidget
7
+ from PyQt5 import uic
8
+
9
+ from molde import UI_DIR
10
+
11
+
12
+ # Catches every message that contains something like [n/N]
13
+ PROGRESS_FRACTION_REGEX = re.compile(r"\[\d+/\d+\]")
14
+
15
+ # Catches every message that contains something like n%
16
+ PROGRESS_PERCENTAGE_REGEX = re.compile(r"\d+%")
17
+
18
+
19
+ class LoadingWindow(QWidget):
20
+ """
21
+ This function is intended to be called for functions that take
22
+ a long time to run and should run together with a progress bar.
23
+
24
+ The indended use is explained in the following example:
25
+ ```
26
+ def long_function(param_a, param_b=0):
27
+ ...
28
+ return value_c
29
+ ```
30
+
31
+ To run this function with a progress bar you just need to write
32
+ ```
33
+ value_c = LoadingWindow(long_function, param_a, param_b=1234)
34
+ ```
35
+
36
+ Disclaimers:
37
+ This is a monstruosity, but it works.
38
+ I hope no one ever needs to modify it.
39
+ I am trying my best to explain every part of this code.
40
+
41
+ An easier way to do it would be using a QWorker and a QThread,
42
+ but it does not work for our Application.
43
+ Qt manages the windows in the main thread, therefore the function
44
+ to be loaded would need to run in a secondary thread.
45
+ The problem is GMSH (wow, what a surprise).
46
+
47
+ GMSH, for some reason, refuses to run in secondary thread.
48
+ And GMSH is an important part of our software, that of course
49
+ need a progress bar when it is running.
50
+ So this is an attempt to run everything (both GMSH and QT) in the
51
+ main thread without conflicts.
52
+
53
+ I also don't want to mix the interface code with the engine code
54
+ because it can easily became a mess and make the creation of
55
+ automated tests really hard.
56
+ """
57
+
58
+ def __init__(self, _function, application, window_icon):
59
+ super().__init__()
60
+
61
+ ui_path = UI_DIR / "messages/new_loading_window.ui"
62
+ uic.loadUi(ui_path, self)
63
+
64
+ self._function = _function
65
+ self._application = application
66
+ self._window_icon = window_icon
67
+
68
+ self._config_window()
69
+
70
+ def _config_window(self):
71
+ self.setWindowIcon(self._window_icon)
72
+ self.setWindowTitle("Loading")
73
+ self.setWindowFlags(Qt.Window | Qt.CustomizeWindowHint | Qt.WindowTitleHint | Qt.WindowMinimizeButtonHint)
74
+ self.setWindowModality(Qt.ApplicationModal)
75
+ self.update_position()
76
+ self.progress_bar.setValue(0)
77
+
78
+ def _define_qt_variables(self):
79
+ self.progress_bar: QProgressBar
80
+ self.progress_label: QLabel
81
+
82
+ def update_position(self):
83
+ '''
84
+ Place the window on the center of the screen.
85
+ '''
86
+ desktop_geometry = self._application.primaryScreen().geometry()
87
+ pos_x = int((desktop_geometry.width() - self.width())/2)
88
+ pos_y = int((desktop_geometry.height() - self.height())/2)
89
+ self.setGeometry(pos_x, pos_y, self.width(), self.height())
90
+
91
+ def run(self, *args, **kwargs):
92
+ self.show()
93
+
94
+ # Changes the cursor to wait
95
+ QApplication.setOverrideCursor(Qt.WaitCursor)
96
+
97
+ # Creates a handler to update progress_bar and progress_label
98
+ # every time a logging containing [n/N] appears
99
+ progress_handler = ProgressBarLogUpdater(logging.DEBUG, loading_window=self)
100
+ logging.getLogger().addHandler(progress_handler)
101
+
102
+ # Waits the loading bar to appear and uptates pyqt
103
+ sleep(0.1)
104
+ QApplication.processEvents()
105
+
106
+ try:
107
+ # Calls the actual function
108
+ return_value = self._function(*args, **kwargs)
109
+
110
+ finally:
111
+ """
112
+ This piece of code will run even if the function have errors.
113
+ Because the error is not handled here it will propagate to the
114
+ function that called it.
115
+ The error should be threated there, here we are just mitigating
116
+ things related to the loading window.
117
+ """
118
+
119
+ # Restores the previous cursor
120
+ QApplication.restoreOverrideCursor()
121
+
122
+ # Removes the ProgressBarLogUpdater
123
+ logging.getLogger().removeHandler(progress_handler)
124
+
125
+ self.hide()
126
+
127
+ return return_value
128
+
129
+ def __call__(self, *args, **kwargs):
130
+ return self.run(self._function, *args, **kwargs)
131
+
132
+
133
+ class ProgressBarLogUpdater(logging.Handler):
134
+ """
135
+ This class is an log observer. It is meant to watch logs
136
+ and use it to update an instance of the loading window.
137
+ """
138
+
139
+ def __init__(self, level=0, *, loading_window: LoadingWindow) -> None:
140
+ super().__init__(level)
141
+ self.loading_window = loading_window
142
+
143
+ def emit(self, record):
144
+ """
145
+ This function is fired when something is logged.
146
+ If the log have a marker like [n/N] or "..." in its message it
147
+ will update the LoadingWindow associated with this class.
148
+ """
149
+
150
+ # Updates QT to prevent freezing
151
+ QApplication.processEvents()
152
+
153
+ percent = self.get_percentage(record.msg)
154
+
155
+ if percent is not None:
156
+ self.loading_window.progress_label.setText(record.msg)
157
+ self.loading_window.progress_bar.setValue(percent)
158
+
159
+ elif "..." in record.msg:
160
+ self.loading_window.progress_label.setText(record.msg)
161
+
162
+ # Updates QT to show the window modifications
163
+ QApplication.processEvents()
164
+
165
+ def get_percentage(self, message: str):
166
+ """
167
+ Uses regex to check if the message have a marker like [2/10]
168
+ If it does, it extracts the step (2) and the max_step (10) and
169
+ calculates the percentage (20%).
170
+ Otherwise it just returns None.
171
+ """
172
+
173
+ if not isinstance(message, str):
174
+ return
175
+
176
+ matches = PROGRESS_FRACTION_REGEX.findall(message)
177
+ if matches:
178
+ first_match: str = matches[0]
179
+ step, max_step = first_match.strip("[]").split("/")
180
+ percentage = 100 * int(step) // int(max_step)
181
+ return percentage
182
+
183
+ matches = PROGRESS_PERCENTAGE_REGEX.findall(message)
184
+ if matches:
185
+ first_match: str = matches[0]
186
+ percentage = int(first_match.strip("%"))
187
+ return percentage
188
+
189
+ return None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: molde
3
- Version: 0.1.1
3
+ Version: 0.1.3
4
4
  Summary:
5
5
  Author: André Fernandes
6
6
  Author-email: fpf.andre@gmail.com
@@ -1,6 +1,7 @@
1
- molde/__init__.py,sha256=uutAOqWJe5XvTpDdU92HBNYga5Pa9zLaMowJBf-9P9U,92
2
- molde/__main__.py,sha256=CEHF8UXXsTxr2APu7lZX1MXHYR984bjQvgOzYFzh8Zc,2097
3
- molde/actors/__init__.py,sha256=8STcYmULmRKe8RhYih_ENSHR-zl7Rlowwfue5ZOT4yo,176
1
+ molde/__init__.py,sha256=EDwvJl_tqHnoLsB4XI2iVUmtxdrBvrpoxyLkmwaSiSA,124
2
+ molde/__main__.py,sha256=ZB6W4bZTvbgez28mzZ4QEDWjApbndHoL6QeZSw1RG1g,2565
3
+ molde/actors/__init__.py,sha256=XgHvW7jKs4OxL9q-PLNi4ses4CBrXXsnOszZTNJ9CTA,271
4
+ molde/actors/common_symbols_actor.py,sha256=86IkbRvHh9N7QunT3fv_iYahuQ9cJ6Nzhyptu2Jxw4k,5231
4
5
  molde/actors/ghost_actor.py,sha256=9LPRfWCjwHhLrZTAUhmmMNt3Tdb0fDAjjOn6BT-mspI,505
5
6
  molde/actors/lines_actor.py,sha256=T-9arZMV6kSWMmII1UFlGE-6NeAX1_zpmrUhaGNNbd8,1122
6
7
  molde/actors/round_points_actor.py,sha256=FZKq46MZ7IJspE9qdr4xHDoG_6qi4ZE7qzWjV47fv0Y,229
@@ -24,13 +25,16 @@ molde/icons/arrow_up_disabled_light_theme.svg,sha256=mXbCteiX6LX1GPcvFjXa-_cZauF
24
25
  molde/icons/arrow_up_light_theme.svg,sha256=bpon_eUC97Q3nYlHvLPGBDoToUlZq2VHqGJsLMI6Cs4,179
25
26
  molde/icons/check_box_image.svg,sha256=5rKzmsoHYtp52jPY4TpWK0jd7mPLPTteYfbLUF2RJbY,335
26
27
  molde/interactor_styles/__init__.py,sha256=Ovu5F9EycKEDQ9GWYirJhvWaBEjjOZxNsacq3jv3SY4,126
27
- molde/interactor_styles/arcball_camera_style.py,sha256=0PNZbmMZhj-uKSWvuenMmhYU_6JJEMZZ28iVILc9di8,9605
28
+ molde/interactor_styles/arcball_camera_style.py,sha256=vOgv9yli0Ei3tpFUkifFSIl0bzd_ab2QXu1vBYX-XIU,10680
28
29
  molde/interactor_styles/box_selection_style.py,sha256=qQCjvXxryOH1jwBc_jEX0N5q7vanmkFA6r7JJ0ybACk,2619
30
+ molde/main_window.ui,sha256=9ZAsT7Y-bNo2mbB5UX04QgsDlmJh3HTtRVAVtX9m-Hs,26493
29
31
  molde/pickers/__init__.py,sha256=Jyc2t5A9vaypAlQ1U2dXC-XHHDG4jkbw2FoqnnLxh00,109
30
32
  molde/pickers/cell_area_picker.py,sha256=Dhvb-H1l0WqZoqs5Arp-9tGQBxdlNhPdVRCKRKJd--w,2114
31
33
  molde/pickers/cell_property_area_picker.py,sha256=cN2DK9No0BNFruTJKA3SCYUzXrfO8LSnHTbSL8c6W7Q,2953
32
- molde/poly_data/__init__.py,sha256=Yv9vfHFVKnHvspwPYtrjs4501mIKDY80jA3jhiGj4zM,76
34
+ molde/poly_data/__init__.py,sha256=smsqssy-HCKf1rVQD4cMaGdXRL93Oh9y616i0hDsq5I,312
35
+ molde/poly_data/arrows.py,sha256=amd5iVn6jnSixpKFGNWSUdK1LEA8DIftH8KtxCQVOag,1283
33
36
  molde/poly_data/lines_data.py,sha256=DScG3EJSP713HbYdL8Dd8sZy-cQ7xXIlStdZXG5mBPs,737
37
+ molde/poly_data/simple_shapes.py,sha256=h43qE-PDxY9d3pZ6B0_XQ0hBFYGHxGppACQsJrJDGis,560
34
38
  molde/poly_data/vertices_data.py,sha256=Ks6drjDTCd1rFZ9WkTo-rr-lQ_HiW3cLz4YIKKd4V90,697
35
39
  molde/render_widgets/__init__.py,sha256=gTCyI5MXmk7hl4yfrR2BpHPQl9bgYQdNZt2IiSj1Y4o,112
36
40
  molde/render_widgets/animated_render_widget.py,sha256=auh818MYT28-yfN4JkK4H-VQi2KSEo1-7fCJg_oH34M,5516
@@ -53,10 +57,12 @@ molde/stylesheets/qtabwidget.qss,sha256=ygmcTp0S4bzV1X-QcVNKZn88YaLl6MIjCzqqlTHn
53
57
  molde/stylesheets/qtoolbar.qss,sha256=o6WLggd0X1goQk8Ih0YrbxNjnUDwJZFrbzr0pTaltuU,1085
54
58
  molde/stylesheets/qtoolbuttons.qss,sha256=9IkxWx_zwGStuFZoEqGv8xcETnagvQGaFkKNJbLWnhk,286
55
59
  molde/stylesheets/qtreewidget.qss,sha256=nkwjNWFshp-nk_Ug_dLes2ZOU3ERYe8_NRHZt16zLoM,582
56
- molde/utils/__init__.py,sha256=Vi1vpnt_iKSZ9JjAoeyhddSja3p4THoj_KlXIOAbeuc,271
60
+ molde/ui_files/messages/new_loading_window.ui,sha256=h9iIzdqKBoCIfaIwBI8tDMhWm-q8kmkjPSMHY0Eq-cA,1799
61
+ molde/utils/__init__.py,sha256=_hyuh9B44qON6n_K1pOVBVD8wCfFOnEYPkSIW0b_rAg,321
57
62
  molde/utils/format_sequences.py,sha256=ikyjXNXWgFHzg3vrv1lQA5VDJO5A678lHZT7HsMvMCg,1389
58
- molde/utils/poly_data_utils.py,sha256=cG88mGDtbJWU3Dmnnm9xgYsXJn027YAgs1TAlFiD_qo,1035
63
+ molde/utils/poly_data_utils.py,sha256=IJ3TpuSCtinQhPH2uJ1rH7SAenYhgAcay6Cowjvez9o,2191
59
64
  molde/utils/tree_info.py,sha256=DyMshZuQKF_UVk-bchhHfvoRCiGloj49p4ABkZWgkKg,1812
60
- molde-0.1.1.dist-info/METADATA,sha256=goxGic1DLGy7xGlZVE9zKGrwfQ5BwAc0ABGQ5KJp_O0,2038
61
- molde-0.1.1.dist-info/WHEEL,sha256=d2fvjOD7sXsVzChCqf0Ty0JbHKBaLYwDbGQDwQTnJ50,88
62
- molde-0.1.1.dist-info/RECORD,,
65
+ molde/windows/loading_window.py,sha256=DnHEwL3n_702dIGJiG6U--jvUnVKbwhh24buVudDaAc,6477
66
+ molde-0.1.3.dist-info/METADATA,sha256=DFKzHbZ_PnVl6QwVfciEA3epnuaMl2f_EcahsuI33xw,2038
67
+ molde-0.1.3.dist-info/WHEEL,sha256=d2fvjOD7sXsVzChCqf0Ty0JbHKBaLYwDbGQDwQTnJ50,88
68
+ molde-0.1.3.dist-info/RECORD,,
File without changes