@@ -66,6 +66,11 @@ def __init__(self, app):
6666 self .gui = durgui .Gui (guiType = "curses" , window = self .stdscr )
6767 curses .start_color () # Yeayuhhh
6868 self .ansi = AnsiArtStuff (self .appState ) # obj for misc ansi-related stuff
69+ # Disable mouse scrolling for Python versions below 3.10, as they don't have
70+ # curses.BUTTON5_*
71+ if sys .version_info .major == 3 :
72+ if sys .version_info .minor < 10 :
73+ self .appState .hasMouseScroll = False
6974 if self .appState .colorMode == "256" :
7075 if self .ansi .initColorPairs_256color ():
7176 self .appState .theme = self .appState .theme_256
@@ -711,13 +716,13 @@ def showScrollingHelpScreen(self):
711716 elif c in [10 , 13 , curses .KEY_ENTER , 27 , ord ('q' )]: # 27 == escape key
712717 self .playingHelpScreen = False
713718
714-
715- if mouseState & curses .BUTTON4_PRESSED : # wheel up
716- if self .appState .topLine > 0 :
717- self .appState .topLine = self .appState .topLine - 1
718- elif mouseState & curses .BUTTON5_PRESSED : # wheel down
719- if self .appState .topLine + self .realmaxY - 3 < helpMov .sizeY - 1 : # wtf?
720- self .appState .topLine += 1
719+ if self . appState . hasMouseScroll :
720+ if mouseState & curses .BUTTON4_PRESSED : # wheel up
721+ if self .appState .topLine > 0 :
722+ self .appState .topLine = self .appState .topLine - 1
723+ elif mouseState & curses .BUTTON5_PRESSED : # wheel down
724+ if self .appState .topLine + self .realmaxY - 3 < helpMov .sizeY - 1 : # wtf?
725+ self .appState .topLine += 1
721726
722727 new_time = time .time ()
723728 frame_delay = helpMov .currentFrame .delay
@@ -938,12 +943,14 @@ def startPlaying(self):
938943 pass
939944 realmaxY ,realmaxX = self .realstdscr .getmaxyx ()
940945
941- if mouseState & curses .BUTTON4_PRESSED : # wheel up
942- if self .appState .topLine > 0 :
943- self .appState .topLine = self .appState .topLine - 1
944- elif mouseState & curses .BUTTON5_PRESSED : # wheel down
945- if self .appState .topLine + self .realmaxY - 3 < self .mov .sizeY - 1 : # wtf?
946- self .appState .topLine += 1
946+ if self .appState .hasMouseScroll :
947+ if mouseState & curses .BUTTON4_PRESSED : # wheel up
948+ if self .appState .topLine > 0 :
949+ self .appState .topLine = self .appState .topLine - 1
950+ elif mouseState & curses .BUTTON5_PRESSED : # wheel down
951+ if self .appState .topLine + self .realmaxY - 3 < self .mov .sizeY - 1 : # wtf?
952+ self .appState .topLine += 1
953+
947954 elif c in [339 , curses .KEY_PPAGE , ord ('u' ), ord ('b' )]: # page up, and vim keys
948955 self .appState .topLine = self .appState .topLine - self .realmaxY + 3
949956 if self .appState .topLine < 0 :
@@ -1713,10 +1720,13 @@ def mainLoop(self):
17131720 if self .pushingToClip :
17141721 self .pushingToClip = False
17151722 self .stdscr .redrawwin ()
1716- if mouseState & curses .BUTTON4_PRESSED : # wheel up
1717- self .move_cursor_up ()
1718- elif mouseState & curses .BUTTON5_PRESSED : # wheel down
1719- self .move_cursor_down ()
1723+
1724+ if self .appState .hasMouseScroll :
1725+ if mouseState & curses .BUTTON4_PRESSED : # wheel up
1726+ self .move_cursor_up ()
1727+ elif mouseState & curses .BUTTON5_PRESSED : # wheel down
1728+ self .move_cursor_down ()
1729+
17201730 elif self .appState .cursorMode == "Move" : # select mode/move the cursor
17211731 self .xy [1 ] = mouseX + 1 # set cursor position
17221732 self .xy [0 ] = mouseY + self .appState .topLine
@@ -2223,19 +2233,21 @@ def showCharSetPicker(self):
22232233 # mask_all = True
22242234 # masks = ['*.*']
22252235 # update file list
2226- elif mouseState & curses .BUTTON4_PRESSED : # wheel up
2227- # scroll up
2228- # if the item isn't at the top of teh screen, move it up
2229- if selected_item_number > top_line :
2230- selected_item_number -= 1
2231- elif top_line > 0 :
2232- top_line -= 1
2233- elif mouseState & curses .BUTTON5_PRESSED : # wheel down
2234- # scroll down
2235- if selected_item_number < len (block_list ) - 1 :
2236- selected_item_number += 1
2237- if selected_item_number == len (block_list ) - top_line :
2238- top_line += 1
2236+
2237+ elif self .appState .hasMouseScroll :
2238+ if mouseState & curses .BUTTON4_PRESSED : # wheel up
2239+ # scroll up
2240+ # if the item isn't at the top of teh screen, move it up
2241+ if selected_item_number > top_line :
2242+ selected_item_number -= 1
2243+ elif top_line > 0 :
2244+ top_line -= 1
2245+ elif mouseState & curses .BUTTON5_PRESSED : # wheel down
2246+ # scroll down
2247+ if selected_item_number < len (block_list ) - 1 :
2248+ selected_item_number += 1
2249+ if selected_item_number == len (block_list ) - top_line :
2250+ top_line += 1
22392251 else : # add to search string
22402252 search_string += chr (c )
22412253 search_string = search_string .lower () # case insensitive search
@@ -2268,7 +2280,17 @@ def openFilePicker(self):
22682280 else :
22692281 current_directory = os .getcwd ()
22702282 #folders += sorted(glob.glob(f"{current_directory}/*/"))
2271- folders += sorted (glob .glob ("*/" , root_dir = current_directory ))
2283+
2284+ #folders += sorted(glob.glob("*/", root_dir=current_directory)) # python 3.10+
2285+ # python 3.9 compatible block instead:
2286+ folders += sorted (filter (os .path .isdir , glob .glob (os .path .join (current_directory , "*/" ))))
2287+ # remove leading paths
2288+ new_folders = []
2289+ for path_string in folders :
2290+ new_folders .append (os .path .sep .join (path_string .split (os .path .sep )[- 2 :]))
2291+ folders = new_folders
2292+
2293+
22722294 matched_files = []
22732295 file_list = []
22742296 for file in os .listdir (current_directory ):
@@ -2357,9 +2379,9 @@ def openFilePicker(self):
23572379 # display file info - format data
23582380 file_info = f"File: { filename } "
23592381 if file_sauce .sauce_found :
2360- file_info + = f", Title: { file_title } , Artist: { file_author } , Width: { file_width } , Height: { file_height } "
2382+ file_info = f"Title: { file_title } , Artist: { file_author } , Width: { file_width } , Height: { file_height } "
23612383 # show it on screen
2362- self .addstr (realmaxY - 1 , 0 , f"filename: { file_info } " )
2384+ self .addstr (realmaxY - 1 , 0 , f"{ file_info } " )
23632385
23642386 self .stdscr .refresh ()
23652387 # Read keyboard input
@@ -2425,7 +2447,14 @@ def openFilePicker(self):
24252447 current_directory = current_directory [:- 1 ]
24262448 # get file list
24272449 folders = ["../" ]
2428- folders += sorted (glob .glob ("*/" , root_dir = current_directory ))
2450+ #folders += sorted(glob.glob("*/", root_dir=current_directory))
2451+ folders += sorted (filter (os .path .isdir , glob .glob (os .path .join (current_directory , "*/" ))))
2452+ # remove leading paths
2453+ new_folders = []
2454+ for path_string in folders :
2455+ new_folders .append (os .path .sep .join (path_string .split (os .path .sep )[- 2 :]))
2456+ folders = new_folders
2457+
24292458 if mask_all :
24302459 masks = ['*.*' ]
24312460 else :
@@ -2487,7 +2516,14 @@ def openFilePicker(self):
24872516 current_directory = current_directory [:- 1 ]
24882517 # get file list
24892518 folders = ["../" ]
2490- folders += glob .glob ("*/" , root_dir = current_directory )
2519+ #folders += glob.glob("*/", root_dir=current_directory)
2520+ folders += sorted (filter (os .path .isdir , glob .glob (os .path .join (current_directory , "*/" ))))
2521+ # remove leading paths
2522+ new_folders = []
2523+ for path_string in folders :
2524+ new_folders .append (os .path .sep .join (path_string .split (os .path .sep )[- 2 :]))
2525+ folders = new_folders
2526+
24912527 if mask_all :
24922528 masks = ['*.*' ]
24932529 else :
@@ -2530,19 +2566,20 @@ def openFilePicker(self):
25302566 # reset ui
25312567 selected_item_number = 0
25322568 search_string = ""
2533- elif mouseState & curses .BUTTON4_PRESSED : # wheel up
2534- # scroll up
2535- # if the item isn't at the top of teh screen, move it up
2536- if selected_item_number > top_line :
2537- selected_item_number -= 1
2538- elif top_line > 0 :
2539- top_line -= 1
2540- elif mouseState & curses .BUTTON5_PRESSED : # wheel down
2541- # scroll down
2542- if selected_item_number < len (file_list ) - 1 :
2543- selected_item_number += 1
2544- if selected_item_number == len (file_list ) - top_line :
2545- top_line += 1
2569+ elif self .appState .hasMouseScroll :
2570+ if mouseState & curses .BUTTON4_PRESSED : # wheel up
2571+ # scroll up
2572+ # if the item isn't at the top of teh screen, move it up
2573+ if selected_item_number > top_line :
2574+ selected_item_number -= 1
2575+ elif top_line > 0 :
2576+ top_line -= 1
2577+ elif mouseState & curses .BUTTON5_PRESSED : # wheel down
2578+ # scroll down
2579+ if selected_item_number < len (file_list ) - 1 :
2580+ selected_item_number += 1
2581+ if selected_item_number == len (file_list ) - top_line :
2582+ top_line += 1
25462583 else : # add to search string
25472584 search_string += chr (c )
25482585 for filename in file_list : # search list for search_string
@@ -3600,12 +3637,13 @@ def startSelecting(self, firstkey=None, mouse=False): # firstkey is the key th
36003637 pass
36013638 realmaxY ,realmaxX = self .realstdscr .getmaxyx ()
36023639 # enable mouse tracking only when the button is pressed
3603- if mouseState & curses .BUTTON4_PRESSED : # wheel up
3604- if mouseY < self .mov .sizeY and mouseX < self .mov .sizeX : # in edit area
3605- self .move_cursor_up ()
3606- elif mouseState & curses .BUTTON5_PRESSED : # wheel down
3607- if mouseY < self .mov .sizeY and mouseX < self .mov .sizeX : # in edit area
3608- self .move_cursor_down ()
3640+ if self .appState .hasMouseScroll :
3641+ if mouseState & curses .BUTTON4_PRESSED : # wheel up
3642+ if mouseY < self .mov .sizeY and mouseX < self .mov .sizeX : # in edit area
3643+ self .move_cursor_up ()
3644+ elif mouseState & curses .BUTTON5_PRESSED : # wheel down
3645+ if mouseY < self .mov .sizeY and mouseX < self .mov .sizeX : # in edit area
3646+ self .move_cursor_down ()
36093647 elif mouseState == curses .BUTTON1_CLICKED or mouseState & curses .BUTTON_SHIFT :
36103648 if mouseY < self .mov .sizeY and mouseX < self .mov .sizeX : # in edit area
36113649 self .xy [1 ] = mouseX + 1 # set cursor position
0 commit comments