-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegrated_gui_backup_june13.py
More file actions
149 lines (128 loc) · 4.6 KB
/
integrated_gui_backup_june13.py
File metadata and controls
149 lines (128 loc) · 4.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
"""
CodedSwitch - Integrated GUI for AI Code Translator with LLM Integration and Premium Features
ENHANCED VERSION with Bug Fixes, Better Error Handling, and Performance Improvements
This module provides a GUI that integrates the chatbot, translator, vulnerability scanner,
and LYRIC LAB into a single, seamless interface powered by the IntegratedTranslatorAI.
"""
import os
import sys
import logging
import argparse
import platform
import tkinter as tk
from tkinter import ttk, messagebox, filedialog
from tkinter.scrolledtext import ScrolledText
import ttkbootstrap as ttk
from ttkbootstrap.constants import *
from ttkbootstrap.dialogs import Messagebox
from ttkbootstrap.scrolled import ScrolledText as TtkScrolledText
from pathlib import Path
from datetime import datetime
from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters import HtmlFormatter
import json
import webbrowser
import numpy as np
import pygame
import threading
import tempfile
import os
from scipy.io import wavfile
import time
import atexit
import re
from concurrent.futures import ThreadPoolExecutor
from typing import Optional, Dict, List, Tuple, Any
import functools
import sys
import io
# Fix for Windows console encoding issues with emojis
if sys.platform == "win32":
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8')
# Optional imports with fallbacks
try:
import librosa
LIBROSA_AVAILABLE = True
except ImportError:
LIBROSA_AVAILABLE = False
# Note: logger not available yet, will log later
# ============================================================================
# CONSTANTS AND CONFIGURATION
# ============================================================================
class Constants:
"""Application constants for better maintainability."""
# GUI Settings
DEFAULT_FONT_SIZE = 10
MIN_FONT_SIZE = 8
MAX_FONT_SIZE = 24
DEFAULT_WINDOW_SIZE = "1200x800"
MIN_WINDOW_SIZE = (800, 600)
# Audio Settings
SAMPLE_RATE = 44100
AUDIO_BUFFER_SIZE = 512
AUDIO_CHANNELS = 2
AUDIO_FORMAT = -16
# File Settings
MAX_CODE_LENGTH = 50000
CONFIG_DIR = "config"
TEMP_FILE_PREFIX = "codedswitch_"
# AI Settings
DEFAULT_MODEL = "gemini-2.0-flash-001"
MAX_RETRIES = 3
TIMEOUT_SECONDS = 30
# Configure logging with better format and handle Unicode
class UnicodeStreamHandler(logging.StreamHandler):
def emit(self, record):
try:
msg = self.format(record)
stream = self.stream
# Replace any characters that can't be encoded with a replacement character
stream.write(msg + self.terminator)
self.flush()
except UnicodeEncodeError:
# If we can't encode the message, try to log a simplified version
try:
stream.write(record.msg.encode('ascii', 'replace').decode('ascii') + '\n')
self.flush()
except:
pass # Give up if we still can't log
# Remove any existing handlers
for handler in logging.root.handlers[:]:
logging.root.removeHandler(handler)
# Configure root logger with our custom handler and file handler
root_logger = logging.getLogger()
root_logger.setLevel(logging.INFO)
# Create formatter
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# Add console handler with our Unicode handler
console_handler = UnicodeStreamHandler()
console_handler.setFormatter(formatter)
root_logger.addHandler(console_handler)
# Add file handler
file_handler = logging.FileHandler('codedswitch.log', encoding='utf-8')
file_handler.setFormatter(formatter)
root_logger.addHandler(file_handler)
# Get logger for this module
logger = logging.getLogger(__name__)
# Add current directory to path
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
if SCRIPT_DIR not in sys.path:
sys.path.insert(0, SCRIPT_DIR)
# Import our modules with better error handling
try:
from security.premium_manager import PremiumManager
from security.vulnerability_scanner import VulnerabilityScanner
from integrated_ai import IntegratedTranslatorAI
except ImportError as e:
logger.warning(f"Failed to import some modules: {e}. Using fallback implementations.")
# Create fallback classes if imports fail
class PremiumManager:
def is_premium(self):
return True
def get_license_info(self):
return {'type': 'premium', 'days_remaining': 30}
class VulnerabilityScanner:
def scan_code(self, code, language):
return []