@@ -383,30 +383,59 @@ class MessageButtonBar(QWidget):
383
383
def __init__ (self , parent ):
384
384
super ().__init__ (parent = parent )
385
385
self .parent = parent
386
- self .mic_button = self .MicButton ()
386
+ self .mic_button = self .MicButton (self )
387
387
self .enhance_button = TextEnhancerButton (self , self .parent , gen_block_folder_name = 'Enhance prompt' )
388
- self .edit_button = self .EditButton ()
388
+ self .edit_button = self .EditButton (self )
389
+ self .screenshot_button = self .ScreenshotButton (self )
390
+
389
391
self .layout = CVBoxLayout (self )
390
392
h_layout = CHBoxLayout ()
391
393
h_layout .addWidget (self .mic_button )
392
394
h_layout .addWidget (self .edit_button )
393
395
self .layout .addLayout (h_layout )
394
- self .layout .addWidget (self .enhance_button )
396
+
397
+ h2_layout = CHBoxLayout ()
398
+ h2_layout .addWidget (self .enhance_button )
399
+ h2_layout .addWidget (self .screenshot_button )
400
+ self .layout .addLayout (h2_layout )
401
+
395
402
self .hide ()
396
403
397
404
class EditButton (IconButton ):
398
- def __init__ (self ):
399
- super ().__init__ (parent = None , icon_path = ':/resources/icon-dots.png' , size = 20 , opacity = 0.75 )
405
+ def __init__ (self , parent ):
406
+ super ().__init__ (parent = parent , icon_path = ':/resources/icon-dots.png' , size = 20 , opacity = 0.75 )
400
407
self .setProperty ("class" , "send" )
401
408
self .clicked .connect (self .on_clicked )
402
- self .recording = False
403
409
404
410
def on_clicked (self ):
405
411
pass
406
412
413
+ class ScreenshotButton (IconButton ):
414
+ def __init__ (self , parent ):
415
+ super ().__init__ (parent = parent , icon_path = ':/resources/icon-screenshot.png' , size = 20 , opacity = 0.75 )
416
+ self .setProperty ("class" , "send" )
417
+ self .clicked .connect (self .on_clicked )
418
+
419
+ def on_clicked (self ):
420
+ # minimize app, take screenshot, maximize app
421
+ main = find_main_widget (self )
422
+
423
+ try :
424
+ import pyautogui
425
+ pyautogui .screenshot () # check missing lib before minimizing
426
+ main .showMinimized ()
427
+ screenshot = pyautogui .screenshot ()
428
+ main .showNormal ()
429
+ b64 = screenshot .tobytes ()
430
+ print (b64 )
431
+ except Exception as e :
432
+ display_message (self , f'Error taking screenshot: { e } ' , 'Error' , QMessageBox .Warning )
433
+ finally :
434
+ main .showNormal ()
435
+
407
436
class MicButton (ToggleIconButton ):
408
- def __init__ (self ):
409
- super ().__init__ (parent = None , icon_path = ':/resources/icon-mic.png' , color_when_checked = '#6aab73' , size = 20 , opacity = 0.75 )
437
+ def __init__ (self , parent ):
438
+ super ().__init__ (parent = parent , icon_path = ':/resources/icon-mic.png' , color_when_checked = '#6aab73' , size = 20 , opacity = 0.75 )
410
439
self .setProperty ("class" , "send" )
411
440
self .recording = False
412
441
@@ -458,40 +487,51 @@ def __init__(self, parent=None, color=None):
458
487
elif not color .startswith ('#' ):
459
488
color = '#ff6464'
460
489
461
- # color = apply_alpha_to_hex(color, 0.8)
462
490
self .setStyleSheet (f"""
463
491
background-color: { color } ;
464
492
border-radius: 10px;
465
493
color: white;
466
494
padding: 10px;
467
495
""" )
468
496
self .setMaximumWidth (300 )
469
- # self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
497
+ outer_layout = QVBoxLayout (self )
498
+ outer_layout .setContentsMargins (0 , 0 , 0 , 0 )
499
+ outer_layout .setSpacing (0 )
500
+
501
+ self .content = QWidget (self )
502
+ content_layout = QVBoxLayout (self .content )
503
+ content_layout .setContentsMargins (0 , 0 , 0 , 0 )
504
+ content_layout .setSpacing (0 )
470
505
471
- self .layout = CVBoxLayout (self )
472
506
self .label = QLabel ()
473
- # set word wrap at 290px width
474
- # self.label.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum)
475
- # self.label.setMaximumWidth(290)
476
- # self.label.setWordWrap(True)
477
- self .layout .addWidget (self .label )
507
+ self .label .setWordWrap (True )
508
+ content_layout .addWidget (self .label )
509
+
510
+ outer_layout .addWidget (self .content )
511
+
512
+ self .content .setMinimumHeight (0 )
478
513
479
514
self .timer = QTimer (self )
480
515
self .timer .setSingleShot (True )
481
516
self .timer .timeout .connect (self .hide_animation )
482
517
483
- self .animation = QPropertyAnimation (self , b"maximumHeight " )
518
+ self .animation = QPropertyAnimation (self . content , b"minimumHeight " )
484
519
self .animation .setEasingCurve (QEasingCurve .InOutCubic )
485
520
self .animation .finished .connect (self .on_animation_finished )
486
521
487
522
def show_message (self , message , duration = 3000 ):
488
523
self .label .setText (message )
489
524
self .label .adjustSize ()
525
+ self .content .adjustSize ()
490
526
self .adjustSize ()
491
- self .setMaximumHeight (0 ) # Start with zero height
492
527
493
- # Animate showing
494
- target_height = self .sizeHint ().height ()
528
+ QApplication .processEvents () # todo
529
+
530
+ self .content .setMinimumHeight (0 )
531
+
532
+ target_height = self .content .sizeHint ().height ()
533
+
534
+ self .animation .stop ()
495
535
self .animation .setStartValue (0 )
496
536
self .animation .setEndValue (target_height )
497
537
self .animation .setDuration (300 )
@@ -500,15 +540,15 @@ def show_message(self, message, duration=3000):
500
540
self .timer .start (duration )
501
541
502
542
def hide_animation (self ):
503
- # Animate hiding
504
- current_height = self .height ()
543
+ current_height = self . content . minimumHeight ()
544
+ self .animation . stop ()
505
545
self .animation .setStartValue (current_height )
506
546
self .animation .setEndValue (0 )
507
547
self .animation .setDuration (300 )
508
548
self .animation .start ()
509
549
510
550
def on_animation_finished (self ):
511
- if self .maximumHeight () == 0 :
551
+ if self .content . minimumHeight () == 0 :
512
552
self .hide ()
513
553
self .closed .emit (self )
514
554
@@ -517,7 +557,7 @@ def enterEvent(self, event):
517
557
event .accept ()
518
558
519
559
def leaveEvent (self , event ):
520
- self .timer .start (3000 ) # Reset timer when mouse leaves
560
+ self .timer .start (3000 )
521
561
event .accept ()
522
562
523
563
@@ -529,6 +569,7 @@ def __init__(self, parent):
529
569
self .setWindowFlags (Qt .FramelessWindowHint | Qt .WindowStaysOnTopHint | Qt .Tool )
530
570
self .setAttribute (Qt .WA_TranslucentBackground )
531
571
self .setAttribute (Qt .WA_ShowWithoutActivating ) # Add this line
572
+ self .setSizePolicy (QSizePolicy .Fixed , QSizePolicy .Preferred )
532
573
533
574
self .layout = CVBoxLayout (self )
534
575
self .layout .setSpacing (4 )
@@ -563,16 +604,8 @@ def remove_notification(self, notification):
563
604
self .hide ()
564
605
565
606
def update_position (self ):
566
- # main_x, main_y = self.main.x(), self.main.y()
567
607
self .move (self .main .x () + self .main .width () - self .width () - 4 , self .main .y () + 50 )
568
- # print(f'POSITION: main.x={self.main.x()}, main.width={self.main.width()}, self.width={self.width()}')
569
- # parent = self.parent()
570
- # if parent:
571
- # parent_geometry = parent.geometry()
572
- # self.adjustSize()
573
- # pos_x = parent_geometry.right() - self.width() - 20
574
- # pos_y = parent_geometry.top() + 20
575
- # self.move(pos_x, pos_y)
608
+
576
609
577
610
578
611
class MessageText (QTextEdit ):
@@ -899,18 +932,6 @@ def __init__(self):
899
932
900
933
self .notification_manager .update_position ()
901
934
902
- def disp_msg (self , msg ):
903
- self .notification_manager .show_notification (msg )
904
-
905
- # @Slot(str, str)
906
- # def on_task_completed(self, task_id, result):
907
- # print(f"Task {task_id} completed with result: {result}")
908
- # # Update UI or perform any other actions
909
- # # def send_notification(self, message):
910
- # # notification = NotificationWidget(self)
911
- # # notification.show_message(message)
912
- # # self.notification_widgets.append(notification)
913
-
914
935
def pinned_pages (self ): # todo?
915
936
all_pinned_pages = {'Chat' , 'Contexts' , 'Agents' , 'Settings' }
916
937
# pinned_pages = self.system.config.dict.get('display.pinned_pages', []) # !! #
@@ -1047,6 +1068,8 @@ def sync_send_button_size(self):
1047
1068
self .message_text .button_bar .setFixedHeight (self .message_text .height ())
1048
1069
self .message_text .button_bar .mic_button .setFixedHeight (int (self .message_text .height () / 2 ))
1049
1070
self .message_text .button_bar .enhance_button .setFixedHeight (int (self .message_text .height () / 2 ))
1071
+ self .message_text .button_bar .edit_button .setFixedHeight (int (self .message_text .height () / 2 ))
1072
+ self .message_text .button_bar .screenshot_button .setFixedHeight (int (self .message_text .height () / 2 ))
1050
1073
1051
1074
def is_bottom_corner (self ):
1052
1075
screen_geo = QGuiApplication .primaryScreen ().geometry () # get screen geometry
0 commit comments