sqlshell 0.1.6__py3-none-any.whl → 0.1.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of sqlshell might be problematic. Click here for more details.

@@ -0,0 +1,405 @@
1
+ from PyQt6.QtWidgets import QWidget, QLabel, QVBoxLayout
2
+ from PyQt6.QtCore import Qt, QTimer, QPropertyAnimation, QEasingCurve, QPoint, QRect, pyqtProperty
3
+ from PyQt6.QtGui import QPainter, QColor, QFont, QMovie, QPainterPath, QLinearGradient, QPixmap
4
+ import os
5
+
6
+ class AnimatedSplashScreen(QWidget):
7
+ def __init__(self):
8
+ super().__init__()
9
+
10
+ # Initialize properties for animations first
11
+ self._opacity = 0.0
12
+ self._progress = 0.0
13
+ self.next_widget = None
14
+ self.use_fallback = False
15
+
16
+ # Set up the window properties
17
+ self.setWindowFlags(
18
+ Qt.WindowType.WindowStaysOnTopHint |
19
+ Qt.WindowType.FramelessWindowHint |
20
+ Qt.WindowType.SplashScreen
21
+ )
22
+
23
+ # Set widget attributes for proper compositing
24
+ self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground)
25
+ self.setAttribute(Qt.WidgetAttribute.WA_NoSystemBackground)
26
+ self.setAttribute(Qt.WidgetAttribute.WA_TransparentForMouseEvents, False)
27
+
28
+ # Set fixed size
29
+ self.setFixedSize(400, 300)
30
+
31
+ # Center the splash screen on the screen
32
+ screen_geometry = self.screen().geometry()
33
+ self.move(
34
+ (screen_geometry.width() - self.width()) // 2,
35
+ (screen_geometry.height() - self.height()) // 2
36
+ )
37
+
38
+ # Create movie label first (background)
39
+ self.movie_label = QLabel(self)
40
+ self.movie_label.setGeometry(0, 0, self.width(), self.height())
41
+
42
+ # Create overlay for fade effect (between movie and content)
43
+ self.overlay = QLabel(self)
44
+ self.overlay.setStyleSheet("background-color: rgba(0, 0, 0, 0);")
45
+ self.overlay.setGeometry(0, 0, self.width(), self.height())
46
+
47
+ # Create text label for animated text
48
+ self.text_label = QLabel(self)
49
+ self.text_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
50
+ self.text_label.setStyleSheet("color: rgba(255, 255, 255, 0); background: transparent;")
51
+ self.text_label.setGeometry(0, 0, self.width(), self.height())
52
+
53
+ # Create layout
54
+ layout = QVBoxLayout(self)
55
+ layout.setContentsMargins(20, 140, 20, 20) # Increased top margin to accommodate title bar and logo
56
+ layout.setSpacing(10)
57
+
58
+ # Create background container for the subtitle
59
+ self.content_container = QWidget(self)
60
+ self.content_container.setStyleSheet("background: transparent;")
61
+ content_layout = QVBoxLayout(self.content_container)
62
+ content_layout.setContentsMargins(20, 5, 20, 20)
63
+ content_layout.setSpacing(5)
64
+
65
+ # Create subtitle label
66
+ self.subtitle_label = QLabel("Loading...", self.content_container)
67
+ self.subtitle_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
68
+ self.subtitle_label.setStyleSheet("""
69
+ QLabel {
70
+ color: #2C3E50;
71
+ font-size: 16px;
72
+ font-family: 'Segoe UI', Arial, sans-serif;
73
+ background: transparent;
74
+ }
75
+ """)
76
+ content_layout.addWidget(self.subtitle_label)
77
+
78
+ # Add content container to main layout
79
+ layout.addWidget(self.content_container)
80
+
81
+ # Create progress bar (always on top)
82
+ self.progress_bar = QLabel(self)
83
+ self.progress_bar.setFixedHeight(4)
84
+ self.progress_bar.setStyleSheet("background-color: #3498DB; border-radius: 2px;")
85
+ self.progress_bar.move(100, self.height() - 40)
86
+ self.progress_bar.setFixedWidth(0)
87
+
88
+ # Create a top overlay widget that will always be on top
89
+ self.top_overlay = QWidget(self)
90
+ self.top_overlay.setGeometry(0, 0, self.width(), 130) # Covers title and logo area
91
+ self.top_overlay.setStyleSheet("background: transparent;")
92
+
93
+ # Now create the top title and logo elements on the overlay
94
+
95
+ # Create title bar at the very top
96
+ self.title_bar = QLabel(self.top_overlay)
97
+ self.title_bar.setText("SQL Shell") # Set the text
98
+ self.title_bar.setFixedSize(self.width(), 50)
99
+ self.title_bar.move(0, 0)
100
+ self.title_bar.setAlignment(Qt.AlignmentFlag.AlignCenter)
101
+ self.title_bar.setStyleSheet("""
102
+ QLabel {
103
+ color: white;
104
+ font-size: 28px;
105
+ font-weight: bold;
106
+ font-family: 'Segoe UI', Arial, sans-serif;
107
+ background-color: rgba(52, 152, 219, 0.9);
108
+ border-bottom: 2px solid #2980B9;
109
+ border-top-left-radius: 10px;
110
+ border-top-right-radius: 10px;
111
+ }
112
+ """)
113
+
114
+ # Create a dedicated logo container right below the title bar
115
+ self.logo_container = QLabel(self.top_overlay)
116
+ self.logo_container.setFixedSize(self.width(), 80)
117
+ self.logo_container.move(0, 50) # Position right below title bar
118
+ self.logo_container.setAlignment(Qt.AlignmentFlag.AlignCenter)
119
+ self.logo_container.setStyleSheet("background: rgba(255, 255, 255, 0.8); border: 0px;")
120
+
121
+ # Try to load logo directly here
122
+ logo_path = os.path.join(os.path.dirname(__file__), "resources", "logo_medium.png")
123
+ if os.path.exists(logo_path):
124
+ logo_pixmap = QPixmap(logo_path)
125
+ # Scale logo to appropriate size
126
+ scaled_logo = logo_pixmap.scaledToWidth(200, Qt.TransformationMode.SmoothTransformation)
127
+ self.logo_container.setPixmap(scaled_logo)
128
+ print(f"Logo loaded with size: {scaled_logo.width()}x{scaled_logo.height()}")
129
+ print(f"Logo container geometry: {self.logo_container.geometry()}")
130
+ else:
131
+ print(f"Logo not found at path: {logo_path}")
132
+ # Try the small logo as fallback
133
+ logo_path = os.path.join(os.path.dirname(__file__), "resources", "logo_small.png")
134
+ if os.path.exists(logo_path):
135
+ logo_pixmap = QPixmap(logo_path)
136
+ scaled_logo = logo_pixmap.scaledToWidth(150, Qt.TransformationMode.SmoothTransformation)
137
+ self.logo_container.setPixmap(scaled_logo)
138
+ print(f"Fallback logo loaded with size: {scaled_logo.width()}x{scaled_logo.height()}")
139
+ print(f"Logo container geometry: {self.logo_container.geometry()}")
140
+
141
+ print(f"Title bar geometry: {self.title_bar.geometry()}")
142
+ print(f"Title bar text: {self.title_bar.text()}")
143
+ print(f"Top overlay geometry: {self.top_overlay.geometry()}")
144
+
145
+ # Set appropriate z-order of elements
146
+ self.movie_label.lower() # Background at the very back
147
+ self.overlay.raise_() # Overlay above background
148
+ self.text_label.raise_() # Text above overlay
149
+ self.content_container.raise_() # Content above text
150
+ self.progress_bar.raise_() # Progress bar on top
151
+ self.top_overlay.raise_() # Top overlay with title and logo at the very top
152
+
153
+ # Set up the loading animation - do it immediately in init
154
+ self.movie = None # Initialize to None for safety
155
+ self.load_animation()
156
+
157
+ # Set up fade animation
158
+ self.fade_anim = QPropertyAnimation(self, b"opacity")
159
+ self.fade_anim.setDuration(1000)
160
+ self.fade_anim.setStartValue(0.0)
161
+ self.fade_anim.setEndValue(1.0)
162
+ self.fade_anim.setEasingCurve(QEasingCurve.Type.InOutQuad)
163
+
164
+ # Set up progress animation
165
+ self.progress_anim = QPropertyAnimation(self, b"progress")
166
+ self.progress_anim.setDuration(2000)
167
+ self.progress_anim.setStartValue(0.0)
168
+ self.progress_anim.setEndValue(1.0)
169
+ self.progress_anim.setEasingCurve(QEasingCurve.Type.InOutQuad)
170
+
171
+ # Create a dedicated timer to ensure title and logo always stay on top
172
+ self.z_order_timer = QTimer(self)
173
+ self.z_order_timer.timeout.connect(self.ensure_top_elements_visible)
174
+ self.z_order_timer.start(50) # Check every 50ms
175
+
176
+ # Start animations after everything is initialized
177
+ QTimer.singleShot(100, self.start_animations) # Small delay to ensure everything is ready
178
+
179
+ def load_animation(self):
180
+ """Load the splash screen animation"""
181
+ # Check multiple potential paths for the splash screen GIF
182
+ possible_paths = [
183
+ os.path.join(os.path.dirname(__file__), "resources", "splash_screen.gif"),
184
+ os.path.join(os.path.dirname(os.path.dirname(__file__)), "resources", "splash_screen.gif"),
185
+ os.path.join(os.path.dirname(__file__), "splash_screen.gif"),
186
+ os.path.abspath("sqlshell/resources/splash_screen.gif"),
187
+ os.path.abspath("resources/splash_screen.gif")
188
+ ]
189
+
190
+ # Try each possible path
191
+ for path in possible_paths:
192
+ if os.path.exists(path):
193
+ print(f"Loading splash screen animation from: {path}")
194
+ try:
195
+ self.movie = QMovie(path)
196
+ self.movie.setCacheMode(QMovie.CacheMode.CacheAll) # Cache all frames for smoother playback
197
+ self.movie.setScaledSize(self.size())
198
+
199
+ # Connect frameChanged signal to update the label
200
+ self.movie.frameChanged.connect(self.update_frame)
201
+
202
+ # Ensure the movie label is visible but below other elements
203
+ self.movie_label.lower()
204
+ self.movie_label.setStyleSheet("background: transparent;")
205
+
206
+ # Set the movie to the label
207
+ self.movie_label.setMovie(self.movie)
208
+
209
+ # Test if the movie is valid
210
+ if self.movie.isValid():
211
+ print(f"Successfully loaded animation with {self.movie.frameCount()} frames")
212
+ self.use_fallback = False
213
+
214
+ # Create a timer to ensure animation updates
215
+ self.animation_timer = QTimer(self)
216
+ self.animation_timer.timeout.connect(self.update_animation)
217
+ self.animation_timer.start(50) # Update every 50ms
218
+
219
+ # Force our top overlay to be visible
220
+ self.top_overlay.raise_()
221
+
222
+ return
223
+ else:
224
+ print(f"Warning: Animation file at {path} is not valid")
225
+ self.use_fallback = True
226
+ except Exception as e:
227
+ print(f"Error loading animation from {path}: {e}")
228
+
229
+ # If we get here, no valid animation was found
230
+ print("No valid animation found, using fallback static splash screen")
231
+ self.use_fallback = True
232
+
233
+ def update_frame(self):
234
+ """Handle frame changed in the animation"""
235
+ # Make sure the movie label is refreshed and visible
236
+ self.movie_label.update()
237
+ self.movie_label.show()
238
+
239
+ # Always ensure title and logo stay on top
240
+ self.title_bar.raise_()
241
+ self.logo_container.raise_()
242
+
243
+ def update_animation(self):
244
+ """Ensure animation keeps running"""
245
+ if self.movie and not self.use_fallback:
246
+ # Check if movie is running
247
+ if self.movie.state() != QMovie.MovieState.Running:
248
+ self.movie.start()
249
+
250
+ # Force update of the movie label
251
+ self.movie_label.update()
252
+
253
+ # Always ensure title and logo stay on top
254
+ self.title_bar.raise_()
255
+ self.logo_container.raise_()
256
+
257
+ def paintEvent(self, event):
258
+ """Custom paint event to draw a fallback splash screen if needed"""
259
+ if self.use_fallback:
260
+ painter = QPainter(self)
261
+ painter.setRenderHint(QPainter.RenderHint.Antialiasing)
262
+
263
+ # Draw rounded rectangle background
264
+ gradient = QLinearGradient(0, 0, 0, self.height())
265
+ gradient.setColorAt(0, QColor(44, 62, 80)) # Dark blue-gray
266
+ gradient.setColorAt(1, QColor(52, 152, 219)) # Bright blue
267
+
268
+ painter.setBrush(gradient)
269
+ painter.setPen(Qt.PenStyle.NoPen)
270
+ painter.drawRoundedRect(0, 0, self.width(), self.height(), 10, 10)
271
+
272
+ # Draw title bar at the top
273
+ title_rect = QRect(0, 0, self.width(), 50)
274
+ painter.setBrush(QColor(52, 152, 219)) # Bright blue
275
+ painter.drawRect(title_rect)
276
+
277
+ # Draw title text
278
+ painter.setPen(QColor(255, 255, 255))
279
+ font = QFont("Segoe UI", 24)
280
+ font.setBold(True)
281
+ painter.setFont(font)
282
+ painter.drawText(title_rect, Qt.AlignmentFlag.AlignCenter, "SQL Shell")
283
+
284
+ # Try to draw logo
285
+ logo_path = os.path.join(os.path.dirname(__file__), "resources", "logo_small.png")
286
+ if os.path.exists(logo_path):
287
+ logo_pixmap = QPixmap(logo_path)
288
+ scaled_logo = logo_pixmap.scaledToHeight(70, Qt.TransformationMode.SmoothTransformation)
289
+ logo_x = (self.width() - scaled_logo.width()) // 2
290
+ painter.drawPixmap(logo_x, 60, scaled_logo)
291
+
292
+ # Draw progress bar
293
+ if hasattr(self, '_progress'):
294
+ progress_width = int(200 * self._progress)
295
+ progress_rect = QRect(100, self.height() - 40, progress_width, 4)
296
+ painter.setBrush(QColor(26, 188, 156)) # Teal
297
+ painter.drawRoundedRect(progress_rect, 2, 2)
298
+
299
+ super().paintEvent(event)
300
+
301
+ def start_animations(self):
302
+ """Start all animations"""
303
+ # Try to start the movie if we have one
304
+ if self.movie and not self.use_fallback:
305
+ self.movie.start()
306
+
307
+ # Check if movie is running after attempt to start
308
+ if not self.movie.state() == QMovie.MovieState.Running:
309
+ print("Warning: Could not start the animation")
310
+ self.use_fallback = True
311
+ else:
312
+ # Ensure the movie label is visible and updated
313
+ self.movie_label.show()
314
+ self.movie_label.update()
315
+
316
+ self.fade_anim.start()
317
+ self.progress_anim.start()
318
+ self.progress_anim.finished.connect(self._on_animation_finished)
319
+
320
+ @pyqtProperty(float)
321
+ def opacity(self):
322
+ return self._opacity
323
+
324
+ @opacity.setter
325
+ def opacity(self, value):
326
+ self._opacity = value
327
+ # Update opacity of overlay and text
328
+ self.overlay.setStyleSheet(f"background-color: rgba(0, 0, 0, {int(100 * value)});")
329
+ self.text_label.setStyleSheet(f"""
330
+ QLabel {{
331
+ color: rgba(255, 255, 255, {int(255 * value)});
332
+ background: transparent;
333
+ text-shadow: 2px 2px 4px rgba(0, 0, 0, {int(180 * value)}),
334
+ 0px 0px 10px rgba(52, 152, 219, {int(160 * value)});
335
+ }}
336
+ """)
337
+
338
+ @pyqtProperty(float)
339
+ def progress(self):
340
+ return self._progress
341
+
342
+ @progress.setter
343
+ def progress(self, value):
344
+ self._progress = value
345
+ # Update progress bar width
346
+ if hasattr(self, 'progress_bar'):
347
+ self.progress_bar.setFixedWidth(int(200 * value))
348
+ # Force repaint if using fallback
349
+ if self.use_fallback:
350
+ self.update()
351
+
352
+ def ensure_top_elements_visible(self):
353
+ """Ensure title bar and logo container are always on top"""
354
+ self.top_overlay.raise_()
355
+
356
+ def _on_animation_finished(self):
357
+ """Handle animation completion"""
358
+ if self.next_widget:
359
+ QTimer.singleShot(500, self._finish_splash)
360
+
361
+ def _finish_splash(self):
362
+ """Clean up and show the main window"""
363
+ # Stop the animation timer if it exists
364
+ if hasattr(self, 'animation_timer') and self.animation_timer:
365
+ self.animation_timer.stop()
366
+
367
+ # Stop the z-order timer
368
+ if hasattr(self, 'z_order_timer'):
369
+ self.z_order_timer.stop()
370
+
371
+ if self.movie:
372
+ self.movie.stop()
373
+ if self.fade_anim:
374
+ self.fade_anim.stop()
375
+ if self.progress_anim:
376
+ self.progress_anim.stop()
377
+ self.close()
378
+ if self.next_widget:
379
+ self.next_widget.show()
380
+
381
+ def finish(self, widget):
382
+ """Store the widget to show after animation completes"""
383
+ self.next_widget = widget
384
+
385
+ # On Windows, we need to explicitly trigger the finish process
386
+ # instead of waiting for the animation to complete
387
+
388
+ # First forcibly stop all animations
389
+ if hasattr(self, 'animation_timer') and self.animation_timer:
390
+ self.animation_timer.stop()
391
+
392
+ # Stop the z-order timer
393
+ if hasattr(self, 'z_order_timer'):
394
+ self.z_order_timer.stop()
395
+
396
+ if self.movie:
397
+ self.movie.stop()
398
+ if self.fade_anim:
399
+ self.fade_anim.stop()
400
+ if self.progress_anim:
401
+ self.progress_anim.stop()
402
+
403
+ # Close the splash screen and show the main window directly
404
+ # Use a very short timer to allow the event loop to process
405
+ QTimer.singleShot(50, self._finish_splash)
@@ -110,28 +110,9 @@ if __name__ == '__main__':
110
110
  print(f"Number of products: {len(product_df)}")
