Do not show stock browser if no faces directory. Show error message if camera fails to init.
This commit is contained in:
parent
a418fb39b2
commit
125962a7da
|
@ -39,19 +39,24 @@ class CameraMugshotDialog(CameraDialog):
|
||||||
# Pack the video widget into the dialog.
|
# Pack the video widget into the dialog.
|
||||||
vbox = builder.get_object('camera_box')
|
vbox = builder.get_object('camera_box')
|
||||||
self.video_window = Gtk.DrawingArea()
|
self.video_window = Gtk.DrawingArea()
|
||||||
self.draw_handler = self.video_window.connect('draw', self.on_draw)
|
|
||||||
self.video_window.connect("realize",self.__on_video_window_realized)
|
self.video_window.connect("realize",self.__on_video_window_realized)
|
||||||
vbox.pack_start(self.video_window, True, True, 0)
|
vbox.pack_start(self.video_window, True, True, 0)
|
||||||
self.video_window.show()
|
self.video_window.show()
|
||||||
|
|
||||||
# Prepare the camerabin element.
|
# Prepare the camerabin element.
|
||||||
self.camerabin = Gst.ElementFactory.make("camerabin", "camera-source")
|
self.camerabin = Gst.ElementFactory.make("camerabin", "camera-source")
|
||||||
bus = self.camerabin.get_bus()
|
if self.camerabin:
|
||||||
bus.add_signal_watch()
|
bus = self.camerabin.get_bus()
|
||||||
bus.enable_sync_message_emission()
|
bus.add_signal_watch()
|
||||||
bus.connect("message", self._on_message)
|
bus.enable_sync_message_emission()
|
||||||
bus.connect("sync-message::element", self._on_sync_message)
|
bus.connect("message", self._on_message)
|
||||||
self.realized = False
|
bus.connect("sync-message::element", self._on_sync_message)
|
||||||
|
self.realized = False
|
||||||
|
self.draw_handler = self.video_window.connect('draw', self.on_draw)
|
||||||
|
# If the camera fails to load, show an error on the screen.
|
||||||
|
else:
|
||||||
|
self.draw_handler = self.video_window.connect('draw', self.on_failed_draw)
|
||||||
|
self.realized = True
|
||||||
|
|
||||||
# Essential widgets
|
# Essential widgets
|
||||||
self.record_button = builder.get_object('camera_record')
|
self.record_button = builder.get_object('camera_record')
|
||||||
|
@ -62,6 +67,34 @@ class CameraMugshotDialog(CameraDialog):
|
||||||
|
|
||||||
self.show_all()
|
self.show_all()
|
||||||
|
|
||||||
|
def on_failed_draw(self, widget, ctx):
|
||||||
|
"""Display a message that the camera failed to load."""
|
||||||
|
# Get the height and width of the drawing area.
|
||||||
|
alloc = widget.get_allocation()
|
||||||
|
height = alloc.height
|
||||||
|
width = alloc.width
|
||||||
|
|
||||||
|
# Make the background black.
|
||||||
|
ctx.set_source_rgb(0,0,0)
|
||||||
|
ctx.paint()
|
||||||
|
|
||||||
|
# Set the font details.
|
||||||
|
font_size = 20
|
||||||
|
font_color = (255,255,255)
|
||||||
|
font_name = "Sans"
|
||||||
|
|
||||||
|
# Draw the message to the drawing area.
|
||||||
|
ctx.set_source_rgb(*font_color)
|
||||||
|
ctx.select_font_face(font_name, cairo.FONT_SLANT_NORMAL,
|
||||||
|
cairo.FONT_WEIGHT_NORMAL)
|
||||||
|
ctx.set_font_size(font_size)
|
||||||
|
ctx.move_to(10,(height-font_size)/2)
|
||||||
|
# Translators: This string is split for use with cairo. The complete string is "Sorry, but your camera failed to initialize."
|
||||||
|
ctx.show_text(_("Sorry, but your camera"))
|
||||||
|
ctx.move_to(10,(height-font_size)/2+font_size)
|
||||||
|
# Translators: This string is split for use with cairo. The complete string is "Sorry, but your camera failed to initialize."
|
||||||
|
ctx.show_text(_("failed to initialize."))
|
||||||
|
|
||||||
def on_draw(self, widget, ctx):
|
def on_draw(self, widget, ctx):
|
||||||
"""Display a message that the camera is initializing on first draw.
|
"""Display a message that the camera is initializing on first draw.
|
||||||
Afterwards, blank the drawing area to clear the message."""
|
Afterwards, blank the drawing area to clear the message."""
|
||||||
|
@ -103,13 +136,15 @@ class CameraMugshotDialog(CameraDialog):
|
||||||
if not self.realized:
|
if not self.realized:
|
||||||
print _("Cannot display web cam output. Ignoring play command")
|
print _("Cannot display web cam output. Ignoring play command")
|
||||||
else:
|
else:
|
||||||
self.camerabin.set_state(Gst.State.PLAYING)
|
if self.camerabin:
|
||||||
|
self.camerabin.set_state(Gst.State.PLAYING)
|
||||||
|
|
||||||
def pause(self):
|
def pause(self):
|
||||||
"""Pause the camera output. It will cause the image to "freeze".
|
"""Pause the camera output. It will cause the image to "freeze".
|
||||||
Use play() to start the camera playing again. Note that calling pause
|
Use play() to start the camera playing again. Note that calling pause
|
||||||
before play may cause errors on certain camera."""
|
before play may cause errors on certain camera."""
|
||||||
self.camerabin.set_state(Gst.State.PAUSED)
|
if self.camerabin:
|
||||||
|
self.camerabin.set_state(Gst.State.PAUSED)
|
||||||
|
|
||||||
def take_picture(self, filename):
|
def take_picture(self, filename):
|
||||||
"""take_picture - grab a frame from the webcam and save it to
|
"""take_picture - grab a frame from the webcam and save it to
|
||||||
|
|
|
@ -40,6 +40,7 @@ home = os.path.expanduser('~')
|
||||||
libreoffice_prefs = os.path.join(home, '.config', 'libreoffice', '4', 'user',
|
libreoffice_prefs = os.path.join(home, '.config', 'libreoffice', '4', 'user',
|
||||||
'registrymodifications.xcu')
|
'registrymodifications.xcu')
|
||||||
pidgin_prefs = os.path.join(home, '.purple', 'prefs.xml')
|
pidgin_prefs = os.path.join(home, '.purple', 'prefs.xml')
|
||||||
|
faces_dir = '/usr/share/pixmaps/faces/'
|
||||||
|
|
||||||
def which(command):
|
def which(command):
|
||||||
'''Use the system command which to get the absolute path for the given
|
'''Use the system command which to get the absolute path for the given
|
||||||
|
@ -109,6 +110,9 @@ class MugshotWindow(Window):
|
||||||
self.image_menu = builder.get_object('image_menu')
|
self.image_menu = builder.get_object('image_menu')
|
||||||
self.image_menu.attach_to_widget(self.image_button, detach_cb)
|
self.image_menu.attach_to_widget(self.image_button, detach_cb)
|
||||||
self.image_from_camera = builder.get_object('image_from_camera')
|
self.image_from_camera = builder.get_object('image_from_camera')
|
||||||
|
image_from_browse = builder.get_object('image_from_browse')
|
||||||
|
image_from_browse.set_visible( os.path.exists(faces_dir) and \
|
||||||
|
len(os.listdir(faces_dir)) > 0 )
|
||||||
|
|
||||||
# Entry widgets (chfn)
|
# Entry widgets (chfn)
|
||||||
self.first_name_entry = builder.get_object('first_name')
|
self.first_name_entry = builder.get_object('first_name')
|
||||||
|
|
Loading…
Reference in New Issue