On Mon, Apr 17, 2017 at 04:39:14PM +0300, Eva Star wrote:
> On 04/17/2017 03:11 AM, Unman wrote:
>
> >I've done some manager hacking myself - some of it now incorporated in
> >release.
> >If you dont want to build a package then you can simply start hacking in
> >/usr/lib64/python2.7/site-packages/qubesmanager.
> >(Back this up first, of course.)
> >
> >Beside the ui elements in ui_mainwindow the slots are in main.py. If
> >you're going to hack these remember to remove the compiled files.
> >I'd recommend using xterm, as it's in all the templates afaik.
> >
>
> Unfortunately main.py contain only functions.
> UI elements located not at qubesmanager dir. They are compiled? How?
> Need to modify this file :
> https://github.com/QubesOS/qubes-manager/blob/master/mainwindow.ui
>
>
>
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
--
You received this message because you are subscribed to the Google Groups
"qubes-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/qubes-users/20170417221329.GA14947%40thirdeyesecurity.org.
For more options, visit https://groups.google.com/d/optout.