dialogtest for webgen - menues
This commit is contained in:
parent
cf64321f6d
commit
4def38f66f
1 changed files with 51 additions and 27 deletions
|
@ -5,38 +5,62 @@ from dialog import Dialog
|
|||
## Initialize a dialog.Dialog instance
|
||||
d = Dialog(dialog="dialog")
|
||||
|
||||
clear = "\x1b[2J\x1b[H"
|
||||
locale.setlocale(locale.LC_ALL, "")
|
||||
sourcedir = "/home/wn/python/webgen/"
|
||||
targetdir = "/home/wn/www/i21k.de/posts/"
|
||||
sourcefolder = os.listdir(sourcedir)
|
||||
targetfolder = os.listdir(targetdir)
|
||||
xwidth = os.get_terminal_size()[0] - 10
|
||||
ywidth = os.get_terminal_size()[1] - 10
|
||||
locale.setlocale(locale.LC_ALL, "")
|
||||
clear = "\x1b[2J\x1b[H"
|
||||
xwidth = os.get_terminal_size()[0] - 3
|
||||
ywidth = os.get_terminal_size()[1] - 3
|
||||
os.chdir(sourcedir)
|
||||
|
||||
# Select a topic for the new post or reedit an existing one
|
||||
def selectfile():
|
||||
# Put files in sourcefolder into list
|
||||
zahl = 0
|
||||
tabelle = [("", "")]
|
||||
for zeile in sourcefolder:
|
||||
tabelle = []
|
||||
for zeile in glob.glob("*.md"):
|
||||
tabelle.insert(zahl, (str(zahl), zeile))
|
||||
zahl += 1
|
||||
|
||||
# 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":
|
||||
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...")
|
||||
headline = newtopic[1]
|
||||
else:
|
||||
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])
|
||||
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 the searched filename doesnt match an existing file we construct a new one
|
||||
if len(glob.glob(sourcedir + headline + ".md")) == 0:
|
||||
sourcefile = sourcedir + headline + ".md"
|
||||
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]
|
||||
if not targetfile:
|
||||
targetfile = targetdir + datetime.datetime.now().strftime("%Y-%m-%d %H:00 ") + fn
|
||||
print(clear, "\nSourcefile: ", sourcefile, "\nTargetfile: ", targetfile)
|
||||
else:
|
||||
targetfile = targetdir + datetime.datetime.now().strftime("%Y-%m-%d %H:00 ") + headline
|
||||
|
||||
# return sourcefile, targetfile
|
||||
return sourcefile, targetfile, headline
|
||||
|
||||
|
||||
antwort = selectfile()
|
||||
print(antwort)
|
||||
|
|
Loading…
Reference in a new issue