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.


    NavView Template

    Pythonista
    4
    8
    4901
    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.
    • niz
      niz last edited by

      I've created a NavView template and put it on GitHub for anyone to use as a starting point for creating a NavView based app using Pythonista. https://github.com/ncarding/NavViewTemplate

      I've done this because it took me ages to workout how to do it myself and I wanted to give something back to the community that unknowingly helped me workout all the problems along the way.

      There is however a fairly large bug with the template that needs fixing before it is truly useful. I've tried various things and I just can't workout why the bug is there and how to fix it.

      As it stands the NavView has two levels: Groups and People. You can create as many Groups as you like and have as many People in each group as you like.

      The UI is built with Pythonista's ui module. The logic uses a custom object orientated module called simple_module. The objects that are created are saved and loaded (for persistence) using the pickle module.

      Known Issue
      The People lists should be independent of the Group lists, but at the moment they are not.

      If you add a new Group then add one or more People to that group and then add a second Group, the People from the first Group are automatically added to the second and any additional Groups.

      I can't tell where the bug is but it only effects Groups created with each launch of the app. E.g. If you create three Groups they will all contain the same People. If you then quit the app and relaunch it those people will still be in each Group but if you create more Groups they will not contain the original list of People. These new Groups will however all share any new People added to any of the Groups created in this session.

      Any suggestions as to why this is happening and how I might fix it are welcome.

      All the code is at https://github.com/ncarding/NavViewTemplate

      1 Reply Last reply Reply Quote 0
      • abcabc
        abcabc last edited by

        The " init" method in simple_module.py is not correct. You can not have "empty list" as default parameter.
        See the discussion here.
        http://effbot.org/zone/default-values.htm
        http://docs.python-guide.org/en/latest/writing/gotchas/

        Mostly this should fix your bug. I have not tested it.

        class Group():
        	def __init__(self, name, people = []):
        		self.name = name
        		# people is a list of People objects
        		self.people = people
        
        1 Reply Last reply Reply Quote 0
        • ccc
          ccc last edited by

          The "fix" code contains an empty list as a default parameter. :-(. I would suggest:

          class Group():
              def __init__(self, name, people=None):
                  self.name = name
                  # people is a list of People objects
                  self.people = people or []  # converts None into an empty list
          
          1 Reply Last reply Reply Quote 0
          • abcabc
            abcabc last edited by

            It is not the fix. It is the part of the code that has the problem. I should have worded that properly. Anyway thanks for the correction.

            1 Reply Last reply Reply Quote 0
            • ccc
              ccc last edited by ccc

              I made a pull request on the repo so there is no ambiguity... I think you are correct that it should solve the open issue.

              1 Reply Last reply Reply Quote 0
              • niz
                niz last edited by

                Thank you for your help. This has indeed fixed the problem.

                The code is there for anyone that wants to make use of it.

                Phuket2 1 Reply Last reply Reply Quote 0
                • Phuket2
                  Phuket2 @niz last edited by Phuket2

                  @niz , thanks for sharing. I have just tried it as I have doing nothing with the nav view before, well at least that I can remember.
                  But 2 things that stand out.

                  1. Seems like it would be easy to make it Python 2.7 and 3 compatible with a try on the pickle import, and maybe a protocol change that either version of pickle loaded could read an existing file.

                  2. Support for different presentations, i.e. Sheet, panel.

                  Just an idea

                  1 Reply Last reply Reply Quote 0
                  • niz
                    niz last edited by

                    Thanks @Phuket2 for the suggestions. I will look into them.

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