@@ -31,103 +31,149 @@ def mousePressEvent(self, event):
3131 self .parent ().parent ().changeTheme (self .index )
3232 super (Preferences .Appearance .ThemeLabel , self ).mousePressEvent (event )
3333
34- def __init__ (self , parent , update_function ):
35- super (Preferences .Appearance , self ).__init__ (parent = parent )
36- self .update_function = update_function
37- self .layout = QGridLayout ()
38- self .theme , self .font_size , self .font_family = returnProperties ()["theme" ], returnProperties ()["font-size" ], returnProperties ()["font-family" ]
39- self .widgets , self .group_box_widgets = {
40- "theme-label" : [QLabel ("Theme" ), [3 , 1 ]],
41- "theme-group-box" : [QGroupBox (self ), [3 , 2 ]],
42- "font-size-label" : [QLabel ("Font Size" ), [5 , 1 ]],
43- "font-size" : [Slider (5 , 20 , int (returnProperties ()["font-size" ]), self .changeFontSize ), [5 , 2 ]],
44- "reset-font-size" : [PushButton ("Reset" ), [5 , 3 ]],
45- "font-family-label" : [QLabel ("Font Family" ), [6 , 1 ]],
46- "font-family" : [QComboBox (self ), [6 , 2 ]]
47- }, {}
48- # Append to self.group_box_widgets
49- for x , y in zip (Themes .getThemes (), range (1 , len (Themes .getThemes ().keys ()) + 1 )):
50- self .group_box_widgets [x ] = [Preferences .Appearance .ThemeLabel (self ), [1 , y ]]
51- # Specific widget properties
52- # # Font family properties
53- self .widgets ["font-family" ][0 ].addItems (returnProperties ()["fonts" ])
54- self .widgets ["font-family" ][0 ].setStyleSheet (f"QComboBox QAbstractItemView {{ selection-color: { '#AAAAAA' if returnProperties ()['theme' ] == 'light' else '#555555' } ; color: { returnBackgroundProperties ()['text-color' ]} ; }};" )
55- self .widgets ["font-family" ][0 ].setCurrentIndex (returnProperties ()["fonts" ].index (self .font_family ))
56- self .widgets ["font-family" ][0 ].currentIndexChanged .connect (self .changeFontFamily )
57- # # Reset font size properties
58- self .widgets ["reset-font-size" ][0 ].clicked .connect (self .resetFontSize )
59- # # Label properties
60- for i in ["theme-label" , "font-size-label" , "font-family-label" ]:
61- self .widgets [i ][0 ].setStyleSheet (f"color: { returnBackgroundProperties ()['text-color' ]} ;" )
62- self .widgets [i ][0 ].setFont (QFont (returnProperties ()["font-family" ], returnProperties ()["font-size" ]))
63- # # Theme group box properties
64- self .widgets ["theme-group-box" ][0 ].setStyleSheet ("QGroupBox { border: none; }" )
65- self .group_box_layout = QHBoxLayout ()
66- for i in self .group_box_widgets :
67- self .group_box_layout .addWidget (self .group_box_widgets [i ][0 ])
68- self .widgets ["theme-group-box" ][0 ].setLayout (self .group_box_layout )
69- self .widgets ["theme-group-box" ][0 ].setFixedSize (540 , 100 )
70- self .widgets ["theme-group-box" ][0 ].layout ().setContentsMargins (30 , 30 , 30 , 30 )
71- # # Theme button properties
72- for i in self .group_box_widgets .keys ():
73- self .group_box_widgets [i ][0 ].setText (i .title ())
74- self .group_box_widgets [i ][0 ].setStyleSheet (f"color: #{ str (Themes .getThemes ()[i ]['text-color' ])[1 :].lower ()} ; border: none; background: #{ str (Themes .getThemes ()[i ]['background-color' ])[1 :].lower ()} ;" )
75- self .group_box_widgets [i ][0 ].index = i
76- # exec(f"self.group_box_widgets[i][0].pressed.connect(lambda self=self: self.changeTheme('{i}'))", globals(), locals())
77- # Add to layout
78- for i in self .widgets .keys ():
79- self .layout .addWidget (self .widgets [i ][0 ], self .widgets [i ][1 ][0 ], self .widgets [i ][1 ][1 ])
80- self .setLayout (self .layout ) # Set layout
81-
82- def _update (self ):
83- self .setStyleSheet (f"background-color: { returnBackgroundProperties ()['background-color-2' ]} " )
84- for i in ["theme-label" , "font-size-label" , "font-family-label" ]:
85- self .widgets [i ][0 ].setStyleSheet (f"color: { returnBackgroundProperties ()['text-color' ]} ; font-size: { returnProperties ()['font-size' ]} " )
86- self .widgets [i ][0 ].setFont (QFont (returnProperties ()["font-family" ], returnProperties ()["font-size" ]))
87- for i in self .group_box_widgets .keys ():
88- self .group_box_widgets [i ][0 ].setStyleSheet (f"color: { returnBackgroundProperties ()['text-color' ]} ; border: none" )
89- self .group_box_widgets [i ][0 ].setFont (QFont (returnProperties ()["font-family" ], returnProperties ()["font-size" ]))
90- # self.widgets["font-family"][0].setStyleSheet("QComboBox QAbstractItemView {selection-color: #AAAAAA}")
91- if returnProperties ()["theme" ] == "light" :
92- self .widgets ["font-family" ][0 ].setStyleSheet ("QComboBox QAbstractItemView { selection-color: #AAAAAA; color: #000000; };" )
93- else :
94- self .widgets ["font-family" ][0 ].setStyleSheet ("QComboBox QAbstractItemView { selection-color: #555555; color: #FFFFFF; };" )
95- self .update_function ()
34+ class Theme (QWidget ):
35+ def __init__ (self , parent , update_function ):
36+ super (Preferences .Appearance .Theme , self ).__init__ (parent = parent )
37+ self .update_function = update_function
38+ self .layout = QGridLayout ()
39+ self .theme , self .font_size , self .font_family = returnProperties ()["theme" ], returnProperties ()["font-size" ], returnProperties ()["font-family" ]
40+ self .top_bar = QGroupBox (self )
41+ self .top_bar .setLayout (QHBoxLayout ())
42+ self .back_button = QPushButton ("Back" , self .top_bar )
43+ self .back_button .pressed .connect (lambda self = self : self .parent ().setCurrentIndex (0 ))
44+ self .top_bar .layout ().addWidget (self .back_button )
45+ # self.layout.addWidget(self.top_bar, 0, 0)
46+ self .widgets , self .group_box_widgets = {
47+ "top-bar" : [self .top_bar , [0 , 0 ]],
48+ "theme-label" : [QLabel ("Theme" ), [3 , 0 ]],
49+ "theme-group-box" : [QGroupBox (self ), [3 , 1 ]],
50+ "font-size-label" : [QLabel ("Font Size" ), [5 , 0 ]],
51+ "font-size" : [Slider (5 , 20 , int (returnProperties ()["font-size" ]), self .changeFontSize ), [5 , 1 ]],
52+ "reset-font-size" : [PushButton ("Reset" ), [5 , 2 ]],
53+ "font-family-label" : [QLabel ("Font Family" ), [6 , 0 ]],
54+ "font-family" : [QComboBox (self ), [6 , 1 ]]
55+ }, {}
56+ # Append to self.group_box_widgets
57+ for x , y in zip (Themes .getThemes (), range (1 , len (Themes .getThemes ().keys ()) + 1 )):
58+ self .group_box_widgets [x ] = [Preferences .Appearance .ThemeLabel (self ), [1 , y ]]
59+ # Specific widget properties
60+ # # Font family properties
61+ self .widgets ["font-family" ][0 ].addItems (returnProperties ()["fonts" ])
62+ self .widgets ["font-family" ][0 ].setStyleSheet (f"QComboBox QAbstractItemView {{ selection-color: { '#AAAAAA' if returnProperties ()['theme' ] == 'light' else '#555555' } ; color: { returnBackgroundProperties ()['text-color' ]} ; }};" )
63+ self .widgets ["font-family" ][0 ].setCurrentIndex (returnProperties ()["fonts" ].index (self .font_family ))
64+ self .widgets ["font-family" ][0 ].currentIndexChanged .connect (self .changeFontFamily )
65+ # # Reset font size properties
66+ self .widgets ["reset-font-size" ][0 ].clicked .connect (self .resetFontSize )
67+ # # Label properties
68+ for i in ["theme-label" , "font-size-label" , "font-family-label" ]:
69+ self .widgets [i ][0 ].setStyleSheet (f"color: { returnBackgroundProperties ()['text-color' ]} ;" )
70+ self .widgets [i ][0 ].setFont (QFont (returnProperties ()["font-family" ], returnProperties ()["font-size" ]))
71+ # # Theme group box properties
72+ self .widgets ["theme-group-box" ][0 ].setStyleSheet ("QGroupBox { border: none; }" )
73+ self .group_box_layout = QHBoxLayout ()
74+ for i in self .group_box_widgets :
75+ self .group_box_layout .addWidget (self .group_box_widgets [i ][0 ])
76+ self .widgets ["theme-group-box" ][0 ].setLayout (self .group_box_layout )
77+ self .widgets ["theme-group-box" ][0 ].setFixedSize (540 , 100 )
78+ self .widgets ["theme-group-box" ][0 ].layout ().setContentsMargins (30 , 30 , 30 , 30 )
79+ # # Theme button properties
80+ for i in self .group_box_widgets .keys ():
81+ self .group_box_widgets [i ][0 ].setText (i .title ())
82+ self .group_box_widgets [i ][0 ].setStyleSheet (f"color: #{ str (Themes .getThemes ()[i ]['text-color' ])[1 :].lower ()} ; border: none; background: #{ str (Themes .getThemes ()[i ]['background-color' ])[1 :].lower ()} ;" )
83+ self .group_box_widgets [i ][0 ].index = i
84+ # exec(f"self.group_box_widgets[i][0].pressed.connect(lambda self=self: self.changeTheme('{i}'))", globals(), locals())
85+ # Add to layout
86+ for i in self .widgets .keys ():
87+ self .layout .addWidget (self .widgets [i ][0 ], self .widgets [i ][1 ][0 ], self .widgets [i ][1 ][1 ])
88+ self .setLayout (self .layout ) # Set layout
9689
97- def resetFontSize (self ) -> None :
98- self .font_size = 12
99- self .widgets ["font-size" ][0 ].setValue (12 )
100- with open ("System/config/font.json" ) as file :
101- data = load (file )
102- data ["font-size" ] = self .font_size
103- open ("System/config/font.json" , "w" ).write (str (data ).replace ("'" , "\" " ))
104- self ._update ()
90+ def _update (self ):
91+ self .setStyleSheet (f"background-color: { returnBackgroundProperties ()['background-color-2' ]} " )
92+ for i in ["theme-label" , "font-size-label" , "font-family-label" ]:
93+ self .widgets [i ][0 ].setStyleSheet (f"color: { returnBackgroundProperties ()['text-color' ]} ; font-size: { returnProperties ()['font-size' ]} " )
94+ self .widgets [i ][0 ].setFont (QFont (returnProperties ()["font-family" ], returnProperties ()["font-size" ]))
95+ for i in self .group_box_widgets .keys ():
96+ self .group_box_widgets [i ][0 ].setStyleSheet (f"color: { returnBackgroundProperties ()['text-color' ]} ; border: none" )
97+ self .group_box_widgets [i ][0 ].setFont (QFont (returnProperties ()["font-family" ], returnProperties ()["font-size" ]))
98+ # self.widgets["font-family"][0].setStyleSheet("QComboBox QAbstractItemView {selection-color: #AAAAAA}")
99+ if returnProperties ()["theme" ] == "light" :
100+ self .widgets ["font-family" ][0 ].setStyleSheet ("QComboBox QAbstractItemView { selection-color: #AAAAAA; color: #000000; };" )
101+ else :
102+ self .widgets ["font-family" ][0 ].setStyleSheet ("QComboBox QAbstractItemView { selection-color: #555555; color: #FFFFFF; };" )
103+ self .update_function ()
104+
105+ def resetFontSize (self ) -> None :
106+ self .font_size = 12
107+ self .widgets ["font-size" ][0 ].setValue (12 )
108+ with open ("System/config/font.json" ) as file :
109+ data = load (file )
110+ data ["font-size" ] = self .font_size
111+ open ("System/config/font.json" , "w" ).write (str (data ).replace ("'" , "\" " ))
112+ self ._update ()
113+
114+ def changeFontFamily (self ) -> None :
115+ self .font_family = self .widgets ["font-family" ][0 ].currentText ()
116+ with open ("System/config/font.json" , "r+" ) as file :
117+ data = load (file )
118+ data ["font-family" ] = self .font_family
119+ open ("System/config/font.json" , "w" ).write (str (data ).replace ("'" , "\" " ))
120+ self ._update ()
121+
122+ def changeFontSize (self ) -> None :
123+ self .font_size = self .widgets ["font-size" ][0 ].value ()
124+ with open ("System/config/font.json" , "r+" ) as file :
125+ data = load (file )
126+ data ["font-size" ] = self .font_size
127+ open ("System/config/font.json" , "w" ).write (str (data ).replace ("'" , "\" " ))
128+ self ._update ()
129+
130+ def changeTheme (self , theme ):
131+ self .theme = theme
132+ with open ("System/config/theme.json" , "r+" ) as file :
133+ data = load (file )
134+ data ["theme" ] = self .theme
135+ open ("System/config/theme.json" , "w" ).write (str (data ).replace ("'" , "\" " ))
136+ self ._update ()
137+ self .parent ().parent ().parent ().parent ().parent ().restartWindow ()
105138
106- def changeFontFamily (self ) -> None :
107- self .font_family = self .widgets ["font-family" ][0 ].currentText ()
108- with open ("System/config/font.json" , "r+" ) as file :
109- data = load (file )
110- data ["font-family" ] = self .font_family
111- open ("System/config/font.json" , "w" ).write (str (data ).replace ("'" , "\" " ))
112- self ._update ()
139+ def resizeEvent (self , event ) -> None :
140+ self .top_bar .resize (QSize (event .size ().width (), self .top_bar .size ().height ()))
141+ super (Preferences .Appearance .Theme , self ).resizeEvent (event )
142+
143+ class AppearanceWidget (QWidget ):
144+ def __init__ (self , parent , update_function ):
145+ super (Preferences .Appearance .AppearanceWidget , self ).__init__ (parent )
146+ self .update_function = update_function
147+ self .buttons = []
148+ self .buttons .append (ActionPushButton (self , "General" , lambda : self .parent ().setCurrentIndex (1 )))
149+ self .buttons .append (ActionPushButton (self , "Windows" , lambda : self .parent ().setCurrentIndex (1 )))
150+ self .buttons .append (ActionPushButton (self , "Dock" , lambda : self .parent ().setCurrentIndex (1 )))
151+ width = self .buttons [0 ].width ()
152+ for i in range (len (self .buttons )):
153+ self .buttons [i ].move (QPoint (i * (width + 5 ), 0 ))
113154
114- def changeFontSize (self ) -> None :
115- self .font_size = self .widgets ["font-size" ][0 ].value ()
116- with open ("System/config/font.json" , "r+" ) as file :
117- data = load (file )
118- data ["font-size" ] = self .font_size
119- open ("System/config/font.json" , "w" ).write (str (data ).replace ("'" , "\" " ))
120- self ._update ()
155+ def resizeEvent (self , event ) -> None :
156+ single_width , width , y = self .buttons [0 ].width (), 0 , 0
157+ for i in range (len (self .buttons )):
158+ if (width + 5 ) >= self .width ():
159+ y += self .buttons [i ].height () + 5
160+ width = 0
161+ self .buttons [i ].move (QPoint (width , y ))
162+ width += single_width + 5
163+ super (Preferences .Appearance .AppearanceWidget , self ).resizeEvent (event )
164+
165+ def __init__ (self , parent , update_function ):
166+ super (Preferences .Appearance , self ).__init__ (parent )
167+ self .update_function = update_function
168+ self .stacked_widgets , self .pages = QStackedWidget (self ), {"main" : Preferences .Appearance .AppearanceWidget (self , update_function ), "theme" : Preferences .Appearance .Theme (self , update_function )}
169+ for i in self .pages .values ():
170+ self .stacked_widgets .addWidget (i )
171+
172+ def resizeEvent (self , event ) -> None :
173+ for i in self .pages .values ():
174+ i .resize (event .size ())
175+ super (Preferences .Appearance , self ).resizeEvent (event )
121176
122- def changeTheme (self , theme ):
123- self .theme = theme
124- with open ("System/config/theme.json" , "r+" ) as file :
125- data = load (file )
126- data ["theme" ] = self .theme
127- open ("System/config/theme.json" , "w" ).write (str (data ).replace ("'" , "\" " ))
128- self ._update ()
129- self .parent ().parent ().parent ().restartWindow ()
130-
131177 def __init__ (self , update_function ) -> None :
132178 super (Preferences , self ).__init__ ()
133179 self .setCursor (Qt .ArrowCursor )
@@ -141,7 +187,7 @@ def __init__(self, update_function) -> None:
141187 self .tab_layout .addWidget (TabButton (self .tab_widget , lambda : self .stacked_widgets .setCurrentIndex (0 ), "Appearance" ))
142188 self .tab_layout .addItem (QSpacerItem (100 , 20 , QSizePolicy .Expanding , QSizePolicy .Expanding ))
143189
144- self .tabs .setStyleSheet ("border: none;" )
190+ self .tabs .setStyleSheet ("border: none; background: #F0F0F0 " )
145191
146192 self .stacked_widgets , self .pages = QStackedWidget (self ), {"appearance" : Preferences .Appearance (self , update_function )}
147193 for i in self .pages .values ():
0 commit comments