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