def __init__(self): GObject.GObject.__init__(self) self.name = "JAMediaVideoDesktop" self.pipeline = False self.bus = False self.info = False #self.resolucion = "video/x-raw-yuv,width=640,height=480" # 800x600 no menor a 640x480 self.audio_enabled = True self.actualizador = False self.file_path = False self.ximagesrc = False self.videoconvert = False self.videoscale = False self.video_capsfilter = False self.theoraenc = False self.gconfaudiosrc = False self.audiorate = False self.audio_capsfilter = False self.audioconvert = False self.vorbisenc = False self.hilovideomuxor = False self.hiloaudiomuxor = False self.oggmux = False self.filesink = False self.screen = GdkX11.X11Screen() self.x = 0 self.y = 0 self.width = int(self.screen.width()) self.height = int(self.screen.height())
def get_pixels(centimetros): """ Recibe un tamaño centimetros y devuelve el tamaño en pixels que le corresponde, según tamaño del monitor que se está utilizando. # 1 px = 0.026458333 cm # 1 Pixel = 0.03 Centimetros = 0.01 Pulgadas. """ screen = GdkX11.X11Screen() res_w = screen.width() res_h = screen.height() mm_w = screen.width_mm() mm_h = screen.height_mm() ancho = int(float(res_w) / float(mm_w) * 10.0 * centimetros) alto = int(float(res_h) / float(mm_h) * 10.0 * centimetros) return int(min([ancho, alto]))
import os.path import pkgutil from unittest import TestCase, TestSuite from gi.repository import Gdk, GdkX11 fake_x11_screen = GdkX11.X11Screen() Gdk.Screen.get_default = lambda: fake_x11_screen class TestImports(TestCase): def __init__(self, mod_name): name = f"test_{mod_name.replace('.', '_')}_import" setattr(self, name, lambda: __import__(mod_name)) super().__init__(name) def load_tests(*_args): test_cases = TestSuite() home = os.path.dirname(os.path.dirname(__file__)) for package in pkgutil.walk_packages([f"{home}/blueman"], "blueman."): test_cases.addTest(TestImports(package.name)) assert test_cases.countTestCases() > 0 return test_cases
def set_pipeline(self): """ Crea el pipe para grabar desde x y autoaudio. """ if self.pipeline: del (self.pipeline) self.pipeline = Gst.Pipeline() screen = GdkX11.X11Screen() width = int(screen.width()) height = int(screen.height()) # >>> Video print "Grabando un Escritorio de:", "%sx%s" % (width, height) ximagesrc = Gst.ElementFactory.make('ximagesrc', "ximagesrc") #self.ximagesrc.set_property("screen-num", self.screen.get_screen_number()) #self.ximagesrc.set_property('use-damage', False) ximagesrc.set_property('startx', 0) ximagesrc.set_property('endx', 200) #ximagesrc.set_property('endx', width) ximagesrc.set_property('starty', 0) ximagesrc.set_property('endy', 100) #ximagesrc.set_property('endy', height) que_encode_video = Gst.ElementFactory.make("queue", "que_encode_video") ''' que_encode_video.set_property('max-size-buffers', 1000) que_encode_video.set_property('max-size-bytes', 0) que_encode_video.set_property('max-size-time', 0)''' videoscale = Gst.ElementFactory.make('videoscale', 'videoscale') video_capsfilter = Gst.ElementFactory.make("capsfilter", "scalecaps") scalecaps = Gst.Caps() scalecaps.from_string("video/x-raw-yuv,width=640,height=480") video_capsfilter.set_property("caps", scalecaps) videoconvert = Gst.ElementFactory.make('videoconvert', 'videoconvert') theoraenc = Gst.ElementFactory.make('theoraenc', 'theoraenc') ''' theoraenc.set_property("bitrate", 1024) # kbps compresion + resolucion = calidad theoraenc.set_property('keyframe-freq', 15) theoraenc.set_property('cap-overflow', False) theoraenc.set_property('speed-level', 0) theoraenc.set_property('cap-underflow', True) theoraenc.set_property('vp3-compatible', True)''' que_video_mux = Gst.ElementFactory.make('queue', "que_video_mux") ''' que_video_mux.set_property('max-size-buffers', 12000) que_video_mux.set_property('max-size-bytes', 0) que_video_mux.set_property('max-size-time', 0)''' videobin = Gst.Bin() videobin.add(ximagesrc) videobin.add(videoconvert) videobin.add(videoscale) videobin.add(video_capsfilter) #videobin.add(que_encode_video) videobin.add(theoraenc) #videobin.add(que_video_mux) ximagesrc.link(videoconvert) videoconvert.link(videoscale) videoscale.link(video_capsfilter) #video_capsfilter.link(que_encode_video) video_capsfilter.link(theoraenc) #theoraenc.link(que_video_mux) #pad = que_encode_video.get_static_pad("sink") #videobin.add_pad(Gst.GhostPad.new("sink", pad)) pad = theoraenc.get_static_pad("src") videobin.add_pad(Gst.GhostPad.new("src", pad)) print "\tvideobin:" print videobin.children # <<< Video # >>> Audio autoaudiosrc = Gst.ElementFactory.make('autoaudiosrc', "autoaudiosrc") audioconvert = Gst.ElementFactory.make('audioconvert', "audioconvert") vorbisenc = Gst.ElementFactory.make('vorbisenc', "vorbisenc") que_audio_mux = Gst.ElementFactory.make('queue', "que_audio_mux") ''' que_audio_mux.set_property('max-size-buffers', 5000) que_audio_mux.set_property('max-size-bytes', 0) que_audio_mux.set_property('max-size-time', 0)''' audiobin = Gst.Bin() audiobin.add(autoaudiosrc) audiobin.add(audioconvert) audiobin.add(vorbisenc) audiobin.add(que_audio_mux) autoaudiosrc.link(audioconvert) audioconvert.link(vorbisenc) vorbisenc.link(que_audio_mux) pad = que_audio_mux.get_static_pad("src") audiobin.add_pad(Gst.GhostPad.new("src", pad)) print "\taudiobin:" print audiobin.children # <<< Audio oggmux = Gst.ElementFactory.make('oggmux', "oggmux") oggmux.set_property("skeleton", True) sink = Gst.ElementFactory.make('filesink', "archivo") sink.set_property("location", self.file_path) self.pipeline.add(videobin) self.pipeline.add(audiobin) self.pipeline.add(oggmux) self.pipeline.add(sink) audiobin.link(oggmux) videobin.link(oggmux) oggmux.link(sink) print "\tself.pipeline:" print self.pipeline.children ''' fakesink = Gst.ElementFactory.make('fakesink', "fakesink") self.pipeline.add(videobin) self.pipeline.add(fakesink) videobin.link(fakesink)''' self.bus = self.pipeline.get_bus() self.bus.enable_sync_message_emission() self.bus.add_signal_watch() self.bus.connect("sync-message::element", self.on_sync_message) self.bus.connect("message", self.on_message)
def __init__(self, handle): super(RulerActivity, self).__init__(handle) self.button_dict = {} self.callback_dict = {} self._ready = False font = 'helvetica 12' font_bold = 'helvetica bold 12' # # We need a canvas # self._canvas = MyCanvas() self.set_canvas(self._canvas) self._canvas.show() screen = GdkX11.X11Screen() width = screen.width() height = screen.height() - GRID_CELL_SIZE dpi, self.known_dpi = calc_dpi() self._canvas.set_dpi(dpi) # Create instances of our graphics self._r = show_rulers.ScreenOfRulers(font, font_bold, width, height) self._gcm = show_grids.ScreenGrid_cm(font, font_bold, width, height) self._gmm = show_grids.ScreenGrid_mm(font, font_bold, width, height) self._a90 = show_angles.Angles90(font, font_bold, width, height) self._a360 = show_angles.Angles360(font, font_bold, width, height) self._c = show_checkers.ScreenOfCircles(font, font_bold, width, height) # start with a ruler self._current = self._r self._canvas.add_a_ruler(self._current) # other settings self._grids_mode = "cm" self._angles_mode = "90" # # We need some toolbars # self.max_participants = 1 toolbar_box = ToolbarBox() # Buttons added to the Activity toolbar activity_button = ActivityToolbarButton(self) toolbar_box.toolbar.insert(activity_button, 0) activity_button.show() self.rulers = radio_factory('ruler', toolbar_box.toolbar, self._rulers_cb, tooltip=_('Ruler'), group=None) self.grids = radio_factory('grid-a', toolbar_box.toolbar, self._grids_cb, tooltip=_('Grid'), group=self.rulers) self.angles = radio_factory('angles-90', toolbar_box.toolbar, self._angles_cb, tooltip=_('Angles'), group=self.rulers) self.checker = radio_factory('checker', toolbar_box.toolbar, self._checker_cb, tooltip=_('Checker'), group=self.rulers) self.wrapper = Gtk.ToolItem() self.wrapper2 = Gtk.ToolItem() self.wrapper3 = Gtk.ToolItem() self.custom_unit_entry = Gtk.Entry() self.txt1 = Gtk.Label() self.txt1.set_text(_('1 custom unit equals ')) self.txt2 = Gtk.Label() # TRANS: mm is for Milli Meters self.txt2.set_text(_(' mm.')) self.wrapper.add(self.txt1) self.wrapper2.add(self.custom_unit_entry) self.wrapper3.add(self.txt2) self.wrapper.show_all() self.wrapper2.show_all() self.wrapper3.show_all() separator = Gtk.SeparatorToolItem() separator.props.draw = True separator.set_expand(False) separator.show() toolbar_box.toolbar.insert(separator, -1) custom_units_toolbox = ToolbarBox() custom_units_toolbox.toolbar.insert(self.wrapper, -1) custom_units_toolbox.toolbar.insert(self.wrapper2, -1) custom_units_toolbox.toolbar.insert(self.wrapper3, -1) custom_units_toolbox.show() self.custom_units_button = ToolbarButton(icon_name='view-source', page=custom_units_toolbox) toolbar_box.toolbar.insert(self.custom_units_button, -1) self.custom_unit_entry.connect('changed', self.custom_unit_change_cb) self.custom_units_button.show() if not self.known_dpi: separator = Gtk.SeparatorToolItem() separator.show() toolbar_box.toolbar.insert(separator, -1) dpi = self._canvas.get_dpi() self._dpi_spin_adj = Gtk.Adjustment(dpi, 72, 200, 2, 32, 0) self._dpi_spin = Gtk.SpinButton(self._dpi_spin_adj, 0, 0) self._dpi_spin_id = self._dpi_spin.connect('value-changed', self._dpi_spin_cb) self._dpi_spin.set_numeric(True) self._dpi_spin.show() self.tool_item_dpi = Gtk.ToolItem() self.tool_item_dpi.add(self._dpi_spin) toolbar_box.toolbar.insert(self.tool_item_dpi, -1) self.tool_item_dpi.show() separator = Gtk.SeparatorToolItem() separator.props.draw = False separator.set_expand(True) separator.show() toolbar_box.toolbar.insert(separator, -1) # The ever-present Stop Button stop_button = StopButton(self) stop_button.props.accelerator = '<Ctrl>Q' toolbar_box.toolbar.insert(stop_button, -1) stop_button.show() self.set_toolbar_box(toolbar_box) toolbar_box.show() self.show_all() # Restore state if previously saved self._ready = True if 'ruler' in self.metadata and \ self.metadata['ruler'] in self.button_dict: _logger.debug('restoring %s', self.metadata['ruler']) self.button_dict[self.metadata['ruler']].set_active(True) self.callback_dict[self.metadata['ruler']] else: self._rulers_cb() self.rulers.set_active(True) if 'custom_unit' in self.metadata: self.custom_unit_entry.set_text(str(self.metadata['custom_unit'])) else: # set the default self.custom_unit_entry.set_text("25.4")