@@ -228,8 +228,7 @@ def __init__(self, parent, ID, pos=wx.DefaultPosition, size=wx.DefaultSize, styl
228228 """
229229 stc .StyledTextCtrl .__init__ (self , parent , ID , pos , size , style )
230230
231- # Do we want to automatically pop up command completion options?
232-
231+ # Do we want to automatically pop up command completion options?
233232 self .autoComplete = True
234233 self .autoCompleteIncludeMagic = True
235234 self .autoCompleteIncludeSingle = True
@@ -469,34 +468,50 @@ def get_current_class(self, pos):
469468
470469 # ------------------ Événement frappe ------------------
471470 def on_key_up (self , event ):
471+ """On key up event handler for auto-completion.
472+
473+ Args:
474+ event: _key up event
475+ """
472476 key = event .GetKeyCode ()
473- if (65 <= key <= 90 ) or (97 <= key <= 122 ) or key == ord ('_' ) or key == ord ('.' ):
477+
478+ return
479+
480+ if (65 <= key <= 90 ) or (97 <= key <= 122 ) or key in (ord ('_' ), ord ('.' )):
474481 pos = self .GetCurrentPos ()
475482 start = self .WordStartPosition (pos , True )
476483 length = pos - start
477484 current_word = self .GetTextRange (start , pos )
478485
479486 self .update_classes_and_instances ()
480487
481- suggestions = set (keyword .kwlist )
482- words = set (self .GetText ().split ())
483- suggestions |= words
484-
485- if '.' in current_word :
486- obj_name , prefix = current_word .rsplit ('.' , 1 )
487- if obj_name == 'self' :
488- cls_name = self .get_current_class (pos )
489- if cls_name and cls_name in self .classes :
490- suggestions |= self .classes [cls_name ]
491- length = len (prefix )
492- else :
493- cls_name = self .instances .get (obj_name )
494- if cls_name and cls_name in self .classes :
495- suggestions |= self .classes [cls_name ]
496- length = len (prefix )
488+ final_suggestions = []
497489
498- # Affiche suggestions locales immédiatement
499- self .AutoCompShow (length , " " .join (sorted (suggestions )))
490+ print (current_word )
491+ # --- CAS SPECIAL : self. ---
492+ if current_word .startswith ("self." ):
493+ prefix = current_word .split ("." , 1 )[1 ] # ce qui est après self.
494+ cls_name = self .get_current_class (pos )
495+ print (cls_name , prefix , self .classes )
496+ if cls_name and cls_name in self .classes :
497+
498+ candidates = self .classes [cls_name ]
499+ # On ne garde que ce qui commence par le préfixe
500+ final_suggestions = sorted (
501+ [c for c in candidates if c .startswith (prefix )]
502+ )
503+ length = len (prefix )
504+
505+ # --- CAS GENERAL ---
506+ # else:
507+ # suggestions = set(keyword.kwlist)
508+ # words = set(re.findall(r"[A-Za-z_][A-Za-z0-9_]*", self.GetText()))
509+ # suggestions |= words
510+ # final_suggestions = sorted(suggestions)
511+
512+ # Affiche uniquement si on a quelque chose à proposer
513+ if final_suggestions :
514+ self .AutoCompShow (length , " " .join (final_suggestions ))
500515
501516 # Appel IA avec délai pour ne pas spammer
502517 # self.last_key_time = time.time()
@@ -1615,11 +1630,13 @@ def CreateMenu(self):
16151630
16161631 return menubar
16171632
1618- def CreateTB (self ):
1633+ def CreateTB (self , tb = None ):
16191634 """ Create tool-bar.
16201635 """
16211636
1622- tb = wx .ToolBar (self , wx .NewIdRef (), name = 'tb' , style = wx .TB_HORIZONTAL | wx .NO_BORDER )
1637+ if not tb :
1638+ tb = wx .ToolBar (self , wx .NewIdRef (), name = 'tb' , style = wx .TB_HORIZONTAL | wx .NO_BORDER )
1639+
16231640 tb .SetToolBitmapSize ((16 , 16 ))# this required for non-standard size buttons on MSW
16241641
16251642 ai_help = _ ('Generative AI based modification' if bool (getattr (builtins , 'SELECTED_IA' )) else 'Check the AI settings in Preferences' )
@@ -1647,11 +1664,10 @@ def CreateTB(self):
16471664 self .Bind (wx .EVT_TOOL , self .nb .OnPaste , id = self .paste .GetId ())
16481665 self .Bind (wx .EVT_TOOL , self .OnAiHelp , id = self .ai .GetId ())
16491666
1650- tb .Realize ()
1651-
1652- ### Add: A. Dominici
16531667 tb .EnableTool (self .ai .GetId (), bool (getattr (builtins ,'SELECTED_IA' )))
16541668
1669+ tb .Realize ()
1670+
16551671 return tb
16561672
16571673 def DoSearch (self , text ):
@@ -2121,6 +2137,8 @@ def __init__(self, parent, id, title):
21212137 """ Constructor.
21222138 """
21232139
2140+ Base .__init__ (self , parent , id , title )
2141+
21242142 ### copy
21252143 self .parent = parent
21262144
@@ -2133,10 +2151,10 @@ def __init__(self, parent, id, title):
21332151 ### create menu, toolbar and statusbar for the frame
21342152 self .menuBar = self .CreateMenu ()
21352153 self .SetMenuBar (self .menuBar )
2136- self .toolbar = self .CreateTB ()
21372154 self .statusbar = self .GetStatusBar ()
21382155
2139- ### set the tool bar
2156+ ### create and set the tool bar
2157+ self .toolbar = self .CreateTB (self .CreateToolBar (wx .TB_HORIZONTAL | wx .NO_BORDER ))
21402158 self .SetToolBar (self .toolbar )
21412159
21422160 ### binding
@@ -2148,7 +2166,6 @@ def __init__(self, parent, id, title):
21482166 e = wx .SizeEvent (self .GetSize ())
21492167 self .ProcessEvent (e )
21502168
2151- Base .__init__ (self , parent , id , title )
21522169
21532170class BlockBase (object ):
21542171 ###
@@ -2621,11 +2638,13 @@ def __init__(self, parent, id, title, block):
26212638 EditorFrame .__init__ (self , parent , id , title )
26222639 BlockBase .__init__ (self , parent , id , title , block )
26232640
2641+ # Icon
26242642 icon_bitmap = load_and_resize_image ('py_file.png' )
2625- icon = wx .Icon ()
2626- icon .CopyFromBitmap (icon_bitmap )
2627- self .SetIcon (icon )
2628-
2643+ if icon_bitmap and icon_bitmap .IsOk ():
2644+ icon = wx .Icon ()
2645+ icon .CopyFromBitmap (icon_bitmap )
2646+ self .SetIcon (icon )
2647+
26292648 self .ConfigureGUI ()
26302649
26312650 ###
@@ -2717,24 +2736,20 @@ def ConfigureGUI(self):
27172736 ### insert new icon in toolbar (icon are not available in embeded editor (Show menu)
27182737 tb = self .GetToolBar ()
27192738
2720- tb .AddSeparator ()
2721- # tb.InsertSeparator(tb.GetToolsCount())
2739+ # tb.AddSeparator()
2740+ tb .InsertSeparator (tb .GetToolsCount ())
27222741
2723- ### combo to insert tips text
2724- cbID = wx .NewIdRef ()
2742+ # # ## combo to insert tips text
2743+ cbID = wx .NewIdRef ()
27252744 tb .AddControl (wx .ComboBox (tb , cbID , _ ("Choose to insert in place" ), choices = self .getChoices (),size = (160 ,- 1 ), style = wx .CB_DROPDOWN ))
2726-
2727- ### search text box
2745+
2746+ # # ## search text box
27282747 tb .AddStretchableSpace ()
27292748 finddlg = TestSearchCtrl (tb , size = (150 ,- 1 ), doSearch = self .DoSearch )
27302749 tb .AddControl (finddlg )
27312750
2732- try :
2733- tb .Realize ()
2734- except :
2735- sys .stdout .write (_ ("Toolbar not displayed on mac..." ))
2736- pass
2737-
2751+ tb .Realize ()
2752+
27382753 if not self .cb .isCMD ():
27392754 self .Bind (wx .EVT_MENU , self .OnInsertPeekPoke , id = peek .GetId ())
27402755 self .Bind (wx .EVT_MENU , self .OnInsertPeekPoke , id = poke .GetId ())
@@ -2760,6 +2775,7 @@ def ConfigureGUI(self):
27602775 self .Bind (wx .EVT_MENU , self .OnInsertDebug , id = debug .GetId ())
27612776 self .Bind (wx .EVT_CLOSE , self .OnClose )
27622777
2778+
27632779 def OnClose (self ,event ):
27642780 """
27652781 """
0 commit comments