Skip to content

Commit

Permalink
Added a configuration option for hiding the network masternodes tab
Browse files Browse the repository at this point in the history
  • Loading branch information
Bertrand256 committed Jun 15, 2023
1 parent 41ef6e9 commit 660a45a
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 33 deletions.
11 changes: 11 additions & 0 deletions src/app_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ def __init__(self, ui_dark_mode_activated: bool):
self.fetch_network_data_after_start = True
self.show_dash_value_in_fiat = True
self.ui_use_dark_mode = False # Use dark mode independently of the OS settings
self.show_network_masternodes_tab = False

# attributes related to encryption cache data with hardware wallet:
self.hw_generated_key = b"\xab\x0fs}\x8b\t\xb4\xc3\xb8\x05\xba\xd1\x96\x9bq`I\xed(8w\xbf\x95\xf0-\x1a\x14\xcb\x1c\x1d+\xcd"
Expand Down Expand Up @@ -537,6 +538,7 @@ def copy_from(self, src_config):
self.log_level_str = src_config.log_level_str
self.encrypt_config_file = src_config.encrypt_config_file
self.ui_use_dark_mode = src_config.ui_use_dark_mode
self.show_network_masternodes_tab = src_config.show_network_masternodes_tab

def configure_cache(self):
if self.is_testnet:
Expand Down Expand Up @@ -652,6 +654,7 @@ def reset_configuration(self):
self.trezor_bridge = True
self.trezor_udp = True
self.trezor_hid = True
self.show_network_masternodes_tab = False

