Skip to content

Commit ec1b05e

Browse files
author
Lee Miller
committed
Allow user to set a base Qt window style and the font (family and size only)
1 parent 21bef10 commit ec1b05e

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

src/bitmessageqt/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4241,6 +4241,15 @@ def __init__(self, *argv):
42414241
QtCore.QCoreApplication.setOrganizationDomain("bitmessage.org")
42424242
QtCore.QCoreApplication.setApplicationName("pybitmessageqt")
42434243

4244+
self.setStyle(
4245+
config.safeGet('bitmessagesettings', 'windowstyle', 'GTK+'))
4246+
4247+
font = config.safeGet('bitmessagesettings', 'font')
4248+
if font:
4249+
# family, size, weight = font.split(',')
4250+
family, size = font.split(',')
4251+
self.setFont(QtGui.QFont(family, int(size)))
4252+
42444253
self.server = None
42454254
self.is_running = False
42464255

src/bitmessageqt/settings.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def __init__(self, parent=None, firstrun=False):
4949
self.firstrun = firstrun
5050
self.config = config_obj
5151
self.net_restart_needed = False
52+
self.font_setting = None
5253
self.timer = QtCore.QTimer()
5354

5455
if self.config.safeGetBoolean('bitmessagesettings', 'dontconnect'):
@@ -85,6 +86,16 @@ def __init__(self, parent=None, firstrun=False):
8586
def adjust_from_config(self, config):
8687
"""Adjust all widgets state according to config settings"""
8788
# pylint: disable=too-many-branches,too-many-statements
89+
90+
current_style = config.safeGet(
91+
'bitmessagesettings', 'windowstyle', 'GTK+')
92+
for i, sk in enumerate(QtGui.QStyleFactory.keys()):
93+
self.comboBoxStyle.addItem(sk)
94+
if sk == current_style:
95+
self.comboBoxStyle.setCurrentIndex(i)
96+
97+
self.save_font_setting(QtGui.QApplication.instance().font())
98+
8899
if not self.parent.tray.isSystemTrayAvailable():
89100
self.groupBoxTray.setEnabled(False)
90101
self.groupBoxTray.setTitle(_translate(
@@ -322,6 +333,18 @@ def click_pushButtonNamecoinTest(self):
322333
if status == 'success':
323334
self.parent.namecoin = nc
324335

336+
def save_font_setting(self, font):
337+
"""Save user font setting and set the buttonFont text"""
338+
font_setting = (font.family(), font.pointSize())
339+
self.buttonFont.setText('{} {}'.format(*font_setting))
340+
self.font_setting = '{},{}'.format(*font_setting)
341+
342+
def choose_font(self):
343+
"""Show the font selection dialog"""
344+
font, valid = QtGui.QFontDialog.getFont()
345+
if valid:
346+
self.save_font_setting(font)
347+
325348
def accept(self):
326349
"""A callback for accepted event of buttonBox (OK button pressed)"""
327350
# pylint: disable=too-many-branches,too-many-statements
@@ -348,6 +371,22 @@ def accept(self):
348371
self.config.set('bitmessagesettings', 'replybelow', str(
349372
self.checkBoxReplyBelow.isChecked()))
350373

374+
window_style = str(self.comboBoxStyle.currentText())
375+
if self.config.safeGet(
376+
'bitmessagesettings', 'windowstyle', 'GTK+'
377+
) != window_style or self.config.safeGet(
378+
'bitmessagesettings', 'font'
379+
) != self.font_setting:
380+
self.config.set('bitmessagesettings', 'windowstyle', window_style)
381+
self.config.set('bitmessagesettings', 'font', self.font_setting)
382+
queues.UISignalQueue.put((
383+
'updateStatusBar', (
384+
_translate(
385+
"MainWindow",
386+
"You need to restart the application to apply"
387+
" the window style or default font."), 1)
388+
))
389+
351390
lang = str(self.languageComboBox.itemData(
352391
self.languageComboBox.currentIndex()).toString())
353392
self.config.set('bitmessagesettings', 'userlocale', lang)

src/bitmessageqt/settings.ui

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,32 @@
147147
</property>
148148
</widget>
149149
</item>
150+
<item row="9" column="0">
151+
<widget class="QGroupBox" name="groupBoxStyle">
152+
<property name="title">
153+
<string>Custom Style</string>
154+
</property>
155+
<layout class="QHBoxLayout">
156+
<item>
157+
<widget class="QComboBox" name="comboBoxStyle">
158+
<property name="minimumSize">
159+
<size>
160+
<width>100</width>
161+
<height>0</height>
162+
</size>
163+
</property>
164+
</widget>
165+
</item>
166+
<item>
167+
<widget class="QPushButton" name="buttonFont">
168+
<property name="text">
169+
<string>Font</string>
170+
</property>
171+
</widget>
172+
</item>
173+
</layout>
174+
</widget>
175+
</item>
150176
<item row="9" column="1">
151177
<widget class="QGroupBox" name="groupBox">
152178
<property name="title">
@@ -1202,5 +1228,11 @@
12021228
</hint>
12031229
</hints>
12041230
</connection>
1231+
<connection>
1232+
<sender>buttonFont</sender>
1233+
<signal>clicked()</signal>
1234+
<receiver>settingsDialog</receiver>
1235+
<slot>choose_font</slot>
1236+
</connection>
12051237
</connections>
12061238
</ui>

0 commit comments

Comments
 (0)