5
5
6
6
from albert import *
7
7
8
- md_iid = '1 .0'
9
- md_version = "1.4 "
8
+ md_iid = '2 .0'
9
+ md_version = "1.5 "
10
10
md_name = "VirtualBox"
11
11
md_description = "Manage your VirtualBox machines"
12
12
md_license = "BSD-3"
@@ -23,74 +23,75 @@ def startVm(vm):
23
23
except Exception as e :
24
24
warning (str (e ))
25
25
26
+
26
27
def acpiPowerVm (vm ):
27
28
with vm .create_session (LockType .shared ) as session :
28
29
session .console .power_button ()
29
30
31
+
30
32
def stopVm (vm ):
31
33
with vm .create_session (LockType .shared ) as session :
32
34
session .console .power_down ()
33
35
36
+
34
37
def saveVm (vm ):
35
38
with vm .create_session (LockType .shared ) as session :
36
39
session .machine .save_state ()
37
40
41
+
38
42
def discardSavedVm (vm ):
39
43
with vm .create_session (LockType .shared ) as session :
40
- session .machine .discard_save_state (True );
44
+ session .machine .discard_save_state (True )
45
+
41
46
42
47
def resumeVm (vm ):
43
48
with vm .create_session (LockType .shared ) as session :
44
49
session .console .resume ()
45
50
51
+
46
52
def pauseVm (vm ):
47
53
with vm .create_session (LockType .shared ) as session :
48
54
session .console .pause ()
49
55
50
- class Plugin (TriggerQueryHandler ):
51
- iconUrls = ["xdg:virtualbox" , ":unknown" ]
52
-
53
- def id (self ):
54
- return md_id
55
-
56
- def name (self ):
57
- return md_name
58
-
59
- def description (self ):
60
- return md_description
61
56
62
- def synopsis (self ):
63
- return "<machine name>"
57
+ class Plugin (PluginInstance , TriggerQueryHandler ):
64
58
65
- def defaultTrigger (self ):
66
- return "vbox "
59
+ def __init__ (self ):
60
+ TriggerQueryHandler .__init__ (self ,
61
+ id = md_id ,
62
+ name = md_name ,
63
+ description = md_description ,
64
+ synopsis = '<machine name>' ,
65
+ defaultTrigger = 'vbox ' )
66
+ PluginInstance .__init__ (self , extensions = [self ])
67
+ self .iconUrls = ["xdg:virtualbox" , ":unknown" ]
67
68
68
69
def handleTriggerQuery (self , query ):
69
70
items = []
70
71
pattern = query .string .strip ().lower ()
71
72
try :
72
73
for vm in filter (lambda vm : pattern in vm .name .lower (), virtualbox .VirtualBox ().machines ):
73
74
actions = []
74
- if vm .state == MachineState .powered_off or vm .state == MachineState .aborted : #1 #4
75
+ if vm .state == MachineState .powered_off or vm .state == MachineState .aborted : # 1 # 4
75
76
actions .append (Action ("startvm" , "Start virtual machine" , lambda vm = vm : startVm (vm )))
76
- if vm .state == MachineState .saved : #2
77
+ if vm .state == MachineState .saved : # 2
77
78
actions .append (Action ("restorevm" , "Start saved virtual machine" , lambda vm = vm : startVm (vm )))
78
79
actions .append (Action ("discardvm" , "Discard saved state" , lambda vm = vm : discardSavedVm (vm )))
79
- if vm .state == MachineState .running : #5
80
+ if vm .state == MachineState .running : # 5
80
81
actions .append (Action ("savevm" , "Save virtual machine" , lambda vm = vm : saveVm (vm )))
81
82
actions .append (Action ("poweroffvm" , "Power off via ACPI event (Power button)" , lambda vm = vm : acpiPowerVm (vm )))
82
83
actions .append (Action ("stopvm" , "Turn off virtual machine" , lambda vm = vm : stopVm (vm )))
83
84
actions .append (Action ("pausevm" , "Pause virtual machine" , lambda vm = vm : pauseVm (vm )))
84
- if vm .state == MachineState .paused : #6
85
+ if vm .state == MachineState .paused : # 6
85
86
actions .append (Action ("resumevm" , "Resume virtual machine" , lambda vm = vm : resumeVm (vm )))
86
87
87
88
items .append (
88
- Item (
89
+ StandardItem (
89
90
id = vm .__uuid__ ,
90
91
text = vm .name ,
91
92
subtext = "{vm.state}" .format (vm = vm ),
92
- completion = vm .name ,
93
- icon = self .iconUrls ,
93
+ inputActionText = vm .name ,
94
+ iconUrls = self .iconUrls ,
94
95
actions = actions
95
96
)
96
97
)
0 commit comments