Skip to content

Commit 8429641

Browse files
authored
Merge pull request #207 from vietanhdev/feature/dark-light-theme
Implement dark/light theme
2 parents a1c10f4 + d2c652b commit 8429641

16 files changed

Lines changed: 27875 additions & 24396 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,4 @@ If you want to contribute to **AnyLabeling**, please read [Contribution Guidelin
143143
- Labeling UI built with ideas and components from [LabelImg](https://github.com/heartexlabs/labelImg), [LabelMe](https://github.com/wkentaro/labelme).
144144
- Auto-labeling with [Segment Anything Models](https://segment-anything.com/), [MobileSAM](https://github.com/ChaoningZhang/MobileSAM).
145145
- Auto-labeling with [YOLOv8](https://github.com/ultralytics/ultralytics).
146+
- Icons from FlatIcon: [DinosoftLabs](https://www.flaticon.com/free-icons/sun "sun icons"), [Freepik](https://www.flaticon.com/free-icons/moon "moon icons"), [Vectoricons](https://www.flaticon.com/free-icons/system "system icons"), [HideMaru](https://www.flaticon.com/free-icons/ungroup "ungroup icons").

anylabeling/app.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from anylabeling.views.labeling.logger import logger
2323
from anylabeling.views.labeling.utils import new_icon
2424
from anylabeling.resources import resources
25+
from anylabeling.styles import AppTheme
2526

2627
__all__ = ["resources"]
2728

@@ -111,6 +112,13 @@ def main():
111112
help="epsilon to find nearest vertex on canvas",
112113
default=argparse.SUPPRESS,
113114
)
115+
# Add theme argument
116+
parser.add_argument(
117+
"--theme",
118+
choices=["system", "light", "dark"],
119+
help="set application theme (default: system)",
120+
default="system",
121+
)
114122
args = parser.parse_args()
115123

116124
logger.setLevel(getattr(logging, args.logger_level.upper()))
@@ -141,6 +149,7 @@ def main():
141149
filename = config_from_args.pop("filename")
142150
output = config_from_args.pop("output")
143151
config_file_or_yaml = config_from_args.pop("config")
152+
theme = config_from_args.pop("theme")
144153
anylabeling_config.current_config_file = config_file_or_yaml
145154
config = get_config(config_file_or_yaml, config_from_args)
146155

@@ -176,6 +185,19 @@ def main():
176185
app = QtWidgets.QApplication(sys.argv)
177186
app.processEvents()
178187

188+
# Apply theme
189+
if theme != "system":
190+
# Override system theme detection
191+
os.environ["DARK_MODE"] = "1" if theme == "dark" else "0"
192+
else:
193+
# Check if theme is in config
194+
config_theme = config.get("theme", "system")
195+
if config_theme != "system":
196+
os.environ["DARK_MODE"] = "1" if config_theme == "dark" else "0"
197+
198+
# Apply our modern theme
199+
AppTheme.apply_theme(app)
200+
179201
app.setApplicationName(__appname__)
180202
app.setWindowIcon(new_icon("icon"))
181203
if loaded_language:

anylabeling/config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ def update_dict(target_dict, new_dict, validate_item=None):
2121
for key, value in new_dict.items():
2222
if validate_item:
2323
validate_item(key, value)
24+
# Special handling for recognized new keys
25+
if key not in target_dict and key in ["theme"]:
26+
target_dict[key] = value
27+
continue
2428
if key not in target_dict:
2529
logger.warning("Skipping unexpected key in config: %s", key)
2630
continue
@@ -59,6 +63,8 @@ def validate_config_item(key, value):
5963
raise ValueError(f"Unexpected value for config key 'shape_color': {value}")
6064
if key == "labels" and value is not None and len(value) != len(set(value)):
6165
raise ValueError(f"Duplicates are detected for config key 'labels': {value}")
66+
if key == "theme" and value not in ["system", "light", "dark"]:
67+
raise ValueError(f"Unexpected value for config key 'theme': {value}")
6268

6369

6470
def get_config(config_file_or_yaml=None, config_from_args=None):

anylabeling/configs/anylabeling_config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
language: en_US
2+
theme: system
23
auto_save: true
34
display_label_popup: true
45
store_data: false
17.7 KB
Loading
128 Bytes
Loading
12.9 KB
Loading
9.05 KB
Loading
2.38 KB
Loading
2.14 KB
Loading

0 commit comments

Comments
 (0)