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():
#########################################################################################################################################
@ -23,7 +31,7 @@ class DR1P1M4G3():
#######################################################################################################################################
if IMGINDEX:
self.IMAGE_INDEX=IMGINDEX
self.USER_IMGINDEX=IMGINDEX
self.USER_IMGINDEX=IMGINDEX
else:
self.USER_IMGINDEX=0
self.IMAGE_INDEX=0
@ -88,7 +96,7 @@ class DR1P1M4G3():
def idrop(self,s):
if not os.path.exists(self.IDROP_DIRECTORY):
os.mkdir(self.IDROP_DIRECTORY)
shutil.move(self.IMAGE_LIST[self.IMAGE_INDEX],self.IDROP_DIRECTORY)
shutil.move(self.IMAGE_LIST[self.IMAGE_INDEX],self.IDROP_DIRECTORY)
print(f"<<<<< moved {self.IMAGE_LIST[self.IMAGE_INDEX]} to {self.IDROP_DIRECTORY} >>>>>")
if self.LAST_DIRECTION:
self.right(self)
@ -178,7 +186,7 @@ class DR1P1M4G3():
offset=0
if yy>self.root.winfo_screenheight():
for i in range(100):
if not self.REDIMENSION==1:
if not self.REDIMENSION==1:
self.canvas.delete('all')
sleep(0.1)
self.loadimage()
@ -194,7 +202,7 @@ class DR1P1M4G3():
self.root.title(Buffer)
print(f"{offset} / {x} - {i}")
self.root.update()
else:
else:
self.resized_image=self.image.resize((xx,yy),Image.LANCZOS)
self.photo_resized=ImageTk.PhotoImage(self.resized_image)
self.canvas.create_image(0,0,anchor=NW,image=self.photo_resized)
@ -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)
@ -329,7 +412,7 @@ if __name__=="__main__":
print(f'[ specified user path: {USERPATH} ]')
except:
USERPATH=""
print(f'[ no directory path was specified: defaulting to current directory and recursively ]')
print(f'[ no directory path was specified: defaulting to current directory and recursively ]')
#########################################################################################################################################
if not DEBUG:
try: