@@ -1036,11 +1036,11 @@ def help_cascade_post():
10361036 tree_bind ("<Leave>" , lambda event : self .widget_leave ())
10371037
10381038 tree_bind ('<KeyPress>' , self .key_press )
1039- tree_bind ('<<TreeviewOpen>>' , lambda event : self .open_item ())
1039+ tree_bind ('<<TreeviewOpen>>' , lambda event : self .open_item_with_update ())
10401040 tree_bind ('<<TreeviewClose>>' , lambda event : self .close_item ())
10411041 tree_bind ('<ButtonPress-3>' , self .context_menu_show )
10421042
1043- tree_bind ("<<TreeviewSelect>>" , lambda event : self .tree_on_select () )
1043+ # tree_bind("<<TreeviewSelect>>", lambda event : self.tree_on_select() )
10441044
10451045 tree_bind ("<Configure>" , lambda event : self .tree_configure ())
10461046
@@ -4205,12 +4205,15 @@ def select_find_result(self,mod,record_par=None,subpath_list_par=None):
42054205 current_item = child_item
42064206
42074207 self_open_item (current_item )
4208+ self .visible_items_update ()
42084209
42094210 self_tree_update ()
42104211 else :
42114212 self .info_dialog_on_main .show ('cannot find item:' ,item_name )
42124213 break
42134214
4215+ self .visible_items_update ()
4216+
42144217 #if self.find_dialog_shown:
42154218 # self.tree.selection_set(current_item)
42164219 #else:
@@ -4231,11 +4234,10 @@ def select_find_result(self,mod,record_par=None,subpath_list_par=None):
42314234 KEY_DIRECTION ['Next' ]= 1
42324235 KEY_DIRECTION ['Up' ]= - 1
42334236 KEY_DIRECTION ['Down' ]= 1
4234- KEY_DIRECTION ['Home' ]= 0
4237+ KEY_DIRECTION ['Home' ]= 1
42354238 KEY_DIRECTION ['End' ]= - 1
42364239
4237- @block
4238- def goto_next_prev_record (self ,direction ):
4240+ def goto_next_prev (self ,direction ):
42394241 tree = self .tree
42404242
42414243 item = tree .focus ()
@@ -4261,7 +4263,7 @@ def goto_next_prev_record(self,direction):
42614263 self .select_and_focus (item_to_sel )
42624264
42634265 @block
4264- def goto_first_last_record (self ,index ):
4266+ def goto_border_node (self ,index ):
42654267 tree = self .tree
42664268
42674269 item = tree .focus ()
@@ -4292,8 +4294,9 @@ def visible_items_update(self):
42924294
42934295 def get_visible_items (self ,item = "" ):
42944296 self_tree_get_children = self .tree .get_children
4297+ self_get_visible_items = self .get_visible_items
42954298 if self .tree .item (item ,"open" ) or item == "" :
4296- return [item ] + [grandchild for child in self_tree_get_children (item ) for grandchild in self . get_visible_items (child )]
4299+ return [item ] + [grandchild for child in self_tree_get_children (item ) for grandchild in self_get_visible_items (child )]
42974300 else :
42984301 return [item ]
42994302
@@ -4315,7 +4318,7 @@ def wrapped_see(self, item):
43154318
43164319 if self .see_direction < 0 :
43174320 try :
4318- pi = self .get_prev_index (item_index ,self .rows_offset )
4321+ pi = self .get_prev_index (item_index ,self .rows_offset_minus )
43194322
43204323 prev_item = self .visible_items [pi ]
43214324
@@ -4328,7 +4331,7 @@ def wrapped_see(self, item):
43284331
43294332 elif self .see_direction > 0 :
43304333 try :
4331- ni = self .get_next_index (item_index ,self .rows_offset ,self .visible_items_max_index )
4334+ ni = self .get_next_index (item_index ,self .rows_offset_plus ,self .visible_items_max_index )
43324335 next_item = self .visible_items [ni ]
43334336
43344337 if next_item :
@@ -4389,12 +4392,15 @@ def tree_item_focused(self,item,can_move=True):
43894392 self .current_group = None
43904393 self .current_subpath_list = None
43914394
4392- rows_offset = 0
4395+ rows_offset_plus = 0
4396+ rows_offset_minus = 0
43934397 def tree_configure (self ):
43944398 try :
4395- self .rows_offset = int ( (self .tree .winfo_height () / self .rowhight ) / 3 )
4399+ self .rows_offset_plus = int ( (self .tree .winfo_height () / self .rowhight ) * 0.75 - 1 )
4400+ self .rows_offset_minus = int ( (self .tree .winfo_height () / self .rowhight ) * 0.25 - 1 )
43964401 except :
4397- self .rows_offset = 0
4402+ self .rows_offset_plus = 0
4403+ self .rows_offset_minus = 0
43984404
43994405 def tree_on_select (self ,can_move = True ):
44004406 item = self .tree .focus ()
@@ -4408,6 +4414,35 @@ def tree_on_select(self,can_move=True):
44084414
44094415 see_direction = 0
44104416
4417+ def get_last_visible_descendant (self , item ):
4418+ while self .tree .item (item , "open" ):
4419+
4420+ children = self .tree .get_children (item )
4421+ if not children :
4422+ break
4423+ item = children [- 1 ]
4424+ return item
4425+
4426+ def get_next_visible_item (self , item ):
4427+ self_tree_get_children = self .tree .get_children
4428+ if item :
4429+ if self .tree .item (item , "open" ):
4430+ if children := self_tree_get_children (item ):
4431+ return children [0 ]
4432+
4433+ self_tree_parent = self .tree .parent
4434+ while item :
4435+ parent = self_tree_parent (item )
4436+ siblings = self_tree_get_children (parent )
4437+ index = siblings .index (item )
4438+
4439+ if index + 1 < len (siblings ):
4440+ return siblings [index + 1 ]
4441+
4442+ item = parent
4443+
4444+ return None
4445+
44114446 @key_press_guard
44124447 def key_press (self ,event ):
44134448 if not self .block_processing_stack :
@@ -4423,22 +4458,45 @@ def key_press(self,event):
44234458 except :
44244459 pass
44254460
4461+ self .visible_items_update ()
44264462 try :
44274463 item = tree .focus ()
44284464 key = event .keysym
44294465
44304466 if key in ("Prior" ,"Next" ):
4431- self .visible_items_update ()
44324467 self .see_direction = self .KEY_DIRECTION [key ]
4433- self .goto_next_prev_record (self .KEY_DIRECTION [key ])
4468+ self .goto_next_prev (self .KEY_DIRECTION [key ])
44344469 return "break"
4435- elif key in ( "Home" , "End" ) :
4436- self .visible_items_update ()
4437- self .goto_first_last_record ( self . KEY_DIRECTION [ key ] )
4470+ elif key == "Home" :
4471+ self .see_direction = - 1
4472+ self .goto_border_node ( 0 )
44384473 return "break"
4439- elif key in ("Up" ,"Down" ):
4440- self .see_direction = self .KEY_DIRECTION [key ]
4441- self .visible_items_update ()
4474+ elif key == "End" :
4475+ self .see_direction = 1
4476+ self .goto_border_node (- 1 )
4477+ return "break"
4478+ elif key == "Up" :
4479+ self .see_direction = - 1
4480+
4481+ if item :
4482+ parent = tree .parent (item )
4483+ siblings = tree .get_children (parent )
4484+
4485+
4486+ index = siblings .index (item )
4487+
4488+ if index > 0 :
4489+ self .select_and_focus (self .get_last_visible_descendant (siblings [index - 1 ]))
4490+ else :
4491+ if parent :
4492+ self .select_and_focus (parent )
4493+
4494+ return "break"
4495+ elif key == "Down" :
4496+ self .see_direction = 1
4497+ if next_item := self .get_next_visible_item (self .sel_item ):
4498+ self .select_and_focus (next_item )
4499+ return "break"
44424500 elif key == "Return" :
44434501 event_str = str (event )
44444502 alt_pressed = ('0x20000' in event_str ) if windows else ('Mod1' in event_str or 'Mod5' in event_str )
@@ -4449,7 +4507,7 @@ def key_press(self,event):
44494507 return
44504508 else :
44514509 item = tree .focus ()
4452- self .open_item (item )
4510+ self .open_item_with_update (item )
44534511 tree .update ()
44544512 elif key == "Alt_L" :
44554513 return "break"
@@ -4468,7 +4526,10 @@ def key_press(self,event):
44684526 elif key == "Right" :
44694527 if tree .get_children (self .sel_item ):
44704528 tree .item (self .sel_item , open = True )
4471- self .open_item ()
4529+ self .open_item_with_update ()
4530+ self .see_direction = 1
4531+ self .select_and_focus (self .sel_item )
4532+
44724533 return "break"
44734534 else :
44744535 #print(key)
@@ -4483,22 +4544,20 @@ def key_press(self,event):
44834544 l_error (e )
44844545 self .info_dialog_on_main .show ('INTERNAL ERROR key_press' ,str (e ))
44854546
4486- self .tree_on_select ()
4547+ # self.tree_on_select()
44874548
44884549#################################################
44894550 def select_and_focus (self ,item ):
44904551 #print('select_and_focus',item)
44914552 self_tree = self .tree
44924553
4554+ self .sel_item = item
44934555 self .tree_focus (item )
44944556 self .tree_item_focused (item )
44954557
44964558 self_tree .see (item )
44974559 self_tree .update ()
44984560
4499- #self.see_direction=0
4500- self .visible_items_update ()
4501-
45024561 self .wrapped_see (item )
45034562
45044563 def tree_on_mouse_button_press_search_results (self ,event ):
@@ -4529,6 +4588,8 @@ def tree_on_mouse_button_press(self,event):
45294588 tree = self .tree
45304589 region = tree .identify ("region" , event .x , event .y )
45314590
4591+ self .see_direction = 0
4592+
45324593 if region != 'separator' :
45334594 if region == 'heading' :
45344595 col_nr = tree .identify_column (event .x )
@@ -4541,8 +4602,9 @@ def tree_on_mouse_button_press(self,event):
45414602 elif item := tree .identify ('item' ,event .x ,event .y ):
45424603 #tree.selection_remove(tree.selection())
45434604
4544- tree .focus (item )
4545- self .tree_on_select (False )
4605+ self .select_and_focus (item )
4606+ #tree.focus(item)
4607+ #self.tree_on_select(False)
45464608 self .set_find_result_record_index ()
45474609
45484610 self .set_find_result_indexes (self .current_subpath_list )
@@ -4596,15 +4658,6 @@ def context_menu_show(self,event):
45964658 state_on_records_or_groups = 'normal' if is_record or is_group else 'disabled'
45974659
45984660 c_nav = Menu (self .menubar ,tearoff = 0 ,bg = self .bg_color )
4599- #c_nav_add_command = c_nav.add_command
4600- #c_nav_add_command = pop_add_command
4601- #c_nav_add_separator = c_nav.add_separator
4602-
4603- #c_nav_add_command(label = STR('Go to next record') ,command = lambda : self.goto_next_prev_record(1),accelerator="Pg Down",state='normal', image = self.ico_empty,compound='left')
4604- #c_nav_add_command(label = STR('Go to previous record') ,command = lambda : self.goto_next_prev_record(-1), accelerator="Pg Up",state='normal', image = self.ico_empty,compound='left')
4605- #c_nav_add_separator()
4606- #c_nav_add_command(label = STR('Go to first record') ,command = lambda : self.goto_first_last_record(0),accelerator="Home",state='normal', image = self.ico_empty,compound='left')
4607- #c_nav_add_command(label = STR('Go to last record') ,command = lambda : self.goto_first_last_record(-1), accelerator="End",state='normal', image = self.ico_empty,compound='left')
46084661
46094662 pop_add_command (label = STR ('New record ...' ), command = self .scan_dialog_show ,accelerator = 'Ctrl+N' ,image = self .ico_record_new ,compound = 'left' )
46104663 pop_add_separator ()
@@ -4756,7 +4809,7 @@ def assign_to_group(self):
47564809 self .group_to_size_sum [group ] += size
47574810 self .single_group_update_size (group )
47584811
4759- self .open_item (group_item )
4812+ self .open_item_with_update (group_item )
47604813 self .tree .focus (record_item )
47614814 self .wrapped_see (record_item )
47624815
@@ -5758,6 +5811,8 @@ def locate_found_item(self,item):
57585811 self .info_dialog_on_main .show ('cannot find item:' ,item_name )
57595812 break
57605813
5814+ self .visible_items_update ()
5815+
57615816 #if self.find_dialog_shown:
57625817 # self.tree.selection_set(current_item)
57635818 #else:
@@ -5770,6 +5825,10 @@ def locate_found_item(self,item):
57705825 def close_item (self ,item = None ):
57715826 self .visible_items_uptodate = False
57725827
5828+ def open_item_with_update (self ,item = None ):
5829+ self .open_item (item )
5830+ self .visible_items_update ()
5831+
57735832 @block
57745833 def open_item (self ,item = None ):
57755834 tree = self .tree
@@ -5883,11 +5942,7 @@ def open_item(self,item=None):
58835942 else :
58845943 pass
58855944
5886- self .visible_items_uptodate = False
5887-
5888- self .see_direction = 0
5889- #self.wrapped_see(item)
5890- #self.tree_on_select()
5945+ self .visible_items_uptodate = False
58915946
58925947 def get_record_raw_icon (self ,record ):
58935948 return self .ico_record_raw_cd if record .has_cd () else self .ico_record_raw
@@ -5961,12 +6016,13 @@ def single_record_show(self,record,batch_mode=False):
59616016 self_tree .focus (record_item )
59626017 self .wrapped_see (record_item )
59636018
6019+ self .tree_on_select ()
6020+
59646021 #if expand_groups:
59656022 #else:
59666023 # self_tree.focus(group_item)
59676024 # self.wrapped_see(group_item)
59686025
5969- self .tree_on_select ()
59706026
59716027 self .update_records_stats ()
59726028
0 commit comments