111
111
 
112
112
  # Print sample queries
113
- print("\nSample SQL queries for joining the data:")
113
+ print("\nSample SQL queries")
114
114
  print("""
115
- -- Join sales with customer data
116
- SELECT s.*, c.FirstName, c.LastName, c.CustomerType
117
- FROM test_data.sample_sales_data s
118
- JOIN test_data.customer_data c ON s.CustomerID = c.CustomerID;
119
-
120
- -- Join sales with product data
121
- SELECT s.*, p.ProductName, p.Category, p.Brand
122
- FROM test_data.sample_sales_data s
123
- JOIN test_data.product_catalog p ON s.ProductID = p.ProductID;
124
-
125
- -- Three-way join with aggregation
126
- SELECT
127
- p.Category,
128
- c.CustomerType,
129
- COUNT(*) as NumOrders,
130
- SUM(s.TotalAmount) as TotalRevenue,
131
- AVG(s.Quantity) as AvgQuantity
132
- FROM test_data.sample_sales_data s
133
- JOIN test_data.customer_data c ON s.CustomerID = c.CustomerID
134
- JOIN test_data.product_catalog p ON s.ProductID = p.ProductID
135
- GROUP BY p.Category, c.CustomerType
136
- ORDER BY p.Category, c.CustomerType;
115
+ select * from product_catalog;
116
+ select * from customer_data;
117
+ select * from sample_sales_data;
137
118
  """)
