@@ -124,6 +124,7 @@ def keyPressEvent(self, event: QKeyEvent):
124124 else :
125125 super ().keyPressEvent (event )
126126
127+
127128class PieChart (QGraphicsItem ):
128129 def __init__ (self , dist , r , colors ):
129130 super ().__init__ ()
@@ -202,10 +203,9 @@ def __init__(self):
202203 self .__pending_selection = self .selection
203204 self ._optimizer = None
204205 self ._optimizer_thread = None
205- self ._stop_optimization = False
206+ self .stop_optimization = False
206207
207208 self .data = self .cont_x = None
208- self .assignments = None
209209 self .sizes = None
210210 self .cells = self .member_data = None
211211 self .selection = set ()
@@ -342,7 +342,6 @@ def clear(self):
342342 self .sizes = None
343343 self .cells = self .member_data = None
344344 self .colors = self .bins = None
345- self .assignments = None
346345 if self .elements is not None :
347346 self .scene .removeItem (self .elements )
348347 self .elements = None
@@ -351,10 +350,6 @@ def clear(self):
351350 self .Warning .clear ()
352351 self .Error .clear ()
353352
354- def clear_selection (self ):
355- self .selection .clear ()
356- self .redraw_selection ()
357-
358353 def recompute_dimensions (self ):
359354 self .manual_box .setEnabled (self .manual_dimension )
360355 if not self .manual_dimension and self .cont_x is not None :
@@ -374,7 +369,7 @@ def on_manual_dimension_change(self):
374369 def on_geometry_change (self ):
375370 self .set_legend_pos ()
376371 self .rescale ()
377- if self .elements : # Prevent having redrawn grid but with old elements
372+ if self .elements : # Prevent having redrawn grid but with old elements
378373 self .scene .removeItem (self .elements )
379374 self .elements = None
380375 self .redraw_grid ()
@@ -393,6 +388,10 @@ def on_attr_size_change(self):
393388 def on_pie_chart_change (self ):
394389 self ._redraw ()
395390
391+ def clear_selection (self ):
392+ self .selection .clear ()
393+ self .redraw_selection ()
394+
396395 def on_selection_change (self , selection , action = SomView .SelectionSet ):
397396 if action & SomView .SelectionClear :
398397 self .selection .clear ()
@@ -430,7 +429,6 @@ def on_selection_move(self, event: QKeyEvent):
430429 if {(x , y )} != self .selection :
431430 self .on_selection_change ({(x , y )})
432431
433-
434432 def redraw_selection (self ):
435433 brushes = [QBrush (Qt .NoBrush ), QBrush (QColor (240 , 240 , 255 ))]
436434 sel_pen = QPen (QBrush (QColor (128 , 128 , 128 )), 2 )
@@ -450,7 +448,7 @@ def replot(self):
450448
451449 def restart_som_pressed (self ):
452450 if self ._optimizer_thread is not None :
453- self ._stop_optimization = True
451+ self .stop_optimization = True
454452 else :
455453 self .clear_selection ()
456454 self ._recompute_som ()
@@ -599,14 +597,14 @@ def __init__(self, data, widget):
599597
600598 def callback (self , progress ):
601599 self .update .emit (progress , self .som )
602- return not self .widget ._stop_optimization
600+ return not self .widget .stop_optimization
603601
604602 def run (self ):
605603 self .som .fit (self .data , N_ITERATIONS , callback = self .callback )
606604 self .done .emit (self .som )
607605 self .stopped .emit ()
608606
609- def update (progress , som ):
607+ def update (_progress , som ):
610608 from AnyQt .QtWidgets import qApp
611609 progressbar .advance ()
612610 qApp .processEvents () # This is apparently needed to advance the bar
@@ -639,12 +637,12 @@ def thread_finished():
639637 self ._optimizer .moveToThread (self ._optimizer_thread )
640638 self ._optimizer_thread .started .connect (self ._optimizer .run )
641639 self ._optimizer_thread .finished .connect (thread_finished )
642- self ._stop_optimization = False
640+ self .stop_optimization = False
643641 self ._optimizer_thread .start ()
644642
645643 def stop_optimization_and_wait (self ):
646644 if self ._optimizer_thread is not None :
647- self ._stop_optimization = True
645+ self .stop_optimization = True
648646 self ._optimizer_thread .quit ()
649647 self ._optimizer_thread .wait ()
650648 self ._optimizer_thread = None
@@ -658,9 +656,9 @@ def set_buttons(self, running):
658656 self .grid_box .setDisabled (running )
659657
660658 def _assign_instances (self , som ):
661- self . assignments = som .winners (self .cont_x )
659+ assignments = som .winners (self .cont_x )
662660 members = defaultdict (list )
663- for i , (x , y ) in enumerate (self . assignments ):
661+ for i , (x , y ) in enumerate (assignments ):
664662 members [(x , y )].append (i )
665663 members .pop (None , None )
666664 self .cells = np .empty ((self .size_x , self .size_y , 2 ), dtype = int )
@@ -733,7 +731,7 @@ def create_legend(self):
733731 self .scene .removeItem (self .legend )
734732 self .legend = None
735733 if self .attr_color is None :
736- return None
734+ return
737735
738736 if self .attr_color .is_discrete :
739737 names = self .attr_color .values
@@ -778,6 +776,7 @@ def send_report(self):
778776 self .report_caption (
779777 f"Self-organizing map colored by '{ self .attr_color .name } '" )
780778
779+
781780def _draw_hexagon ():
782781 path = QPainterPath ()
783782 s = 0.5 / (np .sqrt (3 ) / 2 )
0 commit comments