Take a screenshot when pausing the domain

This commit is contained in:
Daniel P. Berrange 2006-06-16 16:07:19 -04:00
parent 21b7ef51d7
commit 9b6bda983d
4 changed files with 87 additions and 13 deletions

View File

@ -2552,12 +2552,30 @@ Inactive virtual machines</property>
</child>
<child>
<widget class="GtkImage" id="console-screenshot">
<widget class="GtkScrolledWindow" id="scrolledwindow6">
<property name="visible">True</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">GTK_POLICY_ALWAYS</property>
<property name="vscrollbar_policy">GTK_POLICY_ALWAYS</property>
<property name="shadow_type">GTK_SHADOW_NONE</property>
<property name="window_placement">GTK_CORNER_TOP_LEFT</property>
<child>
<widget class="GtkViewport" id="viewport2">
<property name="visible">True</property>
<property name="shadow_type">GTK_SHADOW_NONE</property>
<child>
<widget class="GtkImage" id="console-screenshot">
<property name="visible">True</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
</child>
</widget>
</child>
</widget>
<packing>
<property name="tab_expand">False</property>

View File

@ -2,6 +2,7 @@
import gobject
import gtk.glade
import libvirt
import sys
from vncViewer.vnc import GRFBViewer
@ -41,7 +42,11 @@ class vmmConsole(gobject.GObject):
self.vncViewer = GRFBViewer()
scrolledWin = gtk.ScrolledWindow()
scrolledWin.add_with_viewport(self.vncViewer)
vp = gtk.Viewport()
vp.set_shadow_type(gtk.SHADOW_NONE)
vp.add(self.vncViewer)
scrolledWin.add(vp)
self.window.get_widget("console-pages").set_show_tabs(False)
self.window.get_widget("console-pages").append_page(scrolledWin, gtk.Label("VNC"))
@ -70,9 +75,6 @@ class vmmConsole(gobject.GObject):
self.vncViewer.connect("disconnected", self._vnc_disconnected)
self.try_login()
def show(self):
dialog = self.window.get_widget("vmm-console")
dialog.show_all()
@ -96,17 +98,29 @@ class vmmConsole(gobject.GObject):
protocol, host, port = self.vm.get_console_info()
if protocol != "vnc" or self.vm.get_id() == 0:
if self.vm.get_id() == 0:
pass
#return
print protocol + "://" + host + ":" + str(port)
if protocol != "vnc":
print "Activate inactive"
self.window.get_widget("console-pages").set_curent_page(0)
return
if not(self.vncViewer.is_connected()):
self.vncViewer.connect_to_host(host, port)
if password and self.vncViewer.authenticate(password) == 1:
print "K " + str(self.vncViewer.is_authenticated())
if self.vncViewer.is_authenticated():
print "Activate console"
self.window.get_widget("console-pages").set_current_page(3)
elif password and (self.vncViewer.authenticate(password) == 1):
self.window.get_widget("console-pages").set_current_page(3)
self.vncViewer.activate()
else:
print "activate auth"
self.window.get_widget("console-auth-password").set_text("")
self.window.get_widget("console-pages").set_current_page(2)
@ -154,6 +168,7 @@ class vmmConsole(gobject.GObject):
self.window.get_widget("control-run").set_sensitive(False)
if status in [ libvirt.VIR_DOMAIN_SHUTDOWN, libvirt.VIR_DOMAIN_SHUTOFF ,libvirt.VIR_DOMAIN_CRASHED ]:
print "actoivate inactive"
self.window.get_widget("control-pause").set_sensitive(False)
self.window.get_widget("control-shutdown").set_sensitive(False)
self.window.get_widget("control-terminal").set_sensitive(False)
@ -167,7 +182,27 @@ class vmmConsole(gobject.GObject):
self.window.get_widget("control-pause").set_active(True)
else:
self.window.get_widget("control-pause").set_active(False)
if status in [ libvirt.VIR_DOMAIN_SHUTOFF ,libvirt.VIR_DOMAIN_CRASHED ]:
self.window.get_widget("console-pages").set_current_page(0)
else:
if status == libvirt.VIR_DOMAIN_PAUSED:
screenshot = None
if self.vncViewer.is_authenticated():
screenshot = self.vncViewer.take_screenshot()
if screenshot != None:
gc = screenshot.new_gc()
width, height = screenshot.get_size()
screenshot.draw_line(gc, 0, 0, width, height)
screenshot.draw_line(gc, 0, height, width, 0)
self.window.get_widget("console-screenshot").set_from_pixmap(screenshot, None)
self.window.get_widget("console-pages").set_current_page(1)
else:
self.window.get_widget("console-pages").set_current_page(0)
else:
self.try_login()
except:
print "Bad shit"
self.ignorePause = False
self.ignorePause = False

View File

@ -229,7 +229,7 @@ class vmmDomain(gobject.GObject):
# XXX don't hardcode me! need to really extract info from
# the libvirt XML as & when the display device info gets
# added
return ["vnc", "localhost", 5900 + self.get_id()]
return ["vnc", "localhost", 5901 + self.get_id()]
gobject.type_register(vmmDomain)

View File

@ -48,6 +48,15 @@ class GRFBFrameBuffer(rfb.RFBFrameBuffer, gobject.GObject):
def get_pixmap(self):
return self.pixmap
def clone_pixmap(self):
if self.pixmap == None:
return None
width, height = self.pixmap.get_size()
clone = gtk.gdk.Pixmap(self.canvas.window, width, height)
gc = clone.new_gc()
clone.draw_drawable(gc, self.pixmap, 0, 0, 0, 0, -1, -1)
return clone
def init_screen(self, width, height, name):
self.pixmap = gtk.gdk.Pixmap(self.canvas.window, width, height)
@ -144,7 +153,8 @@ class GRFBViewer(gtk.DrawingArea):
self.fb = GRFBFrameBuffer(self)
self.client = None
self.authenticated = False
self.fb.connect("resize", self.resize_display)
self.fb.connect("invalidate", self.repaint_region)
@ -176,6 +186,7 @@ class GRFBViewer(gtk.DrawingArea):
self.client.connect("disconnected", self._client_disconnected)
self.client.init()
self.authenticated = False
self.emit("connected", host, port)
def _client_disconnected(self, src):
@ -195,7 +206,9 @@ class GRFBViewer(gtk.DrawingArea):
try:
self.client.auth()
except:
print str(sys.exc_info()[0]) + " " + str(sys.exc_info()[1])
return 0
self.authenticated = True
self.emit("authenticated")
return 1
@ -204,6 +217,11 @@ class GRFBViewer(gtk.DrawingArea):
self.client.request_update()
self.emit("activated")
def is_authenticated(self):
if not(self.is_connected()):
return False
return self.authenticated
def is_connected(self):
if self.client == None:
return False
@ -224,6 +242,9 @@ class GRFBViewer(gtk.DrawingArea):
return mask
def take_screenshot(self):
return self.fb.clone_pixmap()
def update_pointer(self, win, event):
x, y, state = event.window.get_pointer()
self.client.update_pointer(self.state_to_mask(state), x, y)