Binary file
@@ -0,0 +1,123 @@
1
+ from PyQt6.QtCore import Qt, QRegularExpression
2
+ from PyQt6.QtGui import QFont, QColor, QSyntaxHighlighter, QTextCharFormat
3
+
4
+ class SQLSyntaxHighlighter(QSyntaxHighlighter):
5
+ def __init__(self, document):
6
+ super().__init__(document)
7
+ self.highlighting_rules = []
8
+
9
+ # SQL Keywords
10
+ keyword_format = QTextCharFormat()
11
+ keyword_format.setForeground(QColor("#0000FF")) # Blue
12
+ keyword_format.setFontWeight(QFont.Weight.Bold)
13
+ keywords = [
14
+ "\\bSELECT\\b", "\\bFROM\\b", "\\bWHERE\\b", "\\bAND\\b", "\\bOR\\b",
15
+ "\\bINNER\\b", "\\bOUTER\\b", "\\bLEFT\\b", "\\bRIGHT\\b", "\\bJOIN\\b",
16
+ "\\bON\\b", "\\bGROUP\\b", "\\bBY\\b", "\\bHAVING\\b", "\\bORDER\\b",
17
+ "\\bLIMIT\\b", "\\bOFFSET\\b", "\\bUNION\\b", "\\bEXCEPT\\b", "\\bINTERSECT\\b",
18
+ "\\bCREATE\\b", "\\bTABLE\\b", "\\bINDEX\\b", "\\bVIEW\\b", "\\bINSERT\\b",
19
+ "\\bINTO\\b", "\\bVALUES\\b", "\\bUPDATE\\b", "\\bSET\\b", "\\bDELETE\\b",
20
+ "\\bTRUNCATE\\b", "\\bALTER\\b", "\\bADD\\b", "\\bDROP\\b", "\\bCOLUMN\\b",
21
+ "\\bCONSTRAINT\\b", "\\bPRIMARY\\b", "\\bKEY\\b", "\\bFOREIGN\\b", "\\bREFERENCES\\b",
22
+ "\\bUNIQUE\\b", "\\bNOT\\b", "\\bNULL\\b", "\\bIS\\b", "\\bDISTINCT\\b",
23
+ "\\bCASE\\b", "\\bWHEN\\b", "\\bTHEN\\b", "\\bELSE\\b", "\\bEND\\b",
24
+ "\\bAS\\b", "\\bWITH\\b", "\\bBETWEEN\\b", "\\bLIKE\\b", "\\bIN\\b",
25
+ "\\bEXISTS\\b", "\\bALL\\b", "\\bANY\\b", "\\bSOME\\b", "\\bDESC\\b", "\\bASC\\b"
26
+ ]
27
+ for pattern in keywords:
28
+ regex = QRegularExpression(pattern, QRegularExpression.PatternOption.CaseInsensitiveOption)
29
+ self.highlighting_rules.append((regex, keyword_format))
30
+
31
+ # Functions
32
+ function_format = QTextCharFormat()
33
+ function_format.setForeground(QColor("#AA00AA")) # Purple
34
+ functions = [
35
+ "\\bAVG\\b", "\\bCOUNT\\b", "\\bSUM\\b", "\\bMAX\\b", "\\bMIN\\b",
36
+ "\\bCOALESCE\\b", "\\bNVL\\b", "\\bNULLIF\\b", "\\bCAST\\b", "\\bCONVERT\\b",
37
+ "\\bLOWER\\b", "\\bUPPER\\b", "\\bTRIM\\b", "\\bLTRIM\\b", "\\bRTRIM\\b",
38
+ "\\bLENGTH\\b", "\\bSUBSTRING\\b", "\\bREPLACE\\b", "\\bCONCAT\\b",
39
+ "\\bROUND\\b", "\\bFLOOR\\b", "\\bCEIL\\b", "\\bABS\\b", "\\bMOD\\b",
40
+ "\\bCURRENT_DATE\\b", "\\bCURRENT_TIME\\b", "\\bCURRENT_TIMESTAMP\\b",
41
+ "\\bEXTRACT\\b", "\\bDATE_PART\\b", "\\bTO_CHAR\\b", "\\bTO_DATE\\b"
42
+ ]
43
+ for pattern in functions:
44
+ regex = QRegularExpression(pattern, QRegularExpression.PatternOption.CaseInsensitiveOption)
45
+ self.highlighting_rules.append((regex, function_format))
46
+
47
+ # Numbers
48
+ number_format = QTextCharFormat()
49
+ number_format.setForeground(QColor("#009900")) # Green
50
+ self.highlighting_rules.append((
51
+ QRegularExpression("\\b[0-9]+\\b"),
52
+ number_format
53
+ ))
54
+
55
+ # Single-line string literals
56
+ string_format = QTextCharFormat()
57
+ string_format.setForeground(QColor("#CC6600")) # Orange/Brown
58
+ self.highlighting_rules.append((
59
+ QRegularExpression("'[^']*'"),
60
+ string_format
61
+ ))
62
+ self.highlighting_rules.append((
63
+ QRegularExpression("\"[^\"]*\""),
64
+ string_format
65
+ ))
66
+
67
+ # Comments
68
+ comment_format = QTextCharFormat()
69
+ comment_format.setForeground(QColor("#777777")) # Gray
70
+ comment_format.setFontItalic(True)
71
+ self.highlighting_rules.append((
72
+ QRegularExpression("--[^\n]*"),
73
+ comment_format
74
+ ))
75
+
76
+ # Multi-line comments
77
+ self.comment_start_expression = QRegularExpression("/\\*")
78
+ self.comment_end_expression = QRegularExpression("\\*/")
79
+ self.multi_line_comment_format = comment_format
80
+
81
+ def highlightBlock(self, text):
82
+ # Apply regular expression highlighting rules
83
+ for pattern, format in self.highlighting_rules:
84
+ match_iterator = pattern.globalMatch(text)
85
+ while match_iterator.hasNext():
86
+ match = match_iterator.next()
87
+ self.setFormat(match.capturedStart(), match.capturedLength(), format)
88
+
89
+ # Handle multi-line comments
90
+ self.setCurrentBlockState(0)
91
+
92
+ # If previous block was inside a comment, check if this block continues it
93
+ start_index = 0
94
+ if self.previousBlockState() != 1:
95
+ # Find the start of a comment
96
+ start_match = self.comment_start_expression.match(text)
97
+ if start_match.hasMatch():
98
+ start_index = start_match.capturedStart()
99
+ else:
100
+ return
101
+
102
+ while start_index >= 0:
103
+ # Find the end of the comment
104
+ end_match = self.comment_end_expression.match(text, start_index)
105
+
106
+ # If end match found
107
+ if end_match.hasMatch():
108
+ end_index = end_match.capturedStart()
109
+ comment_length = end_index - start_index + end_match.capturedLength()
110
+ self.setFormat(start_index, comment_length, self.multi_line_comment_format)
111
+
112
+ # Look for next comment
113
+ start_match = self.comment_start_expression.match(text, start_index + comment_length)
114
+ if start_match.hasMatch():
115
+ start_index = start_match.capturedStart()
116
+ else:
117
+ start_index = -1
118
+ else:
119
+ # No end found, comment continues to next block
120
+ self.setCurrentBlockState(1) # Still inside comment
121
+ comment_length = len(text) - start_index
122
+ self.setFormat(start_index, comment_length, self.multi_line_comment_format)
123
+ start_index = -1
@@ -0,0 +1,6 @@
1
+ """UI components for SQLShell application."""
2
+
3
+ from sqlshell.ui.filter_header import FilterHeader
4
+ from sqlshell.ui.bar_chart_delegate import BarChartDelegate
5
+
6
+ __all__ = ['FilterHeader', 'BarChartDelegate']
@@ -0,0 +1,49 @@
1
+ from PyQt6.QtWidgets import QStyledItemDelegate
2
+ from PyQt6.QtCore import Qt, QRect
3
+ from PyQt6.QtGui import QColor
4
+
5
+ class BarChartDelegate(QStyledItemDelegate):
6
+ def __init__(self, parent=None):
7
+ super().__init__(parent)
8
+ self.min_val = 0
9
+ self.max_val = 1
10
+ self.bar_color = QColor("#3498DB")
11
+
12
+ def set_range(self, min_val, max_val):
13
+ self.min_val = min_val
14
+ self.max_val = max_val
15
+
16
+ def paint(self, painter, option, index):
17
+ # Draw the default background
18
+ super().paint(painter, option, index)
19
+
20
+ try:
21
+ text = index.data()
22
+ value = float(text.replace(',', ''))
23
+
24
+ # Calculate normalized value
25
+ range_val = self.max_val - self.min_val if self.max_val != self.min_val else 1
26
+ normalized = (value - self.min_val) / range_val
27
+
28
+ # Define bar dimensions
29
+ bar_height = 16
30
+ max_bar_width = 100
31
+ bar_width = max(5, int(max_bar_width * normalized))
32
+
33
+ # Calculate positions
34
+ text_width = option.fontMetrics.horizontalAdvance(text) + 10
35
+ bar_x = option.rect.left() + text_width + 10
36
+ bar_y = option.rect.center().y() - bar_height // 2
37
+
38
+ # Draw the bar
39
+ bar_rect = QRect(bar_x, bar_y, bar_width, bar_height)
40
+ painter.fillRect(bar_rect, self.bar_color)
41
+
42
+ # Draw the text
43
+ text_rect = QRect(option.rect.left() + 4, option.rect.top(),
44
+ text_width, option.rect.height())
45
+ painter.drawText(text_rect, Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignVCenter, text)
46
+
47
+ except (ValueError, AttributeError):
48
+ # If not a number, just draw the text
49
+ super().paint(painter, option, index)