jpuk / rpi-128x64-oled-menusystem

Simple python 3 library for creating a menu driven interface on 128x64 OLED displays for Raspberry Pi's
GNU Lesser General Public License v2.1
27 stars 3 forks source link

unbound method myfunction1() #1

Open fujiman3 opened 6 years ago

fujiman3 commented 6 years ago

I ran the menusystem on a Raspberry Pi Zero, menu shows correctly, selected "help" then "function1" got the following error. TypeError: unbound method myFunction1() must be called with MenuFunc_Base instan ce as first argument (got nothing instead).

What I've changed: - on my local files. The pin numbers for the buttons. Added pull down option in the button setup section, the pins on my Pi were constantly high (insert joke here). Uncommented functionHandlersDictionary in myfunctions.py - I was getting a global variable error.

My knowledge of Python is limited. Any guidance will be much appreciated.

jpuk commented 6 years ago

Hey, sorry to hear you're having some issues.

It's been a while since I played with this code and I never fleshed it out to be functional for much more than the most basic of demos but I'll have a look through the code and see if I can get reacquainted.

I've not got my rpi set up so might have some issues running the code here.

Are you able to post the full error message?

jpuk commented 6 years ago

Out of interest, if you comment out everything after import globalsettings in myFunctions.py and replace it with;

def myFunction1():
    print("Executing myFunction1")

def myFunction2():
    print("Executing myFunction2")

functionHandlersDictionary = { "myFunction1":  [myFunction1, "My function 1"], "myFunction2": [myFunction2, "My Function 2"]}

Does that work?

fujiman3 commented 6 years ago

Here's the full traceback: Button 2 handler ('selecting menu screen ', 998) Call to menu function handler ('Looking for match for ', 'myFunction1')

#this is from the print statement within executeFunctionHandler Traceback (most recent call last): File "menu.py", line 53, in main() File "menu.py", line 42, in main menusystem.checkButtons() File "./menuSystemClass.py", line 104, in checkButtons button.buttonPress(menu=self.menus[globalsettings.selectedMenu],menufunc=self.myMenuFunctions) File "./buttonClass.py", line 24, in buttonPress self.action(self, menu=menu, menufunc=menufunc) File "./buttonClass.py", line 57, in button2Handler menufunc.executeFunctionHandler(functionLable) File "./menuHandlerClass.py", line 180, in executeFunctionHandler func() TypeError: unbound method myFunction1() must be called with MenuFunc_Base instance as first argument (got nothing instead) I tried your recommendation, but it just throws up an error: NameError: name 'MenuFunc_Base' is not defined. Thanks for replying - which I didn't expect really. Don't waste too much time on this, I shall plod on till I find it. I am planning on using this menu system in my project because this is one of a very few menus I've come across that could be easily adaptable.
fujiman3 commented 6 years ago

addendum: The print output line seems to have vanished from my post, just after ('Looking for ....... ) it should have a line that says "" -- this is from the print statement within executeFunctionHandler

fujiman3 commented 6 years ago

I'm sorry about this but the text I'm trying to post is being ignored, it should be between the double quotes in the previous comment. I'll put it into a text file instead. errortext.txt

jpuk commented 6 years ago

Cheers that's great.

Yes the markup plays havoc with text.

I think it should work if you put < pre ></ pre > tags around the text. (without spaces)

jpuk commented 6 years ago

Starting to get my head round the code a little bit now.

Are you able to post the full debug output including the initialisation.

Do you get any debug info about "function handle registered"?

fujiman3 commented 6 years ago

Here is the full initialisation output:

Initialising MenuSystem object
Menu Reader class initialized
('Menus will be read from ', 'menus/')
('Processing menu file ', 'menus/menu.0')
('Processing menu file ', 'menus/menu.1')
('Processing menu file ', 'menus/menu.2')
('Processing menu file ', 'menus/menu.3')
('Processing menu file ', 'menus/menu.4')
('Processing menu file ', 'menus/menu.5')
('Processing menu file ', 'menus/menu.6')
('Processing menu file ', 'menus/menu.7')
('Processing menu file ', 'menus/menu.8')
('Processing menu file ', 'menus/menu.9')
('Processing menu file ', 'menus/menu.9a')
('Processing titles file', 'menus/titles.lst')
('Title entered in to list position,', [0, 'Menu System\n'])
('Title entered in to list position,', [1, 'First Screen\n'])
('Title entered in to list position,', [2, 'Second Screen\n'])
('Title entered in to list position,', [3, 'Third Screen\n'])
('Title entered in to list position,', [4, 'Function Handlers\n'])
('Title entered in to list position,', [5, 'Sub Screen 5\n'])
('Title entered in to list position,', [6, 'Sub Screen 6\n'])
('Title entered in to list position,', [7, 'Sub Screen 7\n'])
('Title entered in to list position,', [8, 'Sub Screen 8\n'])
('Title entered in to list position,', [9, 'Sub Screen 9\n'])
('Title entered in to list position,', [10, 'Sub Screen 10\n'])
init my menu func
('Processing functions file', 'menus/functions.lst')
('creating dictionary object with key ', ['myFunction1', ['myFunction1', 'myFunction1', 'My Function 1']])
('self.functions =', {'myFunction1': ('myFunction1', 'My Function 1')})
('creating dictionary object with key ', ['myFunction2', ['myFunction2', 'myFunction2', 'My Function 2']])
('self.functions =', {'myFunction1': ('myFunction1', 'My Function 1'), 'myFunction2': ('myFunction2', 'My Function 2')})
Registering functions
('Function handler registered:', 'My Function 1')
('Function handler registered:', 'My Function 2')
InputGetter class initialised
Drawing title

Hope this helps.
Many thanks.            
jpuk commented 6 years ago

Thank you.

Looks like the functions are registering correctly.

I'm looking at line 26 in myClasses.py and wondering if that shouldn't be commented out?

Sorry for the back and forth, wish I could test this here.

What happens if you remove the comment from that line.

self.functionHandlersDictionary = functionHandlersDictionary

fujiman3 commented 6 years ago

Commented that line out but still get the same error message :-( Unbound method myFunction1() .........

jpuk commented 6 years ago

Argh ok.

Thanks for trying that.

I'll see if I can dig the pi out later in the week and give it a run on that to see if I can work out what's going on.

fujiman3 commented 6 years ago

Thank you, I really appreciate your efforts on this. When I finally publish my project online (hackaday and instructables) I will ensure that all acknowledgements for the menu system go to you.

On Tue, 9 Oct 2018, 10:44 John Porter, notifications@github.com wrote:

Argh ok.

Thanks for trying that.

I'll see if I can dig the pi out later in the week and give it a run on that to see if I can work out what's going on.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jpuk/rpi-128x64-oled-menusystem/issues/1#issuecomment-428129338, or mute the thread https://github.com/notifications/unsubscribe-auth/Ap5k0ym2aRYjUmwZ0DLKhqa0-0uaXAyDks5ujHAAgaJpZM4XMaQ0 .