This is a script to auto generate .txt outlines commonly seen in readme files, guides, video game walkthroughs, etc.
Its prompt-based and allows for custom brackets and separators as well as an option to cancel if you mis-clicked. I'm new to python so much of the code is probably convoluted and not "pythonic", but nevertheless I think it may be useful.
layers=[]title="Auto-Outline"FLAG_RUN=TrueYNC=notepad.messageBox("Welcome to the Auto-Outliner.\nDefault enclosures are [x.y.z...]\nIs this OK?",title,MESSAGEBOXFLAGS.YESNOCANCEL)ifYNC==MESSAGEBOXFLAGS.RESULTYES:op,sep,cl=("[",".","]")elifYNC==MESSAGEBOXFLAGS.RESULTCANCEL:FLAG_RUN=Falseelse:whileYNC==MESSAGEBOXFLAGS.RESULTNO:op=notepad.prompt("Enter opening string:",title,"[")sep=notepad.prompt("Format:"+op+"x...\nEnter separator string:",title,".")cl=notepad.prompt("Format:"+op+"x"+sep+"y...\nEnter separator string:",title,"]")YNC=notepad.messageBox("Format: "+op+sep.join(["x","y","z"])+"..."+cl+" OK?",title,MESSAGEBOXFLAGS.YESNO)ifFLAG_RUNisTrue:defas_tag(ids,OpCl=False):"""Used to take a list of [x,y,z,...] integers and turn it into a string using sep and optionally op/cl"""ifOpClisFalse:returnsep.join([str(x) for x in ids])elifOpClisTrue:returnop+sep.join([str(x) for x in ids])+cltitle2=title+"(Use Cancel to end a section)"YN=MESSAGEBOXFLAGS.RESULTYES#Loopthroughwhileuseragreestoaddlayers.whileYN==MESSAGEBOXFLAGS.RESULTYES:cur_layer={}cur_name=""#Firsttimethrough,noprevioussectiontodisplayiflen(layers)==0:id_cur_name=1whilenotcur_nameisNone:cur_name=notepad.prompt("Current sections: "+",".join(cur_layer.values())+"\nEnter section "+str(id_cur_name)+":",title2)ifcur_name=="":cur_name=Noneifnotcur_nameisNone:cur_layer[str(id_cur_name)]=cur_nameid_cur_name+=1#Otherwise,displayprevioussectiontitleelse:id_prv_layer=len(layers)-1cur_layer={}prv_layer=layers[id_prv_layer].keys()prv_layer.sort()fortaginprv_layer:cur_name=""id_cur_name=1cur_sublayer={}ids_cur=[]whilenotcur_nameisNone:cur_name=notepad.prompt(op+tag+cl+" = "+layers[id_prv_layer][tag]+"\nCurrent subsections: "+",".join([x + " " + cur_sublayer[x]forxinids_cur])+" ... "+as_tag([tag,str(id_cur_name)])+" = ?",title2)ifcur_name=="":cur_name=Noneids_cur.append(as_tag([tag,id_cur_name]))ifnotcur_nameisNone:cur_sublayer[as_tag([tag,id_cur_name])]=cur_nameid_cur_name+=1cur_layer.update(cur_sublayer)layers.append(cur_layer)YN=notepad.messageBox("Add another layer?",title,MESSAGEBOXFLAGS.YESNO)#Beginoutputfile...notepad.new()tot_layers=len(layers)-1defwrite_subs_main(cur_tag,layer_num,just_val,body=False):"""This function should recursively call itself, writing 3 space indented outline parts until finished."""ifbodyisFalse:editor.addText("".join([" " for x in range(layer_num)])+as_tag([str(cur_tag)],OpCl=True)+" "+layers[layer_num][cur_tag]+"\n")elifbodyisTrue:editor.addText("\t\tSection "+as_tag([str(cur_tag)],OpCl=True).rjust(just_val)+" "+layers[layer_num][cur_tag]+"\n"*3)iflayer_num<tot_layers:next_layer=layers[layer_num + 1]next_tags=next_layer.keys()next_tags.sort()fornext_taginnext_tags:ifcur_taginnext_tag[0:len(cur_tag)]:write_subs_main(next_tag,layer_num+1,just_val,body)main_tags=layers[0].keys()main_tags.sort()#Thiscodegrabsthelengthofthelongesttaglineandusesittojustifyoutputsmax_len=max([len(as_tag([x],OpCl=True))forxinlayers[tot_layers].keys()])fortaginmain_tags:write_subs_main(tag,0,max_len)editor.addText("\n"*3)fortaginmain_tags:write_subs_main(tag,0,max_len,body=True)else:pass
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Very handy! I'm no Python expert either, but the auto-type-conversion can come in very handy to make things shorter and more readable. For instance, and empty string and None are converted to False when a boolean is needed, a non-empty string is converted to true, so you can say
ifnotbody:
...
elifbody:
...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This is a script to auto generate .txt outlines commonly seen in readme files, guides, video game walkthroughs, etc.
Its prompt-based and allows for custom brackets and separators as well as an option to cancel if you mis-clicked. I'm new to python so much of the code is probably convoluted and not "pythonic", but nevertheless I think it may be useful.
Very handy! I'm no Python expert either, but the auto-type-conversion can come in very handy to make things shorter and more readable. For instance, and empty string and None are converted to False when a boolean is needed, a non-empty string is converted to true, so you can say