def _AppendControl(self, sizer: wx.Sizer, label_str: str, ctrl: wx.Control): """Append a control, its label, and its info badge to the last row of the sizer. Returns the automaticaly created label and info badge (wx.StaticText for now). """ label = wx.StaticText(self, label=label_str) label.SetFont(self._label_font) rows = sizer.GetRows() sizer.Add(label, wx.GBPosition(rows, 1), wx.GBSpan(1, 1), flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT) sizer.Add(ctrl, wx.GBPosition(rows, 2), wx.GBSpan(1, 1), flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND) sizer.Add(0, self._info_length, wx.GBPosition(rows, 4), wx.GBSpan(1, 1)) info_badge = wx.StaticBitmap(self, bitmap=self._info_bitmap) info_badge.Show(False) sizer.Add(info_badge, wx.GBPosition(rows, 3), wx.GBSpan(1, 1), flag=wx.ALIGN_CENTER) self.labels[ctrl.GetId()] = label self.badges[ctrl.GetId()] = info_badge
def __init__(self): ''' Initializes the object: ''' Sizer.__init__(self) self._frozen = False self._needed_size = None self._height = 0
def _AppendSpacer(self, sizer: wx.Sizer, height: int): """Append a horizontal spacer with the given height. Note: The VGAP value still applies, i.e. there is an additional gap between the spacer and the next row. """ rows = sizer.GetRows() sizer.Add(0, height, wx.GBPosition(rows, 0), wx.GBSpan(1, 5))
def AppendModeButton(self, label: str, mode: InputMode, sizer: wx.Sizer): if get_theme('btn_border'): btn = wx.ToggleButton(self, label=label) else: btn = wx.ToggleButton(self, label=label, style=wx.BORDER_NONE) def enter_func(evt): btn.SetBackgroundColour(get_theme('btn_hover_bg')) btn.SetForegroundColour(get_theme('btn_hover_fg')) def exit_func(evt): btn.SetBackgroundColour(get_theme('btn_bg')) btn.SetForegroundColour(get_theme('btn_fg')) btn.Bind(wx.EVT_ENTER_WINDOW, enter_func) btn.Bind(wx.EVT_LEAVE_WINDOW, exit_func) btn.SetBackgroundColour(get_theme('btn_bg')) #font = wx.Font(11, wx.FONTFAMILY_MODERN, 0, 90, underline = False, faceName ="") # <- if we want to change font style btn.SetForegroundColour(get_theme('btn_fg')) #btn.SetFont (font) sizer.Add(btn, wx.SizerFlags().Align(wx.ALIGN_CENTER).Border(wx.TOP, 10)) self.btn_group.AddButton(btn, mode)
def makeSettings(self, sizer: wx.Sizer) -> None: """Populate the dialog with WX controls. @param sizer: The sizer to which to add the WX controls. @type sizer: wx.Sizer """ sHelper = gui.guiHelper.BoxSizerHelper(self, sizer=sizer) self.gesturesList = sHelper.addLabeledControl( # Translators: Label above the list of found gestures _("Select a gesture from the list"), AutoWidthColumnListCtrl, autoSizeColumn=1, # The replacement column is likely to need the most space itemTextCallable=None, style=wx.LC_REPORT | wx.LC_SINGLE_SEL ) # Translators: The label for a first column in the list of gestures self.gesturesList.InsertColumn(0, _("Gesture"), width=150) # Translators: The label for the second column in the list of gestures self.gesturesList.InsertColumn(1, _("Script description or function name")) # Translators: The label for the third column in the list of gestures self.gesturesList.InsertColumn(2, _("Category"), width=150) sizer.Fit(self) self.Center(wx.BOTH | wx.Center) # Fill in the list of available input gestures gestureDisplayText = lambda gest: "{1} ({0})".format(*getDisplayTextForGestureIdentifier(gest)) # noqa E731 do not assign a lambda expression, use a def for gesture in sorted(self.gestures, key=lambda x: x.gesture): self.gesturesList.Append(( gestureDisplayText(gesture.gesture), gesture.displayName or gesture.scriptName, gesture.category or f"[{gesture.moduleName}]" )) self.gesturesList.SetFocus() self.gesturesList.Focus(0) self.gesturesList.Select(0)
def _AppendSubtitle(self, sizer: wx.Sizer, text: str) -> wx.StaticText: self._AppendSpacer(sizer, 3) line = wx.StaticLine(self, style=wx.HORIZONTAL) sizer.Add(line, wx.GBPosition(sizer.GetRows(), 0), wx.GBSpan(1, 5), flag=wx.EXPAND) statictext = wx.StaticText(self, label=text) font = wx.Font(wx.FontInfo(9)) statictext.SetFont(font) sizer.Add(statictext, wx.GBPosition(sizer.GetRows(), 0), wx.GBSpan(1, 5), flag=wx.ALIGN_CENTER) self._AppendSpacer(sizer, 0) return statictext
def _on_remove_property(self, sizer: wx.Sizer, key: int): self.Freeze() self._property_sizer.Detach(sizer) sizer.Clear(True) del self._properties[key] self.TopLevelParent.Layout() self.Thaw() self._post_property_change()
def AppendNormalButton(self, label: str, callback, sizer: wx.Sizer, tooltip: str = None): btn = wx.Button(self, label=label) if tooltip is not None: btn.SetToolTip(tooltip) btn.Bind(wx.EVT_BUTTON, lambda _: callback()) sizer.Add(btn, wx.SizerFlags().Align(wx.ALIGN_CENTER).Border(wx.TOP, 10))
def _createSection(self, main_sizer: wx.Sizer, title: str) -> Tuple[wx.StaticBox, wx.StaticBoxSizer]: ''' Create StaticBox for options ''' staticBox = wx.StaticBox(self, label=title) staticBoxSizer = wx.StaticBoxSizer(staticBox, wx.VERTICAL) colorsSizer = wx.FlexGridSizer(cols=2) colorsSizer.AddGrowableCol(0) colorsSizer.AddGrowableCol(1) staticBoxSizer.Add(colorsSizer, flag=wx.EXPAND) main_sizer.Add(staticBoxSizer, flag=wx.EXPAND | wx.ALL, border=2) return (staticBox, colorsSizer)
def AppendNormalButton(self, label: str, callback, sizer: wx.Sizer, tooltip: str = None): if get_theme('btn_border'): btn = wx.Button(self, label=label) else: btn = wx.Button(self, label=label, style=wx.BORDER_NONE) btn.SetBackgroundColour(get_theme('btn_bg')) btn.SetForegroundColour(get_theme('btn_fg')) if tooltip is not None: btn.SetToolTip(tooltip) btn.Bind(wx.EVT_BUTTON, lambda _: callback()) sizer.Add(btn, wx.SizerFlags().Align(wx.ALIGN_CENTER).Border(wx.TOP, 10))
def __init__(self, parent: wx.Window, sizer: wx.Sizer, label: str, available: Union[List[str], None], chosen: List[str], selected: List[str], on_change_cb: Callable[[wx.Event], None], on_add_cb: Optional[Callable[[str], None]] = None, on_rm_cb: Optional[Callable[[str], None]] = None): self.available = available self.chosen = chosen self.selected = selected self.on_change_cb = on_change_cb self.on_add_cb = on_add_cb self.on_rm_cb = on_rm_cb self.cp = wx.CollapsiblePane(parent, label=label, style=wx.CP_DEFAULT_STYLE) self.cpp = self.cp.GetPane() self.localsizer = wx.BoxSizer(wx.VERTICAL) self.itemlist = wx.CheckListBox(self.cpp, choices=self.chosen) self.itemlist.Bind(wx.EVT_CHECKLISTBOX, self.checkbox_changed_cb) for sel in selected: self.itemlist.Check(self.chosen.index(sel)) self.cpp.SetSizer(self.localsizer) self.localsizer.SetSizeHints(self.cpp) self.localsizer.Add(self.itemlist, flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND | wx.GROW | wx.ALL) if self.available is not None: self.modify = wx.Button(self.cpp, label="Add/Remove...") self.modify.Bind(wx.EVT_BUTTON, self.picker) self.localsizer.Add(self.modify, flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND | wx.ALL) self.cpp.SetSizer(self.localsizer) sizer.Add(self.cp, 0, flag=wx.EXPAND | wx.ALL | wx.GROW, border=5)
def add_stretcher(sizer: wx.Sizer): temp_sizer = wx.BoxSizer(wx.VERTICAL) temp_sizer.AddSpacer(10) sizer.Add(temp_sizer, 1, wx.TOP | wx.LEFT, 10)
def makeSettings(self, sizer: wx.Sizer) -> None: """Populate the panel with settings controls. @param sizer: The sizer to which to add the settings controls. @type sizer: wx.Sizer """ self.sizer = sizer addonHelper = guiHelper.BoxSizerHelper(self, sizer=sizer) addonHelper.addItem( wx.StaticText( self, # Translators: Help message for a dialog. label= _("Select the initial sound system settings that will be set when NVDA starts:" ), style=wx.ALIGN_LEFT)) self._customVolumeSlider = addonHelper.addLabeledControl( # Translators: A setting in addon settings dialog. _("Set &custom volume level:"), nvdaControls.EnhancedInputSlider, value=config.conf[ADDON_NAME]['volume'], minValue=0, maxValue=100, size=(250, -1)) self._minVolumeSlider = addonHelper.addLabeledControl( # Translators: A setting in addon settings dialog. _("Increase the volume if it is &lower than:"), nvdaControls.EnhancedInputSlider, value=config.conf[ADDON_NAME]['minlevel'], minValue=0, maxValue=100, size=(250, -1)) self._driverChk = addonHelper.addItem( # Translators: A setting in addon settings dialog. wx.CheckBox( self, label= _("&Repeat attempts to initialize the voice synthesizer driver" ))) self._driverChk.SetValue(config.conf[ADDON_NAME]['reinit']) self._retriesCountSpin = addonHelper.addLabeledControl( # Translators: A setting in addon settings dialog. _("&Number of retries (0 - infinitely):"), nvdaControls.SelectOnFocusSpinCtrl, value=str(config.conf[ADDON_NAME]['retries']), min=0, max=10000000) self._retriesCountSpin.Show(self._driverChk.GetValue()) self._driverChk.Bind(wx.EVT_CHECKBOX, self.onDriverChk) self._switchDeviceChk = addonHelper.addItem( # Translators: A setting in addon settings dialog. wx.CheckBox(self, label=_("Switch to the default audio output &device"))) self._switchDeviceChk.SetValue(config.conf[ADDON_NAME]['switchdevice']) self._playSoundChk = addonHelper.addItem( # Translators: A setting in addon settings dialog. wx.CheckBox( self, label=_( "Play &sound when audio has been successfully turned on"))) self._playSoundChk.SetValue(config.conf[ADDON_NAME]['playsound']) sizer.Fit(self)
def AppendSeparator(self, sizer: wx.Sizer): line = wx.StaticLine(self, style=wx.LI_HORIZONTAL) sizer.Add(line, wx.SizerFlags().Expand().Border(wx.TOP, 10))
def AppendModeButton(self, label: str, mode: InputMode, sizer: wx.Sizer): btn = wx.ToggleButton(self, label=label) sizer.Add(btn, wx.SizerFlags().Align(wx.ALIGN_CENTER).Border(wx.TOP, 10)) self.btn_group.AddButton(btn, mode)
def makeSettings(self, sizer: wx.Sizer) -> None: """Populate the panel with settings controls. @param sizer: The sizer to which to add the settings controls. @type sizer: wx.Sizer """ self.sizer = sizer addonHelper = guiHelper.BoxSizerHelper(self, sizer=sizer) self.reportStatusChk = addonHelper.addItem( # Translators: This is the label for a checkbox in the settings panel. wx.CheckBox(self, label=_("&Report the status of the sound source while switching")) ) self.reportStatusChk.SetValue(config.conf[addonName]['status']) # Translators: The label of the component in the settings panel self.volumeStep = addonHelper.addLabeledControl(_("Volume level change &step:"), nvdaControls.SelectOnFocusSpinCtrl, value=str(config.conf[addonName]['step']), min=1, max=20) self.followFocusChk = addonHelper.addItem( # Translators: This is the label for a checkbox in the settings panel. wx.CheckBox(self, label=_("Change the volume of the current &application")) ) self.followFocusChk.SetValue(config.conf[addonName]['focus']) self.hideDuplicatesChk = addonHelper.addItem( # Translators: This is the label for a checkbox in the settings panel. wx.CheckBox(self, label=_("Hide audio sessions with the same &names")) ) self.hideDuplicatesChk.SetValue(config.conf[addonName]['duplicates']) procs = [s.Process.name() for s in AudioUtilities.GetAllSessions() if s.Process and s.Process.name()] self.procs = list(set(procs)) if config.conf[addonName]['duplicates'] else procs self.procs.extend([proc for proc in cfg.processes if proc not in procs]) # Translators: The label of the Checkable list in the settings panel self.hideProcesses = addonHelper.addLabeledControl(_("Hide &processes:"), nvdaControls.CustomCheckListBox, choices=self.procs) if len(self.procs)>0: self.hideProcesses.SetCheckedStrings(cfg.processes) self.hideProcesses.SetSelection(0) procButtons = addonHelper.addDialogDismissButtons(guiHelper.ButtonHelper(wx.HORIZONTAL)) self.updateProcessesButton = procButtons.addButton(self, id=wx.ID_REFRESH) self.updateProcessesButton.Bind(wx.EVT_BUTTON, self.onUpdateProcessesButton) self.clearProcessesButton = procButtons.addButton(self, id=wx.ID_CLEAR) self.clearProcessesButton.Bind(wx.EVT_BUTTON, self.onClearProcessesButton) self.advancedChk = addonHelper.addItem( # Translators: This is the label for a checkbox in the settings panel. wx.CheckBox(self, label=_("C&ontrol all available audio devices (experimental)")) ) self.advancedChk.SetValue(config.conf[addonName]['advanced']) self.advancedChk.Bind(wx.EVT_CHECKBOX, self.onAdvancedCheckbox) # Translators: The label of the Checkable list in the settings panel self.hideDevices = addonHelper.addLabeledControl(_("Hide audio &devices:"), nvdaControls.CustomCheckListBox, choices=[]) self.devs = dict(cfg.devices) self.devs.update({devices[i].id: devices[i].name for i in range(len(devices))}) for id,name in self.devs.items(): self.hideDevices.Append(name, id) if len(self.devs)>0: self.hideDevices.SetCheckedStrings([self.devs[id] for id in cfg.devices]) self.hideDevices.SetSelection(0) self.hideDevices.Show(show=self.advancedChk.GetValue()) self.devButtons = addonHelper.addDialogDismissButtons(guiHelper.ButtonHelper(wx.HORIZONTAL)) self.updateDevicesButton = self.devButtons.addButton(self, id=wx.ID_REFRESH) self.updateDevicesButton.Bind(wx.EVT_BUTTON, self.onUpdateDevicesButton) self.clearDevicesButton = self.devButtons.addButton(self, id=wx.ID_CLEAR) self.clearDevicesButton.Bind(wx.EVT_BUTTON, self.onClearDevicesButton) sizer.Show(self.devButtons.sizer, show=self.advancedChk.GetValue()) self.muteMode = addonHelper.addLabeledControl( # Translators: This is the label for a choice list in the settings panel. labelText=_("&Mute mode:"), wxCtrlClass=wx.Choice, choices=[] ) # Translators: An item in the choice list of mute modes in the settings panel self.muteMode.Append(_("Complete Mute"), 0) # Translators: An item in the choice list of mute modes in the settings panel self.muteMode.Append(_("Volume Down"), 1) self.muteMode.Select(int(not config.conf[addonName]['muteCompletely'])) self.muteMode.Bind(wx.EVT_CHOICE, self.onMuteModeChoice) self.mutePercentageSlider = addonHelper.addLabeledControl( # Translators: This is the label for a slider in the settings panel. labelText=_("Decrease the volume &by, %"), wxCtrlClass=nvdaControls.EnhancedInputSlider, value=config.conf[addonName]['mutePercentage'], minValue=1, maxValue=99, size=(250, -1) ) self.mutePercentageSlider.Show(show=not config.conf[addonName]['muteCompletely']) self.unmuteOnExitChk = addonHelper.addItem( # Translators: This is the label for a checkbox in the settings panel. wx.CheckBox(self, label=_("&Unmute all muted audio resources at NVDA shutdown")) ) self.unmuteOnExitChk.SetValue(config.conf[addonName]['unmuteOnExit']) self.defaultGesturesChk = addonHelper.addItem( # Translators: This is the label for a checkbox in the settings panel. wx.CheckBox(self, label=_("Use default &keyboard shortcuts")) ) self.defaultGesturesChk.SetValue(config.conf[addonName]['gestures']) self.defaultGesturesChk.Bind(wx.EVT_CHECKBOX, self.onGesturesCheckbox)
def AppendSeparator(self, sizer: wx.Sizer): sizer.Add((0, 10))
def _addLabelAndControlToSizer(self, sizer: wx.Sizer, label: wx.StaticText, control: wx.Control): sizer.Add(label, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, border=2) sizer.Add(control, 0, wx.ALL | wx.ALIGN_RIGHT, border=2)
def _createCheckBox(self, title: str, sizer: wx.Sizer) -> wx.CheckBox: checkBox = wx.CheckBox(self, label=title) sizer.Add(checkBox, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, border=2) return checkBox