This commit is contained in:
.[d]. 2023-02-06 15:45:30 -06:00
parent d9373d86dd
commit 56d83d2e9b

View File

@ -2,13 +2,21 @@
import os
import shutil
import sys
from curses import (A_REVERSE, KEY_DOWN, KEY_ENTER, KEY_LEFT, KEY_RIGHT,
KEY_UP, ascii, wrapper)
import curses
from imghdr import what as is_file_an_image
from os import chdir, listdir, path
from pathlib import Path
from random import randint, shuffle
from time import sleep
from tkinter import *
from tkinter import filedialog, ttk
from tkinter.filedialog import askopenfile
from PIL import Image, ImageTk
from random import randint, shuffle
###########################################################################################################################################
class DR1P1M4G3():
#########################################################################################################################################
@ -246,7 +254,17 @@ class DR1P1M4G3():
print('<< dr1p1m4g3 >> screen: {}x{} - image: {}x{} - file: {}/{} - interval: {} - filename: {}'.format(self.root.winfo_screenwidth(),self.root.winfo_screenheight(),self.image.width,self.image.height,self.IMAGE_INDEX,len(self.IMAGE_LIST)-1,self.PUMP_INTERVAL,self.IMAGE_LIST[self.IMAGE_INDEX]))
#########################################################################################################################################
def getfilelist(self):
self.IMAGE_LIST=[ x for x in Path(self.IMAGE_DIR+'/').rglob('*') if not str(x).endswith('.txt') and not "intermediates" in x.name ]
# self.IMAGE_LIST=[ x for x in Path(self.IMAGE_DIR+'/').rglob('*') if not str(x).endswith('.txt') and not "intermediates" in x.name ]
print(f'<<< generating image list recursively from base directory: {self.IMAGE_DIR}/* >>>')
FILE_LIST=[ x for x in Path(self.IMAGE_DIR+'/').rglob('*') ]
self.IMAGE_LIST=[]
for x in FILE_LIST:
try:
if is_file_an_image(str(x)):
self.IMAGE_LIST.append(x)
print(f'added: {str(x)}')
except Exception as e:
print(f'skipped: {str(x)} - reason: {e}')
if self.USER_USERSHUF:
shuffle(self.IMAGE_LIST)
self.IMAGE_INDEX=randint(0,len(self.IMAGE_LIST)-1)
@ -276,9 +294,9 @@ class DR1P1M4G3():
self.root=Tk(className=Name)
self.root.attributes('-fullscreen',True)
self.root.eval('tk::PlaceWindow . center') # self.root.overrideredirect(True)
self.root.wm_attributes("-topmost",True)
self.root.wm_attributes("-transparent",True)
self.root.config(bg='systemTransparent')
#self.root.wm_attributes("-topmost",True)
#self.root.wm_attributes("-transparent",True)
#self.root.config(bg='systemTransparent')
self.image=Image.new(mode='RGB', size=(self.root.winfo_screenwidth(),self.root.winfo_screenheight()))
self.photo=ImageTk.PhotoImage(self.image)
self.canvas=Canvas(self.root,width=self.root.winfo_screenwidth(),height=self.root.winfo_screenheight(),bd=0,highlightthickness=0)
@ -303,20 +321,85 @@ class DR1P1M4G3():
self.root.mainloop()
#######################################################################################################################################
except Exception as err:
print(err)
print(f"main(): {err}")
###########################################################################################################################################
def main(screen):
curses.start_color()
curses.use_default_colors()
curses.init_pair(1,5,0)
curses.init_pair(2,4,0)
curses.init_pair(3,6,0)
curses.init_pair(4,3,0)
ch, first, selected, paths = 0, 0, 0, [ x for x in listdir() if os.path.isdir(x) ]
screen.erase()
try:
screen.addstr(0,0,'SELECT A BASE DIRECTORY',curses.color_pair(2))
screen.addstr(': ',curses.color_pair(1))
screen.addstr('<< ',curses.color_pair(4))
screen.addstr('LEFT',curses.color_pair(3))
screen.addstr('/',curses.color_pair(1))
screen.addstr('RIGHT',curses.color_pair(3))
screen.addstr('/',curses.color_pair(1))
screen.addstr('ENTER',curses.color_pair(3))
screen.addstr(' >>',curses.color_pair(4))
screen.addstr(1,0,'[ ',curses.color_pair(1))
screen.addstr("THE CURRENT DIRECTORY",curses.color_pair(2))
screen.addstr(': ',curses.color_pair(1))
screen.addstr(f"{os.getcwd()}",curses.color_pair(3))
screen.addstr(' ]',curses.color_pair(1))
screen.addstr(2,0,'',curses.color_pair(1))
except Exception as e:
pass
screen.refresh()
sleep(3)
while ch != ascii.ESC:
height, _ = screen.getmaxyx()
screen.erase()
screen.refresh()
try:
paths=sorted(paths)
for y, filename in enumerate(paths[first : first+height]):
screen.addstr(y, 0, filename, A_REVERSE * (selected == first + y))
except:
pass
ch = screen.getch()
selected += (ch == KEY_DOWN) - (ch == KEY_UP)
selected = max(0, min(len(paths)-1, selected))
first += (first <= selected - height) - (first > selected)
if ch in [KEY_LEFT, KEY_RIGHT, KEY_ENTER, 10, 13]:
if not ch==10:
new_dir = '..' if ch == KEY_LEFT else paths[selected]
if path.isdir(new_dir):
chdir(new_dir)
first, selected, paths = 0, 0, [ x for x in listdir() if os.path.isdir(x) ]
paths=sorted(paths)
else:
curses.nocbreak()
curses.endwin()
return str(os.getcwd())
###########################################################################################################################################
if __name__=="__main__":
#########################################################################################################################################
#########################################################################################################################################
DEBUG=True
if DEBUG:
USERPATH=str("/Users/dr1p/Desktop/txt2img-images/")
USERPATH=str(wrapper(main))
IMGINDEX=int(0)
RENDMODE=int(0)
PUMPMODE=int(1)
PUMPTIME=10
USERSHUF=True
else:
USERPATH=str("")
USERPATH=str(wrapper(main))
IMGINDEX=int(0)
RENDMODE=int(0)
PUMPMODE=int(0)