glb module
Developers can access global shell and main window from this module.
Shell
- class lys.glb.shell.ExtendShell[source]
Bases:
QObjectExtended shell object that is used for Python Interface in lys.
This object is basically used to realize custom functionarities of lys from plugins.
Any expression can be executed and evaluated by
exec()andeval()functions. Any object can be added byaddObject()ExtendShell is basically singleton object. Developers should access the instance of ExtendShell from
glb.shell()function.Example:
from lys import glb shell = glb.shell() # The global shell instance shell.exec("a=1") # Execute a command print(shell.eval("a")) # 1, Evaluate a expression f = lambda: print("hello") shell.addObject(f, name = "sayHello") # Adding new function in lys Python Interface. sayHello() # hello
- addObject(obj, name=None, printResult=True)[source]
Add an object to shell.
name represents name of object on shell. If None, obj.__name__ and obj.name is used as a name. If both methods are not defined, object is loaded as default name “obj”.
To avoid overlap, name is automatically changed.
- Parameters:
obj (any) – object to be loaded
name (str) – name of object
printResult (bool) – If True, message is printed after loading.
- Retruns:
str: The name of the object added.
Example:
from lys import glb name = glb.shell().addObject("test", name="a") instance = eval(name) # Since the name may be changed from 'a' to avoid conflict. print(instance) # test
- property commandLog
List of command log that is executed by user.
- Returns:
List of commands
- Return type:
list
- property dict
Global dictionary of shell.
This is useful when developers want to access local variables in Python Interface.
It is recommended to use
addObject()to add an object in shell.- Returns:
Global dictionary of shell
- Return type:
dict
- eval(expr, save=False)[source]
Evaluate expression in shell.
- Parameters:
expr (str) – expression to be evaluated
save (bool) – if True, expr is added to command log.
- Returns:
Result
- Return type:
Any
- exec(expr, save=False)[source]
Execute expression in shell.
- Parameters:
expr (str) – expression to be executed
save (bool) – if True, expr is added to command log.
- importAll(module)[source]
Import module
This function import module, i.e. from module import * is called.
If the module has been imported, it is reloaded by importlib.
- Parameters:
module (str) – module to be loaded.
Example:
from lys import glb glb.shell().importAll("time") print(time())
Main Window
- class lys.glb.MainWindow.MainWindow(show=True, restore=False, askClose=False)[source]
Bases:
QMainWindowMain window class gives several methods to customize lys GUI.
Tabs can be customized by
tabWidget()method.Developers can access
lys.widgets.fileView.FileSystemViewbyfileViewproperty.Do not instanciate this class because it is automatically done by lys.
- beforeClosed
beforeClosed(event) signal is emitted when close button of lys is clicked.
Developers can connect any functions/methods to this signal.
If the main window should not be closed, call event.ignore() in the connected functions/methods.
Example:
from lys import glb glb.mainWindow().beforeClosed.connect(lambda event: print("Main window closed."))
- closeAllGraphs(workspace=None)[source]
Close all graphs in the workspace.
- Parameters:
workspace (str) – The name of the workspace to close all graphs. If it is None, present workspace is selected.
- closeEvent(event)[source]
Reimplementation of closeEvent in QMainWindow.closeEvent for realization of beforeClosed and closed signals.
- closed
closed(event) signal is emitted when main window of lys is closed.
Example:
from lys import glb glb.mainWindow().closed.connect(lambda: print("Main window closed."))
- property fileView
Returns
lys.widgets.fileView.FileSystemViewobject in main window.Developers can get selected paths and add new context menu in FileSystemView.
See
lys.widgets.fileView.FileSystemViewfor detail.