Forum Archive

Help with building an app at early stages

craigmrock

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

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

mikael

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

craigmrock

@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).

craigmrock

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

cvp

@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

JonB

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

brumm
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()