Skip to content

Commit b35617a

Browse files
add a disable ocr build option
1 parent 5df53c2 commit b35617a

File tree

6 files changed

+10
-4
lines changed

6 files changed

+10
-4
lines changed

data/ui/image_stack.blp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ template $GradiaImageStack: Adw.Bin {
100100
Gtk.Revealer ocr_revealer {
101101
transition-type: slide_right;
102102
transition-duration: 300;
103+
reveal-child: false;
103104
Gtk.Button ocr_button {
104105
icon-name: "scanner-symbolic";
105106
tooltip-text: _("Text Extraction");

data/ui/preferences_window.blp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ template $GradiaPreferencesWindow : Adw.PreferencesDialog {
9797
}
9898
Adw.PreferencesGroup {
9999
title: _("Text Extraction");
100+
visible: bind template.ocr_enabled;
100101
Adw.ActionRow {
101102
title: _("_Language Models");
102103
use-underline: true;

gradia/backend/ocr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from pathlib import Path
2626
from gradia.backend.logger import Logger
2727
from gradia.backend.settings import Settings
28-
from gradia.constants import app_id
28+
from gradia.constants import app_id, ocr_enabled
2929
from gradia.constants import ocr_tesseract_cmd, ocr_original_tessdata
3030

3131

@@ -79,7 +79,7 @@ def _update_ocr_action_state(self):
7979
available = Path(ocr_tesseract_cmd).exists() and len(self.get_installed_models()) > 0
8080
ocr_action = self.window.lookup_action("ocr")
8181
if ocr_action and hasattr(ocr_action, 'set_state'):
82-
ocr_action.set_state(GLib.Variant.new_boolean(available))
82+
ocr_action.set_state(GLib.Variant.new_boolean(available and ocr_enabled.lower() == 'true'))
8383

8484
def get_current_model(self):
8585
return self.settings.trained_data

gradia/constants.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ build_type = '@BUILD_TYPE@'
2828
project_url = '@PROJECT_URL@'
2929
bugtracker_url = '@BUGTRACKER_URL@'
3030
help_url = '@HELP_URL@'
31-
#translate_url = '@TRANSLATE_URL@'
31+
#translate_url = '@TRANSLATE_URL@'
3232

3333
# OCR paths
34+
ocr_enabled = '@ENABLE_OCR@'
3435
ocr_tesseract_cmd = '@OCR_TESSERACT_CMD@'
3536
ocr_original_tessdata = '@OCR_ORIGINAL_TESSDATA_DIR@'

meson.build

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ endif
6565
OCR_TESSERACT_CMD = '/app/bin/tesseract'
6666
OCR_ORIGINAL_TESSDATA_DIR = '/app/share/tessdata'
6767

68+
enable_ocr = get_option('enable-ocr')
69+
6870
# Install configuration data
6971
conf = configuration_data()
7072
conf.set('APP_ID', APPLICATION_ID)
@@ -78,7 +80,7 @@ conf.set('BUILD_TYPE', get_option('buildtype'))
7880
conf.set('SCHEMAS_DIR', PKGDATA_DIR)
7981
conf.set('SOURCE_DIR', meson.current_source_dir())
8082
conf.set('BUILD_DIR', meson.current_build_dir())
81-
83+
conf.set('ENABLE_OCR', enable_ocr)
8284
conf.set('OCR_TESSERACT_CMD', OCR_TESSERACT_CMD)
8385
conf.set('OCR_ORIGINAL_TESSDATA_DIR', OCR_ORIGINAL_TESSDATA_DIR)
8486

meson.options

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
option('enable-ocr', type: 'boolean', value: true, description: 'Enable OCR functionality')

0 commit comments

Comments
 (0)