omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Almost finished app, just need advice finalizing it.

    Pythonista
    problem help needed export
    4
    6
    3535
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • procryon
      procryon last edited by

      Hey everyone. So I have an app that is basically ready but I have a few las things I want to polish first. They are listed below. I’d appreciate any advice on how to accomplish the following:

      1. I have two views/sheets in this app. The first one sets up settings for the second one. How can I make it so that the first sheet only appears the first time the app is opened? Like when the user closes and reppens the app, the first sheet will not appear, it goes straight to the second. Is this something done in pythonista or xcode.

      2. In relation to the first question, how do I make the settings the user changes in the first sheet stay permanent dor everytime they open the app, even after closing it? Like if they change the color of a square to red, how can I “save” that so that everytime the user opens the app, the square is red?

      Thank you in advance!!

      cvp 1 Reply Last reply Reply Quote 0
      • cvp
        cvp @procryon last edited by

        @procryon I often use a dictionnary to store the settings of my apps.
        I save the settings in keychain

        When I start my app, I check if the keychain is present:

        settings_str = keychain.get_password(script_name,'settings')
        if settings_str:
        	settings = ast.literal_eval(settings_str) # convert str -> dict
        else:
        	# Init settings
        	settings = {'setting1':'value1','setting2':'value2',...}
        	# Save settings into keychain
        	settings_str = str(settings) # convert dict -> str
        	settings_str = keychain.set_password(script_name,'settings',settings_str)
        
        pastorhudson 1 Reply Last reply Reply Quote 0
        • pastorhudson
          pastorhudson @cvp last edited by

          @cvp said:

          @procryon I often use a dictionnary to store the settings of my apps.
          I save the settings in keychain

          This is a brilliant approach. I was thinking just saving it to a .json file, but keychain seems like a really cool solution.

          cvp 1 Reply Last reply Reply Quote 0
          • cvp
            cvp @pastorhudson last edited by

            @pastorhudson I even support newly added settings or old removed settings:

            	# Eventual remove unused settings
            	#settings_del = ['Serveur','Utilisateur','Mot de passe','Répertoire']		
            	settings_del = []		
            	for setting_key in settings.keys():
            		if setting_key not in settings_init:
            			# setting has been removed, store key to be removed
            			settings_del.append(setting_key)			
            	for setting_key in settings_del:
            		del settings[setting_key]
            				
            	# Eventual add new settings
            	settings[setting_name] = 'value'
            
            1 Reply Last reply Reply Quote 1
            • dgelessus
              dgelessus last edited by

              I'll add my vote for using a JSON file to save settings :) JSON maps nicely to Python lists/dicts, so I find it very convenient to use for this sort of thing. I wouldn't put it in the keychain unless the data is actually sensitive, simply because it seems like the wrong tool for the job. I don't know enough about Pythonista's keychain module and the iOS keychain in general to say if it would actually be bad, but personally I wouldn't want to test it out.

              @cvp By the way, you can use dict.pop(key, None) to remove a key if it's in the dict, and do nothing if it's already missing. That way you can simplify your code to this:

              for key in settings_del:
                  settings.pop(key, None)
              

              Similarly, there's dict.setdefault(key, value): if key is already in the dict, it returns the existing value, otherwise it does dict[key] = value and returns value. That way you can write code like language = settings.setdefault("language", "en-US"), which gets the language from the settings and sets it to "en-US" if missing.

              cvp 1 Reply Last reply Reply Quote 0
              • cvp
                cvp @dgelessus last edited by

                @dgelessus As with only two lines, get_services() and get_keychain(), you can get the data of keychain memory, I never shall store there sensitive data, without a real password protection. I only wanted to store my parameters without using a file that the user could remove by accident.
                About Python dictionary, I recognize I don't know a lot about it.Thanks for the info.

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post
                Powered by NodeBB Forums | Contributors