One global less
This commit is contained in:
19
owocr/run.py
19
owocr/run.py
@@ -143,20 +143,20 @@ class ClipboardThread(threading.Thread):
|
|||||||
count = pasteboard.changeCount()
|
count = pasteboard.changeCount()
|
||||||
else:
|
else:
|
||||||
from PIL import ImageGrab
|
from PIL import ImageGrab
|
||||||
global just_unpaused
|
process_clipboard = False
|
||||||
just_unpaused = True
|
|
||||||
img = None
|
img = None
|
||||||
|
|
||||||
while not terminated:
|
while not terminated:
|
||||||
if paused:
|
if paused:
|
||||||
sleep_time = 0.5
|
sleep_time = 0.5
|
||||||
|
process_clipboard = False
|
||||||
else:
|
else:
|
||||||
sleep_time = self.delay_secs
|
sleep_time = self.delay_secs
|
||||||
if is_macos:
|
if is_macos:
|
||||||
with objc.autorelease_pool():
|
with objc.autorelease_pool():
|
||||||
old_count = count
|
old_count = count
|
||||||
count = pasteboard.changeCount()
|
count = pasteboard.changeCount()
|
||||||
if not just_unpaused and count != old_count:
|
if process_clipboard and count != old_count:
|
||||||
while len(pasteboard.types()) == 0:
|
while len(pasteboard.types()) == 0:
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
if NSPasteboardTypeTIFF in pasteboard.types():
|
if NSPasteboardTypeTIFF in pasteboard.types():
|
||||||
@@ -173,12 +173,12 @@ class ClipboardThread(threading.Thread):
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if ((not just_unpaused) and isinstance(img, Image.Image) and \
|
if (process_clipboard and isinstance(img, Image.Image) and \
|
||||||
(self.ignore_flag or pyperclipfix.paste() != '*ocr_ignore*') and \
|
(self.ignore_flag or pyperclipfix.paste() != '*ocr_ignore*') and \
|
||||||
(not self.are_images_identical(img, old_img))):
|
(not self.are_images_identical(img, old_img))):
|
||||||
image_queue.put((img, False))
|
image_queue.put((img, False))
|
||||||
|
|
||||||
just_unpaused = False
|
process_clipboard = True
|
||||||
|
|
||||||
if not terminated:
|
if not terminated:
|
||||||
time.sleep(sleep_time)
|
time.sleep(sleep_time)
|
||||||
@@ -704,16 +704,10 @@ class AutopauseTimer:
|
|||||||
|
|
||||||
def pause_handler(is_combo=True):
|
def pause_handler(is_combo=True):
|
||||||
global paused
|
global paused
|
||||||
global just_unpaused
|
message = 'Unpaused!' if paused else 'Paused!'
|
||||||
if paused:
|
|
||||||
message = 'Unpaused!'
|
|
||||||
just_unpaused = True
|
|
||||||
else:
|
|
||||||
message = 'Paused!'
|
|
||||||
|
|
||||||
if auto_pause_handler:
|
if auto_pause_handler:
|
||||||
auto_pause_handler.stop()
|
auto_pause_handler.stop()
|
||||||
|
|
||||||
if is_combo:
|
if is_combo:
|
||||||
notifier.send(title='owocr', message=message)
|
notifier.send(title='owocr', message=message)
|
||||||
logger.info(message)
|
logger.info(message)
|
||||||
@@ -731,7 +725,6 @@ def engine_change_handler(user_input='s', is_combo=True):
|
|||||||
engine_index += 1
|
engine_index += 1
|
||||||
elif user_input.lower() != '' and user_input.lower() in engine_keys:
|
elif user_input.lower() != '' and user_input.lower() in engine_keys:
|
||||||
engine_index = engine_keys.index(user_input.lower())
|
engine_index = engine_keys.index(user_input.lower())
|
||||||
|
|
||||||
if engine_index != old_engine_index:
|
if engine_index != old_engine_index:
|
||||||
new_engine_name = engine_instances[engine_index].readable_name
|
new_engine_name = engine_instances[engine_index].readable_name
|
||||||
if is_combo:
|
if is_combo:
|
||||||
|
|||||||
Reference in New Issue
Block a user