dialogtest for webgen - menues

This commit is contained in:
Wolfgang Nowak 2021-11-28 15:47:58 +01:00
parent cf64321f6d
commit 4def38f66f

View file

@ -5,38 +5,62 @@ from dialog import Dialog
## Initialize a dialog.Dialog instance ## Initialize a dialog.Dialog instance
d = Dialog(dialog="dialog") d = Dialog(dialog="dialog")
clear = "\x1b[2J\x1b[H"
locale.setlocale(locale.LC_ALL, "")
sourcedir = "/home/wn/python/webgen/" sourcedir = "/home/wn/python/webgen/"
targetdir = "/home/wn/www/i21k.de/posts/" targetdir = "/home/wn/www/i21k.de/posts/"
sourcefolder = os.listdir(sourcedir) locale.setlocale(locale.LC_ALL, "")
targetfolder = os.listdir(targetdir) clear = "\x1b[2J\x1b[H"
xwidth = os.get_terminal_size()[0] - 10 xwidth = os.get_terminal_size()[0] - 3
ywidth = os.get_terminal_size()[1] - 10 ywidth = os.get_terminal_size()[1] - 3
os.chdir(sourcedir)
# Put files in sourcefolder into list # Select a topic for the new post or reedit an existing one
zahl = 0 def selectfile():
tabelle = [("", "")] # Put files in sourcefolder into list
for zeile in sourcefolder: zahl = 0
tabelle = []
for zeile in glob.glob("*.md"):
tabelle.insert(zahl, (str(zahl), zeile)) tabelle.insert(zahl, (str(zahl), zeile))
zahl += 1 zahl += 1
# Open list in menu and let user choose one # Open list in menu and let user choose one
ausgewaehlt = d.menu("Biddesehr:", width=xwidth, height=0, menu_height=ywidth, title="Such dir ne Datei", choices=tabelle) ausgewaehlt = d.menu(
"Such dir ne Datei:",
width=xwidth,
height=ywidth,
menu_height=ywidth,
title="Ein Thema wählen:",
choices=tabelle,
cancel="Neuen Namen eingeben",
)
if ausgewaehlt[0] == "cancel": if ausgewaehlt[0] == "cancel":
newtopic = d.inputbox("Ok, gib hier ein neues Thema an:", width=xwidth, height=ywidth, title="Ein Thema wählen:", cancel="Exit")
if newtopic[0] == "cancel" or newtopic[1] == "":
sys.exit("Na, dann eben nicht...") sys.exit("Na, dann eben nicht...")
headline = newtopic[1]
else:
headline = ""
# Clean filename from leading .md for later construction of a headline # Clean filename from leading .md for later construction of a headline
fn = re.sub("\.md$", "", tabelle[int(ausgewaehlt[1])][1]) if headline == "":
headline = re.sub("\.md$", "", tabelle[int(ausgewaehlt[1])][1])
sourcefile = str(glob.glob(sourcedir + fn + ".md")[0]) # if the searched filename doesnt match an existing file we construct a new one
targetfile = glob.glob(targetdir + "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-2][0-9]:[0-6][0-9] " + fn + "*") if len(glob.glob(sourcedir + headline + ".md")) == 0:
targetfilelength = len(targetfile) sourcefile = sourcedir + headline + ".md"
if targetfilelength >= 1: else:
sourcefile = str(glob.glob(sourcedir + headline + ".md")[0])
# if the targetfilename doesnt match an existing file we construct a new one
targetfile = glob.glob(targetdir + "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-2][0-9]:[0-6][0-9] " + headline + "*")
targetfilelength = len(targetfile)
if targetfilelength >= 1:
targetfile = targetfile[targetfilelength - 1] targetfile = targetfile[targetfilelength - 1]
if not targetfile: else:
targetfile = targetdir + datetime.datetime.now().strftime("%Y-%m-%d %H:00 ") + fn targetfile = targetdir + datetime.datetime.now().strftime("%Y-%m-%d %H:00 ") + headline
print(clear, "\nSourcefile: ", sourcefile, "\nTargetfile: ", targetfile)
# return sourcefile, targetfile return sourcefile, targetfile, headline
antwort = selectfile()
print(antwort)