Skip to content
Advertisement

Python MWC pattern GUI – Menubar command from controller class

I’m trying to build a tool for data analysis. I expect that this kind of application gets big, so I’m following the MVC pattern to organize it as best as possible.

My results are saved in .csv files, so the goal should be to “import” them into the GUI. I want to open these files using “CTRL + O” as keybinding and of course using the corresponding option in the menubar.

Now to the actual problem: The function which is called when hitting “CTRL + O” is in the Controller class and works as expected, I can open a bunch of files and the list saves each name. But when using the menubar I’m stucked how to implement the “command=” option.

This is my code:

JavaScript

I would really appreciate If some could give me a hint, want I’m doing wrong. Thanks!

Advertisement

Answer

You are trying to call a Controller function from a View Object, but View doesn’t know that Controller has that function. It doesn’t know that Controller exist.

There might be a better way than this, but you can pass a function as a parameter to View’s constructor. By passing the get_open_filename() function as a parameter to View’s constructor you can use that as the command.

NOTE: I called the parameter func so you can see what I’m doing. I’d recommend giving it a better name though.

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement