Eva,
You've actually quoted the part where I tell you where the ui elements
are.
You can make this change directly in dom0 without building a package, by
editing the code in /usr/lib64/python2.7/site-packages/qubesmanager
As I said, main.py contains the slots (functions) and also the signals
that trigger them.
The simplest way to do what you want is to use the "Run command in VM"
structure as a template. You can search "command" and see how that is
implemented, and adapt it for your new purpose.
1. Define the function:
Copy the section defining the slot
(@pyqtSlot(name='on_action_run_command_in_vm_triggered'))
and the static method:
def do_run_command_in_vm(vm, command_to_run, thread_monitor):
You can pretty much just replace "command" with "xterm" throughout the
slot, and simplify because you arent prompting for a command to run:
@pyqtSlot(name='on_action_run_xterm_in_vm_triggered')
def action_run_xterm_in_vm_triggered(self):
vm = self.get_selected_vm()
thread_monitor = ThreadMonitor()
thread = threading.Thread(target=self.do_run_xterm_in_vm, args=(
vm, thread_monitor))
thread.daemon = True
thread.start()
while not thread_monitor.is_finished():
app.processEvents()
time.sleep(0.2)
if not thread_monitor.success:
QMessageBox.warning(None,
self.tr("Error while running xterm"),
unicode(
self.tr("Exception while running xterm:<br>{0}")).format(
thread_monitor.error_msg))
@staticmethod
def do_run_xterm_in_vm(vm, thread_monitor):
try:
vm.run('xterm', verbose=False, autostart=True,
notify_function=lambda lvl, msg: trayIcon.showMessage(
msg, msecs=3000))
except Exception as ex:
thread_monitor.set_error_msg(str(ex))
thread_monitor.set_finished()
2. Enable it when a row is selected.
Go to the table_selection_changed(self) function, and add in the new
function:
(again you can copy the action_run_command_in_vm details).
So in the main body of the function add:
self.action_run_xterm_in_vm.setEnabled(
not vm.last_power_state == "Paused" and vm.qid != 0)
and in the else clause:
self.action_run_xterm_in_vm.setEnabled(False)
3. Create the context menu item:
In __init__ section,
add a line below the line that adds the action_run_command_in_vm:
self.context_menu.addAction(self.action_run_xterm_in_vm)
4.
That's almost it:
But you need to add the new action to the Window. Again, you can look at
how action_run_command_in_vm is managed, and adapt it for your new menu
item. At a minimum you'll want entries in the setup and retranslate
functions.
So you'll want to add:
self.action_run_xterm_in_vm = QtGui.QAction(VmManagerWindow)
self.action_run_xterm_in_vm.setObjectName(_fromUtf8("action_run_xterm_in_vm"))
and
self.action_run_xterm_in_vm.setText(_translate("VmManagerWindow", "&Run xterm in VM", None))
That's pretty much done.
If you want to build a package just edit the files in the manager
directory, and run 'make manager'
The files you want there are qubesmanager/main.py and mainwindow.ui
As I said though, it's much simpler just to hack the source in dom0.
(Again, make sure you have backed up the originals.)
I hope this gives you the general idea - you can add all sorts of
context menus items, (including customizing the action to the VM.)
unman