Skip to content
This repository was archived by the owner on Aug 28, 2020. It is now read-only.

Commit 4ec3600

Browse files
committed
Merge pull request #102 from ihabunek/feature/settings
Some improvements to settings. Thanks @ihabunek !
2 parents 49357d9 + 8137231 commit 4ec3600

File tree

3 files changed

+34
-59
lines changed

3 files changed

+34
-59
lines changed

pugdebug/gui/main_window.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,6 @@ def setup_docks(self):
8585
Qt.LeftDockWidgetArea
8686
)
8787

88-
self.__add_dock_widget(
89-
self.settings_window,
90-
"Settings",
91-
Qt.LeftDockWidgetArea
92-
)
93-
9488
self.__add_dock_widget(
9589
self.variable_viewer,
9690
"Variables",
@@ -179,6 +173,11 @@ def setup_actions(self):
179173
self.quit_action.setShortcut(QKeySequence("Alt+F4"))
180174
self.quit_action.triggered.connect(self.close)
181175

176+
self.show_settings_action = QAction("&Settings", self)
177+
self.show_settings_action.setToolTip("Show settings")
178+
self.show_settings_action.setStatusTip("Show the settings window.")
179+
self.show_settings_action.triggered.connect(self.settings_window.exec)
180+
182181
def setup_toolbar(self):
183182
toolbar = QToolBar("Main Toolbar")
184183
toolbar.setObjectName("main-toolbar")
@@ -199,6 +198,7 @@ def setup_menubar(self):
199198

200199
file_menu = menu_bar.addMenu("&File")
201200
file_menu.addAction(self.quit_action)
201+
file_menu.addAction(self.show_settings_action)
202202

203203
view_menu = menu_bar.addMenu("&View")
204204

pugdebug/gui/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99

1010
__author__ = "robertbasic"
1111

12-
from PyQt5.QtWidgets import (QWidget, QLineEdit, QFormLayout,
12+
from PyQt5.QtWidgets import (QDialog, QLineEdit, QFormLayout,
1313
QSpinBox, QCheckBox)
1414

1515
from pugdebug.models.settings import get_setting, set_setting
1616

1717

18-
class PugdebugSettingsWindow(QWidget):
18+
class PugdebugSettingsWindow(QDialog):
1919

2020
layout = QFormLayout()
2121

pugdebug/models/settings.py

Lines changed: 26 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,27 @@
1111

1212
import os
1313

14-
from PyQt5.QtCore import QCoreApplication, QSettings
14+
from PyQt5.QtCore import QCoreApplication, QSettings, Qt
1515

1616

1717
class PugdebugSettings():
1818

19+
defaults = {
20+
'debugger': {
21+
'host': '127.0.0.1',
22+
'port_number': 9000,
23+
'idekey': 'pugdebug',
24+
'break_at_first_line': Qt.Checked,
25+
'max_depth': '3',
26+
'max_children': '128',
27+
'max_data': '512'
28+
},
29+
'path': {
30+
'project_root': os.path.expanduser('~'),
31+
'path_mapping': ''
32+
}
33+
}
34+
1935
def __init__(self):
2036
"""Model object to handle application settings
2137
@@ -30,60 +46,19 @@ def __init__(self):
3046
QCoreApplication.setApplicationName("pugdebug")
3147
self.application_settings = QSettings()
3248

33-
self.setup_debugger_settings()
34-
self.setup_path_settings()
35-
36-
def setup_debugger_settings(self):
37-
"""Set up initial debugger settings
38-
39-
Sets up the initial host to 127.0.0.1.
40-
Sets up the initial port number to 9000.
41-
Sets up the initial IDE key to pugdebug.
42-
"""
43-
self.application_settings.beginGroup("debugger")
44-
45-
if not self.application_settings.contains('host'):
46-
self.application_settings.setValue('host', '127.0.0.1')
47-
48-
if not self.application_settings.contains('port_number'):
49-
self.application_settings.setValue('port_number', 9000)
50-
51-
if not self.application_settings.contains('idekey'):
52-
self.application_settings.setValue('idekey', 'pugdebug')
53-
54-
if not self.application_settings.contains('break_at_first_line'):
55-
# 2 is the init value because 1 is some weird
56-
# between checked and unchecked state
57-
self.application_settings.setValue('break_at_first_line', 2)
58-
59-
if not self.application_settings.contains('max_depth'):
60-
self.application_settings.setValue('max_depth', '3')
61-
62-
if not self.application_settings.contains('max_children'):
63-
self.application_settings.setValue('max_children', '128')
64-
65-
if not self.application_settings.contains('max_data'):
66-
self.application_settings.setValue('max_data', '512')
67-
68-
self.application_settings.endGroup()
69-
70-
def setup_path_settings(self):
71-
"""Set up initial path settings
72-
73-
Sets up the initial project root to the user's home directory.
74-
Sets up the initial path mapping to an empty string.
75-
"""
49+
self.setup_default_settings()
7650

77-
self.application_settings.beginGroup("path")
51+
def setup_default_settings(self):
52+
"""Set up initial debugger settings"""
7853

79-
if not self.application_settings.contains('project_root'):
80-
home_path = os.path.expanduser('~')
81-
self.application_settings.setValue('project_root', home_path)
54+
for group, settings in self.defaults.items():
55+
self.application_settings.beginGroup(group)
8256

83-
if not self.application_settings.contains('path_mapping'):
84-
self.application_settings.setValue('path_mapping', '')
57+
for key, value in settings.items():
58+
if not self.application_settings.contains(key):
59+
self.application_settings.setValue(key, value)
8560

86-
self.application_settings.endGroup()
61+
self.application_settings.endGroup()
8762

8863
def get(self, key):
8964
return self.application_settings.value(key)

0 commit comments

Comments
 (0)