def simple_decrypt(self, str_to_decrypt: str, string_can_be_unencrypted: bool = False, validator: Callable = None) -> str:
""""
Expand Down Expand Up @@ -814,6 +817,9 @@ def read_from_file(self, hw_session: 'HwSessionInfo', file_name: Optional[str] =
self.show_dash_value_in_fiat = self.value_to_bool(
config.get(section, 'show_dash_value_in_fiat', fallback='1'))

self.show_network_masternodes_tab = self.value_to_bool(
config.get(section, 'show_network_masternodes_tab', fallback='1'))

# with ini ver 3 we changed the connection password encryption scheme, so connections in new ini
# file will be saved under different section names - with this we want to disallow the old app
# version to read such network configuration entries, because passwords won't be decoded properly
Expand Down Expand Up @@ -1125,6 +1131,7 @@ def save_to_file(self, hw_session: 'HwSessionInfo', file_name: Optional[str] = N
config.set(section, 'proposal_vote_time_offset_lower', str(self._proposal_vote_time_offset_lower))
config.set(section, 'proposal_vote_time_offset_upper', str(self._proposal_vote_time_offset_upper))
config.set(section, 'encrypt_config_file', '1' if self.encrypt_config_file else '0')
config.set(section, 'show_network_masternodes_tab', '1' if self.show_network_masternodes_tab else '0')

# save mn configuration
for idx, mn in enumerate(self.masternodes):
Expand Down Expand Up @@ -1240,6 +1247,7 @@ def get_cfg_data_str(self):
all_data += str(self._proposal_vote_time_offset_lower)
all_data += str(self._proposal_vote_time_offset_upper)
all_data += str(self.encrypt_config_file)
all_data += str(self.show_network_masternodes_tab)

for mn in self.masternodes:
all_data += mn.get_data_str()
Expand Down Expand Up @@ -1741,6 +1749,9 @@ def get_widget_background_color(self, wdg: QWidget) -> str:
bg_color = bg_col.name()
return bg_color

def is_network_masternodes_enabled(self) -> bool:
return self.show_network_masternodes_tab


class MasternodeConfig:
def __init__(self):
Expand Down
90 changes: 59 additions & 31 deletions src/app_main_view_wdg.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def __init__(self, parent, app_config: AppConfig, dashd_intf: DashdInterface, hw
self.net_mn_list_columns_resized_by_user = False
self.net_mn_list_last_where_cond = ''
self.cur_network_masternode: Optional[Masternode] = None
self.network_masternodes_enabled: bool = self.app_config.is_network_masternodes_enabled()

self.refresh_status_thread_ref = None
self.refresh_price_thread_ref = None
Expand Down Expand Up @@ -226,7 +227,6 @@ def restore_cache_settings(self):
except Exception as e:
log.exception(str(e))


def save_cache_settings(self):
app_cache.set_value(CACHE_ITEM_SHOW_MN_DETAILS_PANEL, self.mn_details_panel_visible)
app_cache.set_value(CACHE_ITEM_SHOW_NET_MNS_FILTER_PANEL, self.network_masternodes_filter_visible)
Expand Down Expand Up @@ -334,6 +334,7 @@ def set_cur_mn():

if len(self.app_config.masternodes) and not self.cur_masternode:
self.set_cur_cfg_masternode(self.app_config.masternodes[0])
self.config_changed()
self.update_navigation_panel()
self.update_ui()
self.update_info_page()
Expand All @@ -345,6 +346,29 @@ def set_cur_mn():

QTimer.singleShot(10, set_cur_mn)

def config_changed(self):
new_enabled = self.app_config.is_network_masternodes_enabled()

try:
if self.network_masternodes_enabled != new_enabled:
if not new_enabled:
self.network_masternodes_enabled = new_enabled
if self.current_view == Pages.PAGE_NET_MASTERNODES:
self.current_view = Pages.PAGE_MASTERNODE_LIST
self.set_cur_net_masternode(None)
self.last_net_masternodes_db_read_params_hash = ''
self.net_masternodes_last_db_timestamp = 0
self.net_mn_list_last_where_cond = ''
self.net_masternodes.clear()
else:
self.network_masternodes_enabled = new_enabled
self.refresh_net_masternodes_view()
self.update_navigation_panel()

self.update_ui()
except Exception as e:
logging.exception(str(e))

def is_editing_enabled(self):
return self.editing_enabled

Expand Down Expand Up @@ -417,32 +441,33 @@ def update_on_thread_finish():
except Exception as e:
logging.exception(str(e))

try:
self.net_mn_list_last_where_cond = self.get_net_masternodes_sql_where_cond()
new_hash = self.dashd_intf.get_masternode_db_query_hash(self.net_masternodes,
self.net_mn_list_last_where_cond)
if self.network_masternodes_enabled:
try:
self.net_mn_list_last_where_cond = self.get_net_masternodes_sql_where_cond()
new_hash = self.dashd_intf.get_masternode_db_query_hash(self.net_masternodes,
self.net_mn_list_last_where_cond)

if new_hash != self.last_net_masternodes_db_read_params_hash or \
self.net_masternodes_last_db_timestamp != self.dashd_intf.masternodes_last_db_timestamp:
if new_hash != self.last_net_masternodes_db_read_params_hash or \
self.net_masternodes_last_db_timestamp != self.dashd_intf.masternodes_last_db_timestamp:

if self.refresh_net_mnasternodes_thred_ref is None and self.refresh_status_thread_ref is None:
logging.info('Starting thread "refresh_net_masternodes_view_thread"')
if self.refresh_net_mnasternodes_thred_ref is None and self.refresh_status_thread_ref is None:
logging.info('Starting thread "refresh_net_masternodes_view_thread"')

self.refresh_net_mnasternodes_thred_ref = WndUtils.run_thread(
self, self.refresh_net_masternodes_view_thread, (new_hash,),
on_thread_finish=update_on_thread_finish)
except Exception as e:
logging.exception(str(e))
self.refresh_net_mnasternodes_thred_ref = WndUtils.run_thread(
self, self.refresh_net_masternodes_view_thread, (new_hash,),
on_thread_finish=update_on_thread_finish)
except Exception as e:
logging.exception(str(e))

# restore the focused row
if self.get_cur_masternode_from_net_view() != self.cur_network_masternode:
if self.cur_network_masternode not in self.net_masternodes:
self.set_cur_net_masternode(None)
old_state = self.viewNetMasternodes.selectionModel().blockSignals(True)
try:
self.set_cur_masternode_in_net_view(self.cur_network_masternode)
finally:
self.viewNetMasternodes.selectionModel().blockSignals(old_state)
# restore the focused row
if self.get_cur_masternode_from_net_view() != self.cur_network_masternode:
if self.cur_network_masternode not in self.net_masternodes:
self.set_cur_net_masternode(None)
old_state = self.viewNetMasternodes.selectionModel().blockSignals(True)
try:
self.set_cur_masternode_in_net_view(self.cur_network_masternode)
finally:
self.viewNetMasternodes.selectionModel().blockSignals(old_state)

def set_cur_cfg_masternode_modified(self):
self.refresh_cfg_masternodes_view()
Expand Down Expand Up @@ -487,6 +512,8 @@ def update_ui(self):
self.btnMnListColumns.setVisible(False)
self.btnMnActions.setVisible(False)

self.lblNavigation3.setVisible(self.network_masternodes_enabled)

if self.cur_masternode and self.cur_masternode in self.app_config.masternodes:
is_first = self.app_config.masternodes.index(self.cur_masternode) == 0
is_last = self.app_config.masternodes.index(self.cur_masternode) == len(self.app_config.masternodes) - 1
Expand Down Expand Up @@ -544,15 +571,16 @@ def update_navigation_panel(self):
mn_link = '<span>' + mn_link + '</span>'
self.lblNavigation2.setText(mn_link)

if self.current_view == Pages.PAGE_NET_MASTERNODES:
network_info_link = f'<span style="color:black">\u25B6 <b>{tab_lbl_net_masternodes}</b></span>'
else:
if self.current_view == Pages.PAGE_SINGLE_MASTERNODE and self.editing_enabled:
# don't allow changing view when in edit mode
network_info_link = f'<span style="color:gray">{tab_lbl_net_masternodes}</span>'
if self.network_masternodes_enabled:
if self.current_view == Pages.PAGE_NET_MASTERNODES:
network_info_link = f'<span style="color:black">\u25B6 <b>{tab_lbl_net_masternodes}</b></span>'
else:
network_info_link = f'<a style="text-decoration:none" href="net-masternodes">{tab_lbl_net_masternodes}</a>'
self.lblNavigation3.setText(network_info_link)
if self.current_view == Pages.PAGE_SINGLE_MASTERNODE and self.editing_enabled:
# don't allow changing view when in edit mode
network_info_link = f'<span style="color:gray">{tab_lbl_net_masternodes}</span>'
else:
network_info_link = f'<a style="text-decoration:none" href="net-masternodes">{tab_lbl_net_masternodes}</a>'
self.lblNavigation3.setText(network_info_link)

if self.current_view == Pages.PAGE_NETWORK_INFO:
network_info_link = f'<span style="color:black">\u25B6 <b>{tab_lbl_network}</b></span>'
Expand Down
7 changes: 7 additions & 0 deletions src/config_dlg.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ def setupUi(self, dialog: QDialog):
self.chbFetchDataAfterStart.setChecked(self.local_config.fetch_network_data_after_start)
self.chbShowDashFIATValue.setChecked(self.local_config.show_dash_value_in_fiat)
self.chbUIDarkMode.setChecked(self.local_config.ui_use_dark_mode)
self.chbShowNetworkMasternodes.setChecked(self.local_config.show_network_masternodes_tab)

idx = {
'CRITICAL': 0,
Expand Down Expand Up @@ -641,6 +642,12 @@ def on_chbUIDarkMode_toggled(self, checked):
if not self.disable_cfg_update:
self.local_config.ui_use_dark_mode = checked

@pyqtSlot(bool)
def on_chbShowNetworkMasternodes_toggled(self, checked):
if not self.disable_cfg_update:
self.local_config.show_network_masternodes_tab = checked
self.set_modified()

def update_ssh_ctrls_ui(self):
index = self.ssh_tunnel_widget.cboAuthentication.currentIndex()
pkey_visible = (index == 2)
Expand Down
1 change: 1 addition & 0 deletions src/main_dlg.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@ def on_action_open_settings_window_triggered(self):
if dash_network_sav != self.app_config.dash_network:
self.disconnect_hardware_wallet()
self.app_config.reset_network_dependent_dyn_params()
self.main_view.config_changed()
self.display_window_title()
self.update_edit_controls_state()
del dlg
Expand Down
7 changes: 6 additions & 1 deletion src/ui/ui_config_dlg.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Ui_ConfigDlg(object):
def setupUi(self, ConfigDlg):
ConfigDlg.setObjectName("ConfigDlg")
ConfigDlg.setWindowModality(QtCore.Qt.NonModal)
ConfigDlg.resize(625, 480)
ConfigDlg.resize(628, 480)
ConfigDlg.setModal(False)
self.verticalLayout = QtWidgets.QVBoxLayout(ConfigDlg)
self.verticalLayout.setSizeConstraint(QtWidgets.QLayout.SetDefaultConstraint)
Expand Down Expand Up @@ -228,6 +228,9 @@ def setupUi(self, ConfigDlg):
self.chbUIDarkMode = QtWidgets.QCheckBox(self.tabMisc)
self.chbUIDarkMode.setObjectName("chbUIDarkMode")
self.verticalLayout_2.addWidget(self.chbUIDarkMode)
self.chbShowNetworkMasternodes = QtWidgets.QCheckBox(self.tabMisc)
self.chbShowNetworkMasternodes.setObjectName("chbShowNetworkMasternodes")
self.verticalLayout_2.addWidget(self.chbShowNetworkMasternodes)
self.hlLogLevel = QtWidgets.QHBoxLayout()
self.hlLogLevel.setObjectName("hlLogLevel")
self.lblLogLevel = QtWidgets.QLabel(self.tabMisc)
Expand Down Expand Up @@ -297,6 +300,8 @@ def retranslateUi(self, ConfigDlg):
self.chbDontUseFileDialogs.setText(_translate("ConfigDlg", "Don\'t use file dialogs"))
self.chbUIDarkMode.setToolTip(_translate("ConfigDlg", "Use dark mode (independent of the OS settings)"))
self.chbUIDarkMode.setText(_translate("ConfigDlg", "Use UI dark mode"))
self.chbShowNetworkMasternodes.setToolTip(_translate("ConfigDlg", "Shows a tab in the main window with a list of all masternodes in the Dash network"))
self.chbShowNetworkMasternodes.setText(_translate("ConfigDlg", "Show network masternodes tab"))
self.lblLogLevel.setText(_translate("ConfigDlg", "Log level:"))
self.cboLogLevel.setItemText(0, _translate("ConfigDlg", "Critical"))
self.cboLogLevel.setItemText(1, _translate("ConfigDlg", "Error"))
Expand Down
12 changes: 11 additions & 1 deletion src/ui/ui_config_dlg.ui
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>625</width>
<width>628</width>
<height>480</height>
</rect>
</property>
Expand Down Expand Up @@ -594,6 +594,16 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="chbShowNetworkMasternodes">
<property name="toolTip">
<string>Shows a tab in the main window with a list of all masternodes in the Dash network</string>
</property>
<property name="text">
<string>Show network masternodes tab</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="hlLogLevel">
<item>
Expand Down

0 comments on commit 660a45a

Please sign in to comment.