Skip to content

Custom watch attributes #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion addon/globalPlugins/objWatcher/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@
from gui import guiHelper
from gui import nvdaControls

import wx
import wx.adv


addonHandler.initTranslation()


class ObjWatcherPanel(gui.settingsDialogs.SettingsPanel):
# Translators: This is the label for the ObjWatcher settings panel.
title = _("ObjWatcher")

def makeSettings(self, settingsSizer):
def makeSettings(self, settingsSizer: wx.BoxSizer):
settingsSizerHelper = guiHelper.BoxSizerHelper(self, sizer=settingsSizer)
# Translators: This is the label of a SpinCtrl in the ObjWatcher settings panel
# This option controls the interval of the Watcher timer (in milliseconds)
Expand All @@ -28,5 +32,49 @@ def makeSettings(self, settingsSizer):
initial=int(config.conf["objWatcher"]["interval"])
)

self._appendWatchAttributesList(settingsSizerHelper)

def _appendWatchAttributesList(self, settingsSizerHelper: guiHelper.BoxSizerHelper) -> None:
# Translators: This is the label of a EditableListBox in the ObjWatcher settings panel
# This list custom the attributes of the object to be watched
watchAttributesLabelText = _("Watch attributes")
self.watchAttributesList: wx.adv.EditableListBox = wx.adv.EditableListBox(
self,
label=watchAttributesLabelText,
)
self.watchAttributesList.SetStrings(config.conf["objWatcher"]["watchAttributes"].split(","))
self.watchAttributesList.SetLabel(watchAttributesLabelText)
editBtn: wx.BitmapButton = self.watchAttributesList.GetEditButton()
editBtn.SetLabel(editBtn.GetToolTipText())
newBtn: wx.BitmapButton = self.watchAttributesList.GetNewButton()
newBtn.SetLabel(newBtn.GetToolTipText())
delBtn: wx.BitmapButton = self.watchAttributesList.GetDelButton()
delBtn.SetLabel(delBtn.GetToolTipText())
upBtn: wx.BitmapButton = self.watchAttributesList.GetUpButton()
upBtn.SetLabel(upBtn.GetToolTipText())
downBtn: wx.BitmapButton = self.watchAttributesList.GetDownButton()
downBtn.SetLabel(downBtn.GetToolTipText())

attrLst: wx.ListCtrl = self.watchAttributesList.GetListCtrl()
attrLst.MoveBeforeInTabOrder(editBtn.GetParent())
attrLst.Bind(wx.EVT_LIST_BEGIN_LABEL_EDIT, self.onBeginEditingForListCtrl)
attrLst.SetLabel(watchAttributesLabelText)
attrLst.EnableCheckBoxes(True)
attrLst.Select(0)

settingsSizerHelper.addItem(self.watchAttributesList)

def onIgnoreDialogCharHookEvent(self, evt: wx.KeyEvent):
evt.DoAllowNextEvent()

def onBeginEditingForListCtrl(self, evt: wx.ListEvent):
evtObj: wx.ListCtrl = evt.GetEventObject()
editCtrl = evtObj.GetEditControl()
if isinstance(editCtrl, wx.TextCtrl):
editCtrl.Bind(wx.EVT_CHAR_HOOK, handler=self.onIgnoreDialogCharHookEvent)
else:
evt.Skip()

def onSave(self):
config.conf["objWatcher"]["interval"] = self.intervalEdit.Value
config.conf["objWatcher"]["watchAttributes"] = ",".join(self.watchAttributesList.GetStrings())