Hi everyone,
I'm all new with python language (and not really advanced in programming stuff in general).
Anyway, I tried to program a very small application in python s60, (I simulate it with the nokia simulator at the moment), to make a light "shopping list".
So far, my program asks the user to choose some items from a list and records the choice in a text file (which is recorded in a special directory dedicated to the app.
Then, in a second time, I would like to be able to go back to the user menu choice (create a new list, or use a new list), and if the "use a new list " choice is made, open the text file recorded previously and display is to the screen with the list form (with checkbox if possible).Code:list_tobuy = [u"Bread", u"Water", ...] choicetobuy = appuifw.multi_selection_list (list_tobuy, style='checkbox', search_field=1) for x in choicetobuy: print >> ListFile
To do so, I wrote the following code :
But unfortunately, the screen displays a blank list saying "No data". I think that the list "ListShopG" can't display the items recorded in the file because the "readlines()" doesn't add the "u" before the name of the itemsCode:ListShop = file (u"D:\\Data\\ShopList\\CurrentList.txt", "r+") ListShop.seek(0) ListShopG = ListShop.readlines() appuifw.multi_selection_list(ListShopG, style='checkbox', search_field=1)
Has anyone an idea to solve it ?
Feel free to tell me if I haven't been clear enough.
Below, you can see the whole code that I wrote (I know there are a lot of mistakes, but I'm a real beginner).
As you can see, I also tried to write in the text file the items selected as they should have been written in the code, thinking that if I used the read() function, it would recognise it as a list... (but didn't work eitherCode:#Import of the libraries import appuifw, e32, os, os.path appuifw.app.screen= "normal" #Enable Exit key def quit(): print "Exit key pressed!" app_lock.signal() appuifw.app.exit_key_handler = quit #Presentation/Introduction name = appuifw.query(u"Type your name:", "text", u"My Name is") appuifw.note(u"Welcome to your shopping list Assistant: " + str(name) + u" !" , "conf") #"info", "error" and "conf #Directory creation for the data storage PATH = u"D:\\Data\\ShopList" if not os.path.exists(PATH): os.makedirs(PATH) #from os import chdir #chdir(u"C:\Symbian\8.1a\S60_2nd_FP3\Epoc32\winscw\d\Data\ShopList") #Application Title appuifw.app.title = u"Shopping List Assistant" ######Menu Creation liste_todo = [u"Start New list", u"Use Set up list"] choixmenu = appuifw.selection_list(liste_todo) ######New List Mode if choixmenu == 0: #Txt file creation for the list ListFile = file (u"D:\\Data\\ShopList\\CurrentList.txt", "w+") ListFile.write(u"[") ## appuifw.note(u"New List Mode", "info") choix = 0 while choix != 1: list_tobuy = [u"Bread", u"Water", u"Nutella", u"Programming_skills"] choicetobuy = appuifw.multi_selection_list (list_tobuy, style='checkbox', search_field=1) for x in choicetobuy: #print >> ListFile, list_tobuy[x] #( "u\"" +list_tobuy[x] + "\n\" ") ListFile.write( "u\"" +list_tobuy[x] + "\n\", ") choix = appuifw.query(u"Add some greetings?", "number") ListFile.write(u"]") ## ListFile.seek(0) ListFile.close() appuifw.note(u"Good Bye !", "info") ######Use List Mode elif choixmenu == 1: appuifw.note(u"Use List Mode", "info") ListShop = file (u"D:\\Data\\ShopList\\CurrentList.txt", "r+") ListShop.seek(0) ListShopG = ListShop.readlines() #print ListShopG appuifw.multi_selection_list(ListShopG, style='checkbox', search_field=1) #appuifw.selection_list(u"You have selected in your shopping list: " +ListShop.read() , "info") ListShop.close() ######We want to live the application else: appuifw.note(u"Good Bye !", "conf"))
Many thanks
Ps : Forgive my poor english, but I'm french![]()


).
Reply With Quote

