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.


    Help with building an app at early stages

    Pythonista
    ui.controls pythonista functions
    5
    8
    5343
    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.
    • craigmrock
      craigmrock last edited by

      Hi,
      I’m looking to get my pythonista code into app mode, and I’m looking for some advice from others. I created the UI folder so I have a UI file and a Python file. The only tutorials I can find are for different types of games.
      I need to figure out how to incorporate my code into the UI layout. Thoughts?
      This is my code, the console says I haven’t defined myInterface, so I need help with that.

      import ui
      import time
      from random import choice
      
      def intro():
      	print("The Guitar Oracle is listening.")
      	time.sleep(2)
      	
      def key (myInterface):
      	viewSelector = myInterface.superview
      	textFromTextBox = viewSelector['textview1'].text
      	keys = ['C','F','Bb','Eb','Ab','Db','Gb', 'Cb','G','D','A','E','B','F#','C#']
      	key = input("Choose your key: ").capitalize()
      	if (key == 'C'):
      		print('You chose C, excellent')
      		ask=input('Major or Minor?: ').lower()
      		if (ask=='major'):
      			cmajor = ['C Ionian: C – D – E – F – G – A – B','C Lydian: C - D - E - F# - G - A - B','C Mixolydian: C - D - E - F - G - A - Bb', 'C Maj Pentatonic: C - D - E - G - A']
      			levels= input('Choose your level (1, 2, or 3): ')
      			validLevel = range(1,4) #provides range for acceptable levels 1, 2, or 3
      			if (levels.isnumeric()):
      				levels = int(levels)
      			if (levels == 1):
      				question = choice(cmajor)
      				print(question)
      			elif (levels == 2):
      				question = choice(cmajor),choice(cmajor)
      				print(question)
      			elif (levels == 3):
      				question = choice(cmajor),choice(cmajor),choice(cmajor)
      				print(question)
      			if (ask=='minor'):
      				cminor = ['C Dorian: C - D - Eb - F - G - A - Bb','C Phrygian: C - Db - Eb - F - G - Ab - Bb', 'C Aeolian: C - D - Eb - F - G - Ab - Bb','C Locrian: C - Db - Eb - F - Gb - Ab - Bb', 'C Harmonic Minor: C - D - Eb - F - G - Ab - B','C Melodic Minor: C - D - Eb - F - G - A - B','C Min Pentatonic: C - Eb - F - G - Bb']
      				levels= input('Choose your level (1, 2, or 3): ')
      				validLevel = range(1,4) #provides range for acceptable levels 1, 2, or 3
      				if (levels.isnumeric()):
      					levels = int(levels)
      				if (levels == 1):
      					question = choice(cminor)
      					print(question)
      				elif (levels == 2):
      					question = choice(cminor),choice(cminor)
      					print(question)
      				elif (levels == 3):
      					question = choice(cminor),choice(cminor),choice(cminor)
      					print(question)
      if __name__ == "__main__":
      	intro()
      	practicing = True
      	while practicing: #prompts the user to keep playing
      		key(myInterface)
      		viewSelector = myInterface.superview
      		textFromTextBox = viewSelector['textview1'].text
      		time.sleep(2)
      		keepPracticing = input('Do you want to keep practicing (yes or no)? ')
      		validUser = ['yes', 'y','sure','ok','k','okay'] #acceptable answers for keepPracticing
      		if (keepPracticing not in validUser): practicing = False #terminates program/loop
      		print('Goodbye')
      v = ui.load_view()
      v.present('sheet')
      
      
      
      cvp mikael 2 Replies Last reply Reply Quote 0
      • cvp
        cvp @craigmrock last edited by

        @craigmrock to be able to help you, we also need your .pyui file

        craigmrock 1 Reply Last reply Reply Quote 0
        • mikael
          mikael @craigmrock last edited by

          @craigmrock, are your files named the same (myInterface.py and myInterface.pyui) and in the same directory?

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

            @cvp I’m not sure how to show that here, I don’t see adding a picture/screenshot option and my UI file only shows the grid layout. I thought I had accessed a code version before, but every button I press in the menu seems to take me everywhere but where the code is (using my iPhone, not a tablet).

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

              @mikael they aren’t named myInterface, but they are both named the same thing, GOapp.py and GOapp.pyui in the same folder

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

                @craigmrock it is always possible to rename temporarily your .pyui file as .txt, then edit it, select all, copy and paste here, like you did for your .py file

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

                  https://github.com/humberry/ui-tutorial has several tutorials

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

                    import ui
                    import time
                    from random import choice
                    
                    class myclass():
                      def __init__(self):
                        #self.v = ui.load_view('UIwithOtherName.pyui')
                        self.v = ui.load_view()
                        self.v.present('sheet')
                        self.v.name = 'goapp'
                        self.intro()
                        self.key()
                    
                      def intro(self):
                        self.v['textfield1'].text = "The Guitar Oracle is listening."
                        time.sleep(2)
                          
                      def key(self):
                        self.v['textfield1'].text = "Good bye."
                              
                    myclass()
                    
                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post
                    Powered by NodeBB Forums | Contributors