]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blobdiff - music_sampler/helpers.py
Add Unfocused overlay when focus is lost
[perso/Immae/Projets/Python/MusicSampler.git] / music_sampler / helpers.py
index 68c1328998379a9d5f2c1deb61f5174d0359741a..2249746a5a928cf2c416915a0b587c6b10b704d8 100644 (file)
@@ -29,11 +29,11 @@ def register_fonts():
     symbola = find_font("Symbola")
 
     if ubuntu_regular is None:
-        error_print("Font Ubuntu regular could not be found, please install it.")
-        sys.exit()
+        error_print("Font Ubuntu regular could not be found, "
+                "please install it.", exit=True)
     if symbola is None:
-        error_print("Font Symbola could not be found, please install it.")
-        sys.exit()
+        error_print("Font Symbola could not be found, please install it.",
+                exit=True)
     if ubuntu_bold is None:
         warn_print("Font Ubuntu Bold could not be found.")
 
@@ -123,6 +123,10 @@ def parse_args():
             action=ListDevicesAction,
             help="List available sound devices"
             )
+    parser.add_argument("--no-focus-warning",
+            action='store_true',
+            help="Don't show warning when focus is lost"
+            )
     parser.add_argument('--',
             dest="args",
             help="Kivy arguments. All arguments after this are interpreted\
@@ -138,6 +142,7 @@ def parse_args():
     Config.channels = args.channels
     Config.sample_width = args.sample_width
     Config.builtin_mixing = args.builtin_mixing
+    Config.no_focus_warning = args.no_focus_warning
     if args.music_path.endswith("/"):
         Config.music_path = args.music_path
     else:
@@ -180,12 +185,29 @@ def gain(volume, old_volume=None):
                 20 * math.log10(max(volume, 0.1) / max(old_volume, 0.1)),
                 max(volume, 0)]
 
-def debug_print(message, with_trace=False):
+def debug_print(message, with_trace=None):
+    if with_trace is None:
+        with_trace = (Logger.getEffectiveLevel() < logging.WARN)
+    with_trace &= (sys.exc_info()[0] is not None)
+
     Logger.debug('MusicSampler: ' + message, exc_info=with_trace)
 
-def error_print(message, with_trace=False):
-    Logger.error('MusicSampler: ' + message, exc_info=with_trace)
+def error_print(message, exit=False, with_trace=None):
+    if with_trace is None:
+        with_trace = (Logger.getEffectiveLevel() < logging.WARN)
+    with_trace &= (sys.exc_info()[0] is not None)
+
+    # FIXME: handle it correctly when in a thread
+    if exit:
+        Logger.critical('MusicSampler: ' + message, exc_info=with_trace)
+        sys.exit(1)
+    else:
+        Logger.error('MusicSampler: ' + message, exc_info=with_trace)
+
+def warn_print(message, with_trace=None):
+    if with_trace is None:
+        with_trace = (Logger.getEffectiveLevel() < logging.WARN)
+    with_trace &= (sys.exc_info()[0] is not None)
 
-def warn_print(message, with_trace=False):
     Logger.warn('MusicSampler: ' + message, exc_info=with_trace)