1212import os
1313
1414
15-
16-
1715class ConfirmWidget (QtWidgets .QWidget ):
1816 on_accept : typing .ClassVar [QtCore .pyqtSignal ] = QtCore .pyqtSignal (
1917 str , list , name = "on_accept"
2018 )
21- on_reject : typing .ClassVar [QtCore .pyqtSignal ] = QtCore .pyqtSignal (
22- name = "on_reject"
23- )
19+ on_reject : typing .ClassVar [QtCore .pyqtSignal ] = QtCore .pyqtSignal (name = "on_reject" )
2420
2521 on_delete : typing .ClassVar [QtCore .pyqtSignal ] = QtCore .pyqtSignal (
26- str ,str ,name = "on_delete"
22+ str , str , name = "on_delete"
2723 )
2824
2925 def __init__ (self , parent ) -> None :
@@ -33,18 +29,20 @@ def __init__(self, parent) -> None:
3329 self .setAttribute (QtCore .Qt .WidgetAttribute .WA_AcceptTouchEvents , True )
3430 self .thumbnail : QtGui .QImage = QtGui .QImage ()
3531 self ._thumbnails : typing .List = []
32+ self .directory = ""
33+ self .filename = ""
3634 self .confirm_button .clicked .connect (
3735 lambda : self .on_accept .emit (
38- str (self .cf_file_name . _text ), self ._thumbnails
36+ str (os . path . join ( self .directory , self . filename ) ), self ._thumbnails
3937 )
4038 )
4139 self .back_btn .clicked .connect (self .on_reject .emit )
42- self .reject_button .clicked .connect (lambda : self .on_delete .emit (self .directory ,self .filename ))
43-
40+ self .reject_button .clicked .connect (
41+ lambda : self .on_delete .emit (self .directory , self .filename )
42+ )
4443
4544 @QtCore .pyqtSlot (str , dict , name = "on_show_widget" )
4645 def on_show_widget (self , text : str , filedata : dict | None = None ) -> None :
47-
4846 directory = os .path .dirname (text )
4947 filename = os .path .basename (text )
5048 self .directory = directory
@@ -54,9 +52,7 @@ def on_show_widget(self, text: str, filedata: dict | None = None) -> None:
5452 return
5553 self ._thumbnails = filedata .get ("thumbnail_images" , [])
5654 if self ._thumbnails :
57- _biggest_thumbnail = self ._thumbnails [
58- - 1
59- ] # Show last which is biggest
55+ _biggest_thumbnail = self ._thumbnails [- 1 ] # Show last which is biggest
6056 self .thumbnail = QtGui .QImage (_biggest_thumbnail )
6157 _total_filament = filedata .get ("filament_weight_total" )
6258 _estimated_time = filedata .get ("estimated_time" )
@@ -81,9 +77,9 @@ def on_show_widget(self, text: str, filedata: dict | None = None) -> None:
8177 _total_filament = "Unknown"
8278 elif _total_filament > 499 :
8379 _total_filament /= 1000
84- _total_filament = str ("%.2f" % _total_filament ) + "kg"
80+ _total_filament = str ("%.2f" % _total_filament ) + "kg"
8581 else :
86- _total_filament = str ("%.2f" % _total_filament ) + "g"
82+ _total_filament = str ("%.2f" % _total_filament ) + "g"
8783 filament_label = f"Total Filament: { _total_filament } "
8884 time_label = f"Slicer time: { time_str } "
8985 self .cf_info_tf .setText (f"{ filament_label } " )
@@ -104,7 +100,15 @@ def estimate_print_time(self, seconds: int) -> list:
104100 days , hours = divmod (num_hours , 24 )
105101 return [days , hours , minutes , seconds ]
106102
103+ def hide (self ):
104+ self .directory = ""
105+ self .filename = ""
106+ return super ().hide ()
107+
107108 def paintEvent (self , event : QtGui .QPaintEvent ) -> None :
109+ if not self .isVisible ():
110+ self .directory = ""
111+ self .filename = ""
108112 if not hasattr (self , "_scene" ):
109113 self ._scene = QtWidgets .QGraphicsScene (self )
110114 self .cf_thumbnail .setScene (self ._scene )
@@ -165,7 +169,10 @@ def setupUI(self) -> None:
165169 self .cf_header_title .setObjectName ("cf_header_title" )
166170
167171 self .spacer = QtWidgets .QSpacerItem (
168- 60 , 60 , QtWidgets .QSizePolicy .Policy .Fixed , QtWidgets .QSizePolicy .Policy .Fixed
172+ 60 ,
173+ 60 ,
174+ QtWidgets .QSizePolicy .Policy .Fixed ,
175+ QtWidgets .QSizePolicy .Policy .Fixed ,
169176 )
170177 self .spacer .setGeometry (QtCore .QRect (0 , 0 , 60 , 60 ))
171178 self .cf_header_title .addItem (self .spacer )
@@ -180,16 +187,10 @@ def setupUI(self) -> None:
180187 font .setFamily ("Momcake" )
181188 font .setPointSize (24 )
182189 self .cf_file_name .setFont (font )
183- self .cf_file_name .setLayoutDirection (
184- QtCore .Qt .LayoutDirection .RightToLeft
185- )
190+ self .cf_file_name .setLayoutDirection (QtCore .Qt .LayoutDirection .RightToLeft )
186191 self .cf_file_name .setSizePolicy (sizePolicy )
187- self .cf_file_name .setStyleSheet (
188- "background: transparent; color: white;"
189- )
190- self .cf_file_name .setAlignment (
191- QtCore .Qt .AlignmentFlag .AlignCenter
192- )
192+ self .cf_file_name .setStyleSheet ("background: transparent; color: white;" )
193+ self .cf_file_name .setAlignment (QtCore .Qt .AlignmentFlag .AlignCenter )
193194 self .cf_file_name .setObjectName ("cf_file_name" )
194195 self .cf_header_title .addWidget (self .cf_file_name )
195196
@@ -203,16 +204,12 @@ def setupUI(self) -> None:
203204 self .cf_header_title .addWidget (
204205 self .back_btn , 0 , QtCore .Qt .AlignmentFlag .AlignLeft
205206 )
206-
207+
207208 self .verticalLayout_4 .addLayout (self .cf_header_title )
208209 self .cf_content_vertical_layout = QtWidgets .QHBoxLayout ()
209- self .cf_content_vertical_layout .setObjectName (
210- "cf_content_vertical_layout"
211- )
210+ self .cf_content_vertical_layout .setObjectName ("cf_content_vertical_layout" )
212211 self .cf_content_horizontal_layout = QtWidgets .QVBoxLayout ()
213- self .cf_content_horizontal_layout .setObjectName (
214- "cf_content_horizontal_layout"
215- )
212+ self .cf_content_horizontal_layout .setObjectName ("cf_content_horizontal_layout" )
216213 self .info_frame = BlocksCustomFrame (parent = self )
217214 sizePolicy = QtWidgets .QSizePolicy (
218215 QtWidgets .QSizePolicy .Policy .Expanding ,
@@ -222,10 +219,8 @@ def setupUI(self) -> None:
222219
223220 self .info_frame .setFrameShadow (QtWidgets .QFrame .Shadow .Raised )
224221
225-
226222 self .info_layout = QtWidgets .QVBoxLayout (self .info_frame )
227223
228-
229224 self .cf_info_tf = QtWidgets .QLabel (parent = self .info_frame )
230225 font = QtGui .QFont ()
231226 font .setFamily ("Momcake" )
@@ -234,25 +229,23 @@ def setupUI(self) -> None:
234229 self .cf_info_tf .setFont (font )
235230 self .cf_info_tf .setStyleSheet ("background: transparent; color: white;" )
236231
237- self .cf_info_tf .setAlignment (QtCore .Qt .AlignmentFlag .AlignLeft | QtCore .Qt .AlignmentFlag .AlignVCenter )
232+ self .cf_info_tf .setAlignment (
233+ QtCore .Qt .AlignmentFlag .AlignLeft | QtCore .Qt .AlignmentFlag .AlignVCenter
234+ )
238235 self .info_layout .addWidget (self .cf_info_tf )
239236
240-
241237 self .cf_info_tr = QtWidgets .QLabel (parent = self .info_frame )
242238
243239 self .cf_info_tr .setFont (font )
244240 self .cf_info_tr .setStyleSheet ("background: transparent; color: white;" )
245- self .cf_info_tr .setAlignment (QtCore .Qt .AlignmentFlag .AlignLeft | QtCore .Qt .AlignmentFlag .AlignTop )
241+ self .cf_info_tr .setAlignment (
242+ QtCore .Qt .AlignmentFlag .AlignLeft | QtCore .Qt .AlignmentFlag .AlignTop
243+ )
246244 self .info_layout .addWidget (self .cf_info_tr )
247245
248-
249-
250-
251-
252246 self .cf_confirm_layout = QtWidgets .QVBoxLayout ()
253247 self .cf_confirm_layout .setSpacing (15 )
254248
255-
256249 self .confirm_button = BlocksCustomButton (parent = self .info_frame )
257250 self .confirm_button .setMinimumSize (QtCore .QSize (250 , 70 ))
258251 self .confirm_button .setMaximumSize (QtCore .QSize (250 , 70 ))
@@ -264,8 +257,9 @@ def setupUI(self) -> None:
264257 )
265258 self .confirm_button .setText ("Print" )
266259 # 2. Align buttons to the right
267- self .cf_confirm_layout .addWidget (self .confirm_button , 0 , QtCore .Qt .AlignmentFlag .AlignCenter )
268-
260+ self .cf_confirm_layout .addWidget (
261+ self .confirm_button , 0 , QtCore .Qt .AlignmentFlag .AlignCenter
262+ )
269263
270264 self .reject_button = BlocksCustomButton (parent = self .info_frame )
271265 self .reject_button .setMinimumSize (QtCore .QSize (250 , 70 ))
@@ -277,28 +271,23 @@ def setupUI(self) -> None:
277271 )
278272 self .reject_button .setText ("Delete" )
279273 # 2. Align buttons to the right
280- self .cf_confirm_layout .addWidget (self .reject_button , 0 , QtCore .Qt .AlignmentFlag .AlignCenter )
281-
274+ self .cf_confirm_layout .addWidget (
275+ self .reject_button , 0 , QtCore .Qt .AlignmentFlag .AlignCenter
276+ )
282277
283278 self .info_layout .addLayout (self .cf_confirm_layout )
284279
285-
286280 self .cf_content_horizontal_layout .addWidget (self .info_frame )
287281
288-
289- self .cf_content_vertical_layout .addLayout (
290- self .cf_content_horizontal_layout
291- )
282+ self .cf_content_vertical_layout .addLayout (self .cf_content_horizontal_layout )
292283 self .cf_thumbnail = QtWidgets .QGraphicsView (self )
293284 sizePolicy = QtWidgets .QSizePolicy (
294285 QtWidgets .QSizePolicy .Policy .Expanding ,
295286 QtWidgets .QSizePolicy .Policy .Expanding ,
296287 )
297288 sizePolicy .setHorizontalStretch (1 )
298289 sizePolicy .setVerticalStretch (1 )
299- sizePolicy .setHeightForWidth (
300- self .cf_thumbnail .sizePolicy ().hasHeightForWidth ()
301- )
290+ sizePolicy .setHeightForWidth (self .cf_thumbnail .sizePolicy ().hasHeightForWidth ())
302291 self .cf_thumbnail .setSizePolicy (sizePolicy )
303292 self .cf_thumbnail .setMinimumSize (QtCore .QSize (400 , 300 ))
304293 self .cf_thumbnail .setMaximumSize (QtCore .QSize (400 , 300 ))
@@ -331,9 +320,6 @@ def setupUI(self) -> None:
331320 self .cf_content_vertical_layout .addWidget (
332321 self .cf_thumbnail ,
333322 0 ,
334- QtCore .Qt .AlignmentFlag .AlignRight
335- | QtCore .Qt .AlignmentFlag .AlignVCenter ,
323+ QtCore .Qt .AlignmentFlag .AlignRight | QtCore .Qt .AlignmentFlag .AlignVCenter ,
336324 )
337325 self .verticalLayout_4 .addLayout (self .cf_content_vertical_layout )
338-
339-
0 commit comments