Use an absolute path instead. load_view will also take a full path, either an abspath or a relative path relative to the current directory.
Here was a method I used in editmenu, which needed to work when run from the action menu, from the editor, or from Tabs.py as an import.
In particular, note the pyui line.
You might initially be tempted to use __file__ to find the pathname, but this doesn't work when running from the editor, while inspect.currentframe does work.
class editmenuclass(ui.View):
_lastinstance=None
def did_load(self):
# ..... setting up button actions went here
type(self)._lastinstance=self # only want one instance, can skip loading if it exists
@classmethod
def load(cls):
import os, inspect
pyui= os.path.abspath(inspect.getfile(inspect.currentframe()))+'ui'
if cls._lastinstance is None:
cls._lastinstance = ui.load_view(pyui)
return cls._lastinstance
Of key interest will be the pyui= line above, which assumes that you are loading the pyui that corresponds with the script name. If you have other pyui's, you would split out the path to get your base folder.
Note my pyui specifies the custom class, such that load_view returns an instance of editmenuclass. In this case only one instance of editmenuclass ever made sense, so to run my class I'd use:
editmenu = editmenuclass.load()
to give me either the existing instance (if one has been created before), or load the view.