Skip to content

Commit

Permalink
Change way to let debug logging show.
Browse files Browse the repository at this point in the history
Drop "-v" option because we cannot modify environment variable. It is not guaranteed to work.
Tell user to set `G_MESSAGES_DEBUG` from outside instead.
  • Loading branch information
hongquan committed Apr 29, 2024
1 parent d61a68a commit e771c54
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
6 changes: 5 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,11 @@ Run from source
python3 -m cobang
Add ``-v`` option to see more detailed log.
To print debug messages, set environment variable ``G_MESSAGES_DEBUG`` to ``cobang``:

.. code-block:: sh
G_MESSAGES_DEBUG=cobang python3 -m cobang
Translation
Expand Down
19 changes: 3 additions & 16 deletions cobang/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,8 @@
CONTROL_MASK = Gdk.ModifierType.CONTROL_MASK

# Some Gstreamer CLI examples
# gst-launch-1.0 v4l2src device=/dev/video0 ! videoconvert ! waylandsink
# gst-launch-1.0 playbin3 uri=v4l2:///dev/video0 video-sink=waylandsink
# Better integration:
# gst-launch-1.0 v4l2src device=/dev/video0 ! videoconvert ! gtksink
# gst-launch-1.0 v4l2src ! videoconvert ! glsinkbin sink=gtkglsink
# gst-launch-1.0 v4l2src device=/dev/video0 ! videoconvert ! gtksink
# gst-launch-1.0 v4l2src ! videoconvert ! glsinkbin sink=gtkglsink


class CoBangApplication(Gtk.Application):
Expand Down Expand Up @@ -84,7 +81,7 @@ class CoBangApplication(Gtk.Application):

def __init__(self, **kwargs):
super().__init__(
application_id=APP_ID, flags=Gio.ApplicationFlags.HANDLES_COMMAND_LINE,
application_id=APP_ID, flags=Gio.ApplicationFlags.DEFAULT_FLAGS,
)
self.add_main_option(
'verbose', ord('v'), GLib.OptionFlags.NONE, GLib.OptionArg.NONE,
Expand Down Expand Up @@ -229,16 +226,6 @@ def do_activate(self):
v4l2_idx = next((n for n, r in enumerate(self.webcam_store) if r[2] == 'v4l2src'), 0)
self.webcam_combobox.set_active(v4l2_idx)

def do_command_line(self, command_line: Gio.ApplicationCommandLine):
options = command_line.get_options_dict().end().unpack()
if options.get('verbose'):
logger.level = logbook.DEBUG
displayed_apps = os.getenv('G_MESSAGES_DEBUG', '').split()
displayed_apps.append(SHORT_NAME)
GLib.setenv('G_MESSAGES_DEBUG', ' '.join(displayed_apps), True)
self.activate()
return 0

def detach_gstreamer_sink_from_window(self):
old_area = self.cont_webcam.get_child()
self.cont_webcam.remove(old_area)
Expand Down

0 comments on commit e771c54

Please sign in to comment.