def CreateCtrl(self, ctrlType, init = True): szr = self.sizer szr.Clear(True) if ctrlType == 0: ctrl = eg.SpinNumCtrl( self, -1, self.initValue, **self.kwargs ) ctrl.numCtrl.Bind(wx.EVT_RIGHT_UP, self.OnRclick) ctrl.numCtrl.SetToolTipString(eg.text.General.smartSpinTooltip) if init: ctrl.SetValue(self.value) else: ctrl = wx.TextCtrl( self, -1, str(self.value), ) ctrl.Bind(wx.EVT_RIGHT_UP, self.OnRclick) ctrl.SetToolTipString(eg.text.General.smartSpinTooltip) if not init: ctrl.SetValue(("","{eg.result}","{eg.event.payload}","")[ctrlType]) szr.Add(ctrl, 1, wx.ALIGN_CENTER_VERTICAL | wx.EXPAND) szr.Layout() self.UpdateWidth(ctrl) return ctrl
def add_cec_item(self, com_port, adapter_name, hdmi_port, use_avr, poll_interval, _ # scan_type ): self.lock.acquire() self.Freeze() index = self.InsertStringItem(self.GetItemCount(), adapter_name) self.SetStringItem(index, 1, com_port) self.SetStringItem(index, 2, '') self.SetStringItem(index, 3, '') self.SetStringItem(index, 4, '') com_item = self.GetItem(index, 0) name_item = self.GetItem(index, 1) hdmi_item = self.GetItem(index, 2) avr_item = self.GetItem(index, 3) poll_item = self.GetItem(index, 4) hdmi_port_ctrl = eg.SpinIntCtrl(self, -1, hdmi_port, min=1, max=99) hdmi_item.SetWindow(hdmi_port_ctrl) avr_ctrl = wx.CheckBox(self, -1, '') avr_ctrl.SetValue(use_avr) avr_item.SetWindow(avr_ctrl) poll_ctrl = eg.SpinNumCtrl(self, -1, poll_interval, min=0.1, max=5.0, increment=0.1) poll_item.SetWindow(poll_ctrl) # if scan_type is None: # com_item.SetBackgroundColour((255, 255, 75)) # name_item.SetBackgroundColour((255, 255, 75)) # hdmi_port_ctrl.SetBackgroundColour((255, 255, 75)) # hdmi_item.SetBackgroundColour((255, 255, 75)) # avr_item.SetBackgroundColour((255, 255, 75)) # # elif scan_type is False: # com_item.SetBackgroundColour((255, 0, 0)) # name_item.SetBackgroundColour((255, 0, 0)) # hdmi_item.SetBackgroundColour((255, 0, 0)) # avr_item.SetBackgroundColour((255, 0, 0)) self.SetItem(com_item) self.SetItem(name_item) self.SetItem(hdmi_item) self.SetItem(avr_item) self.SetItem(poll_item) self.Thaw() self.Update() self.lock.release()
def Configure(self, muteVol=0.0, delay=5.0, step=5.0): panel = eg.ConfigPanel(self) muteVolCtrl = eg.SpinNumCtrl(panel, -1, muteVol, max=100.0, fractionWidth=0) delayCtrl = eg.SpinIntCtrl(panel, -1, delay, min=1, max=50) stepCtrl = eg.SpinIntCtrl(panel, -1, step, min=1, max=10) panel.AddLabel("Volume Level to set for mute (default 0):") panel.AddCtrl(muteVolCtrl) panel.AddLabel("delay per step (milliseconds) on Mute/Unmute") panel.AddCtrl(delayCtrl) panel.AddLabel("step size on mute/unmute") panel.AddCtrl(stepCtrl) while panel.Affirmed(): panel.SetResult(muteVolCtrl.GetValue(), delayCtrl.GetValue(), stepCtrl.GetValue())
def Configure(self, targetVol=50.0, delay=5.0, step=5.0): panel = eg.ConfigPanel(self) volumeCtrl = eg.SpinNumCtrl(panel, -1, targetVol, max=100.0, fractionWidth=0) delayCtrl = eg.SpinIntCtrl(panel, -1, delay, min=1, max=50) stepCtrl = eg.SpinIntCtrl(panel, -1, step, min=1, max=10) panel.AddLabel("Volume to set when applying *mute*") panel.AddCtrl(volumeCtrl) panel.AddLabel("delay per step (milliseconds) for mute/unmute") panel.AddCtrl(delayCtrl) panel.AddLabel("step size for mute/unmute") panel.AddCtrl(stepCtrl) while panel.Affirmed(): panel.SetResult(volumeCtrl.GetValue(), delayCtrl.GetValue(), stepCtrl.GetValue())
def Configure(self, muteVol=0.0, delay=5.0, step=5.0): panel = eg.ConfigPanel(self) muteVolCtrl = eg.SpinNumCtrl(panel, -1, muteVol, max=100.0, fractionWidth=0) delayCtrl = eg.SpinIntCtrl(panel, -1, delay, min=1, max=50) stepCtrl = eg.SpinIntCtrl(panel, -1, step, min=1, max=10) panel.AddLabel(self.text.label_volume) panel.AddCtrl(muteVolCtrl) panel.AddLabel(self.text.label_delay) panel.AddCtrl(delayCtrl) panel.AddLabel(self.text.label_step) panel.AddCtrl(stepCtrl) while panel.Affirmed(): panel.SetResult(muteVolCtrl.GetValue(), delayCtrl.GetValue(), stepCtrl.GetValue())
def Configure(self, targetVol=50.0, delay=5.0, step=5.0): panel = eg.ConfigPanel(self) volumeCtrl = eg.SpinNumCtrl(panel, -1, targetVol, max=100.0, fractionWidth=0) delayCtrl = eg.SpinIntCtrl(panel, -1, delay, min=1, max=50) stepCtrl = eg.SpinIntCtrl(panel, -1, step, min=1, max=10) panel.AddLabel("Volume Level:") panel.AddCtrl(volumeCtrl) panel.AddLabel("delay per step (milliseconds)") panel.AddCtrl(delayCtrl) panel.AddLabel("step (adjust vol by this much on each loop)") panel.AddCtrl(stepCtrl) while panel.Affirmed(): panel.SetResult(volumeCtrl.GetValue(), delayCtrl.GetValue(), stepCtrl.GetValue())
def Configure( self, program="", winName=None, winClass=None, childName=None, childClass=None, matchNum=1, includeInvisible=False, timeout=0, stop=STOP_IF_NOT_FOUND ): panel = eg.ConfigPanel(resizable=True) text = self.text searchOnlyFrontmost = False if stop is None: program = "" matchNum = 1 includeInvisible = False timeout = 0 stop = 0 searchOnlyFrontmost = True self.dialog = panel.dialog self.lastHwnd = None self.lastPid = None self.hideOnDrag = True # the "only search for the frontmost" checkbox cbOnlyFrontmost = wx.CheckBox(panel, -1, text.onlyFrontmost) def OnSearchOnlyFrontmostCheckbox(event): flag = not cbOnlyFrontmost.IsChecked() cbIncludeInvisible.Enable(flag) if not flag: stopMacroCtrl_1.SetValue(False) stopMacroCtrl_2.SetValue(False) stopMacroCtrl_1.Enable(flag) stopMacroCtrl_2.Enable(flag) waitCtrl.Enable(flag) for checkBox, textCtrl in self.options[:-1]: checkBox.Enable(flag) textCtrl.Enable(flag and checkBox.GetValue()) self.options[-1][0].Enable(flag) self.options[-1][1].Enable(flag) event.Skip() cbOnlyFrontmost.Bind(wx.EVT_CHECKBOX, OnSearchOnlyFrontmostCheckbox) # the IncludeInvisible checkbox cbIncludeInvisible = wx.CheckBox(panel, -1, text.invisible_box) def OnIncludeInvisibleCheckbox(event): hwnd = self.lastHwnd self.tree.includeInvisible = cbIncludeInvisible.IsChecked() self.tree.Refresh() self.tree.SelectHwnd(hwnd) event.Skip() cbIncludeInvisible.Bind(wx.EVT_CHECKBOX, OnIncludeInvisibleCheckbox) # the stop-macro choice id_1 = wx.NewId() stopMacroCtrl_1 = wx.CheckBox(panel, id_1, text.stopMacro[0]) id_2 = wx.NewId() stopMacroCtrl_2 = wx.CheckBox(panel, id_2, text.stopMacro[1]) if stop == STOP_IF_NOT_FOUND: stopMacroCtrl_1.SetValue(True) stopMacroCtrl_2.Enable(False) elif stop == STOP_IF_FOUND: stopMacroCtrl_2.SetValue(True) stopMacroCtrl_1.Enable(False) def OnStopMacroCtrl(event): # if cbOnlyFrontmost.IsChecked(): id = event.GetId() flag = event.IsChecked() if id == id_1: stopMacroCtrl_2.Enable(not flag) if flag: stopMacroCtrl_2.SetValue(False) else: stopMacroCtrl_1.Enable(not flag) if flag: stopMacroCtrl_1.SetValue(False) event.Skip() stopMacroCtrl_1.Bind(wx.EVT_CHECKBOX, OnStopMacroCtrl) stopMacroCtrl_2.Bind(wx.EVT_CHECKBOX, OnStopMacroCtrl) finderTool = eg.WindowDragFinder( panel, self.OnFinderToolLeftClick, self.OnFinderTool ) self.finderTool = finderTool # the HideOnDrag checkbox cbHideOnDrag = wx.CheckBox(panel, -1, text.hide_box) cbHideOnDrag.SetValue(Config.hideOnDrag) def OnHideOnDragCheckbox(dummyEvent): Config.hideOnDrag = cbHideOnDrag.IsChecked() cbHideOnDrag.Bind(wx.EVT_CHECKBOX, OnHideOnDragCheckbox) # the tree to display processes and windows self.tree = eg.WindowTree(panel, includeInvisible=includeInvisible) cbIncludeInvisible.SetValue(includeInvisible) # the refresh button refreshButton = wx.Button(panel, -1, text.refresh_btn) def OnButton(dummyEvent): hwnd = self.lastHwnd self.tree.Refresh() self.tree.SelectHwnd(hwnd) refreshButton.Bind(wx.EVT_BUTTON, OnButton) # construction of the layout with sizers dragSizer = wx.StaticBoxSizer( wx.StaticBox(panel, -1, "Drag Finder"), wx.VERTICAL ) dragSizer.Add(finderTool, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.BOTTOM, 4) dragSizer.Add(cbHideOnDrag) leftTopSizer = wx.BoxSizer(wx.VERTICAL) leftTopSizer.Add(cbOnlyFrontmost, 0, wx.BOTTOM, 5) leftTopSizer.Add(cbIncludeInvisible, 0, wx.BOTTOM, 5) leftTopSizer.Add(stopMacroCtrl_1, 0, wx.BOTTOM, 5) leftTopSizer.Add(stopMacroCtrl_2, 0, wx.BOTTOM, 5) topSizer = wx.BoxSizer(wx.HORIZONTAL) topSizer.Add(leftTopSizer, 1, wx.EXPAND) topSizer.Add(dragSizer) sizer1 = wx.GridBagSizer(vgap=4, hgap=4) sizer1.SetEmptyCellSize((0, 0)) sizer1.Add(self.tree, (0, 0), (1, 5), wx.EXPAND) sizer1.Add(refreshButton, (1, 4), (2, 1), wx.ALIGN_TOP | wx.ALIGN_RIGHT) self.options = options = [] def Wrapper(textCtrl, checkBox): def OnCheckBox(event): textCtrl.Enable(checkBox.GetValue()) event.Skip() return OnCheckBox def MakeLine(line, checkBoxText, value): checkBox = wx.CheckBox(panel, -1, checkBoxText) sizer1.Add(checkBox, (line, 0), (1, 1), wx.ALIGN_CENTER_VERTICAL) textCtrl = wx.TextCtrl(panel, -1, size=(20, -1)) if value is not None: checkBox.SetValue(True) textCtrl.SetValue(value) else: textCtrl.Enable(False) sizer1.Add(textCtrl, (line, 1), (1, 3), wx.EXPAND) checkBox.Bind(wx.EVT_CHECKBOX, Wrapper(textCtrl, checkBox)) options.append((checkBox, textCtrl)) line += 1 MakeLine(1, text.options[0], program) MakeLine(2, text.options[1], winName) MakeLine(3, text.options[2], winClass) MakeLine(4, text.options[3], childName) MakeLine(5, text.options[4], childClass) line = 6 numMatchCB = wx.CheckBox(panel, -1, text.matchNum1) numMatchCB.SetValue(bool(matchNum)) sizer1.Add(numMatchCB, (line, 0), (1, 1), wx.ALIGN_CENTER_VERTICAL) numMatchCtrl = eg.SpinIntCtrl(panel, -1, matchNum or 1, 1) sizer1.Add(numMatchCtrl, (line, 1), (1, 1), wx.EXPAND) sizer1.Add( wx.StaticText(panel, -1, text.matchNum2), (line, 2), (1, 3), wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT ) numMatchCB.Bind(wx.EVT_CHECKBOX, Wrapper(numMatchCtrl, numMatchCB)) options.append((numMatchCB, numMatchCtrl)) line += 1 # the wait parameter waitCtrl = eg.SpinNumCtrl(panel) waitCtrl.SetValue(timeout) sizer1.Add( panel.StaticText(text.wait1), (line, 0), (1, 1), wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT ) sizer1.Add( waitCtrl, (line, 1), (1, 1), wx.ALIGN_CENTER_VERTICAL | wx.EXPAND ) sizer1.Add( panel.StaticText(text.wait2), (line, 2), (1, 3), wx.ALIGN_CENTER_VERTICAL ) line += 1 sizer1.Add((1, 1), (line, 0)) sizer1.AddGrowableCol(2, 100) sizer1.AddGrowableRow(0, 100) #sizer1.SetItemMinSize(options[0][1], 300, -1) # group the main lines together panel.sizer.AddMany([ (topSizer, 0, wx.EXPAND), ((5, 5), ), (sizer1, 1, wx.EXPAND), ]) # re-assign the test button def OnTestButton(dummyEvent): args = GetResult()[:-2] # we don't need timeout and stopMacro hwnds = eg.WindowMatcher(*args)() dialog = TestDialog(panel.dialog, hwnds) dialog.ShowModal() dialog.Destroy() panel.dialog.buttonRow.testButton.Bind(wx.EVT_BUTTON, OnTestButton) @eg.LogIt def GetResult(): resultList = [] for checkBox, textCtrl in options: if not checkBox.IsChecked(): resultList.append(None) else: resultList.append(textCtrl.GetValue()) resultList.append(self.tree.includeInvisible) resultList.append(waitCtrl.GetValue()) if stopMacroCtrl_1.IsChecked(): resultList.append(STOP_IF_NOT_FOUND) elif stopMacroCtrl_2.IsChecked(): resultList.append(STOP_IF_FOUND) else: resultList.append(STOP_NEVER) return resultList hwnds = eg.WindowMatcher( program, winName, winClass, childName, childClass, matchNum, includeInvisible, )() if matchNum is not None and len(hwnds): self.lastHwnd = hwnds[0] self.tree.SelectHwnd(self.lastHwnd) if searchOnlyFrontmost: cbOnlyFrontmost.SetValue(True) OnSearchOnlyFrontmostCheckbox(wx.CommandEvent()) while True: self.tree.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelectionChanged) affirmed = panel.Affirmed() self.tree.Unbind(wx.EVT_TREE_SEL_CHANGED) if not affirmed: break if cbOnlyFrontmost.IsChecked(): panel.SetResult( None, None, None, None, None, None, None, None, None ) else: panel.SetResult(*GetResult())
def SpinNumCtrl(self, value=0, *args, **kwargs): return eg.SpinNumCtrl(self, -1, value, *args, **kwargs)
def __init__(self, parent): wx.Panel.__init__(self, parent) # --- components self.keepFullRB = wx.RadioButton(self, -1, text.keepFullMsg1, style=wx.RB_GROUP) self.keepFullRB.SetValue(parseArgs.searchMode == SM_KEEP_FULL) self.keepFullRB.Bind(wx.EVT_RADIOBUTTON, self.onParseRBChange) guiComponents.append(self.keepFullRB) self.parseNumValRB = wx.RadioButton(self, -1, text.parseNumVal1) self.parseNumValRB.SetValue( parseArgs.searchMode == SM_FIND_NUMBER) self.parseNumValRB.Bind(wx.EVT_RADIOBUTTON, self.onParseRBChange) guiComponents.append(self.parseNumValRB) self.grabBetweenCharRB = wx.RadioButton( self, -1, text.grabBetweenChar1) self.grabBetweenCharRB.SetValue( parseArgs.searchMode == SM_GET_SUBSTR_BY_CHAR) self.grabBetweenCharRB.Bind(wx.EVT_RADIOBUTTON, self.onParseRBChange) guiComponents.append(self.grabBetweenCharRB) self.searchChar1Ctl = wx.TextCtrl(self, size=(30, -1)) self.searchChar1Ctl.SetValue(parseArgs.searchChar1) guiComponents.append(self.searchChar1Ctl) self.searchChar2Ctl = wx.TextCtrl(self, size=(30, -1)) self.searchChar2Ctl.SetValue(parseArgs.searchChar2) guiComponents.append(self.searchChar2Ctl) self.grabBetweenPosRB = wx.RadioButton(self, -1, text.grabBetweenPos1) self.grabBetweenPosRB.SetValue( parseArgs.searchMode == SM_GET_SUBSTR_BY_POS) self.grabBetweenPosRB.Bind(wx.EVT_RADIOBUTTON, self.onParseRBChange) guiComponents.append(self.grabBetweenPosRB) self.searchPos1Ctl = eg.SpinNumCtrl(self, value=parseArgs.searchPos1, min=-9999, max=9999, fractionWidth=0, integerWidth=4) guiComponents.append(self.searchPos1Ctl) self.searchPos2Ctl = eg.SpinNumCtrl(self, value=parseArgs.searchPos2, min=-9999, max=9999, fractionWidth=0, integerWidth=4) guiComponents.append(self.searchPos2Ctl) self.applyRegexRB = wx.RadioButton(self, -1, text.applyRegex1) self.applyRegexRB.SetValue( parseArgs.searchMode == SM_APPLY_REGEX) self.applyRegexRB.Bind(wx.EVT_RADIOBUTTON, self.onParseRBChange) guiComponents.append(self.applyRegexRB) self.regexCtl = wx.TextCtrl(self, size=(200, -1)) self.regexCtl.SetValue(parseArgs.searchRegex) guiComponents.append(self.regexCtl) # --- layout gridBagSizer = wx.GridBagSizer(hgap=5, vgap=3) rowcount = 0 gridBagSizer.Add(self.keepFullRB, (rowcount, 0), span=(1, 2), flag=wx.ALIGN_CENTER_VERTICAL) rowcount += 1 gridBagSizer.Add(wx.Size(12, 0), (rowcount, 0)) gridBagSizer.Add(wx.StaticText(self, -1, text.keepFullMsg2), (rowcount, 1), flag=wx.ALIGN_CENTER_VERTICAL) rowcount += 1 gridBagSizer.Add(wx.Size(0, 5), (rowcount, 1)) rowcount += 1 gridBagSizer.Add(self.parseNumValRB, (rowcount, 0), span=(1, 2), flag=wx.ALIGN_CENTER_VERTICAL) rowcount += 1 gridBagSizer.Add(wx.StaticText(self, -1, text.parseNumVal2), (rowcount, 1), flag=wx.ALIGN_CENTER_VERTICAL) rowcount += 1 gridBagSizer.Add(wx.StaticText(self, -1, text.multipleFindings), (rowcount, 1), flag=wx.ALIGN_CENTER_VERTICAL) rowcount += 1 gridBagSizer.Add(wx.Size(0, 5), (rowcount, 1)) rowcount += 1 innerFGSizer = wx.FlexGridSizer(rows=1, hgap=5, vgap=5) innerFGSizer.Add(self.grabBetweenCharRB, flag=wx.ALIGN_CENTER_VERTICAL) innerFGSizer.Add(self.searchChar1Ctl, flag=wx.ALIGN_CENTER_VERTICAL) innerFGSizer.Add(wx.StaticText(self, -1, text.grabBetweenChar2), flag=wx.ALIGN_CENTER_VERTICAL) innerFGSizer.Add(self.searchChar2Ctl, flag=wx.ALIGN_CENTER_VERTICAL) gridBagSizer.Add(innerFGSizer, (rowcount, 0), span=(1, 2), flag=wx.ALIGN_CENTER_VERTICAL) rowcount += 1 gridBagSizer.Add(wx.StaticText(self, -1, text.grabBetweenChar3), (rowcount, 1), flag=wx.ALIGN_CENTER_VERTICAL) rowcount += 1 gridBagSizer.Add(wx.StaticText(self, -1, text.grabBetweenChar4), (rowcount, 1), flag=wx.ALIGN_CENTER_VERTICAL) rowcount += 1 gridBagSizer.Add(wx.StaticText(self, -1, text.multipleFindings), (rowcount, 1), flag=wx.ALIGN_CENTER_VERTICAL) rowcount += 1 gridBagSizer.Add(wx.Size(0, 5), (rowcount, 1)) rowcount += 1 innerFGSizer = wx.FlexGridSizer(rows=1, hgap=5, vgap=5) innerFGSizer.Add(self.grabBetweenPosRB, flag=wx.ALIGN_CENTER_VERTICAL) innerFGSizer.Add(self.searchPos1Ctl, flag=wx.ALIGN_CENTER_VERTICAL) innerFGSizer.Add(wx.StaticText(self, -1, text.grabBetweenPos2), flag=wx.ALIGN_CENTER_VERTICAL) innerFGSizer.Add(self.searchPos2Ctl, flag=wx.ALIGN_CENTER_VERTICAL) gridBagSizer.Add(innerFGSizer, (rowcount, 0), span=(1, 2), flag=wx.ALIGN_CENTER_VERTICAL) rowcount += 1 gridBagSizer.Add(wx.StaticText(self, -1, text.grabBetweenPos3), (rowcount, 1), flag=wx.ALIGN_CENTER_VERTICAL) rowcount += 1 gridBagSizer.Add(wx.StaticText(self, -1, text.grabBetweenPos4), (rowcount, 1), flag=wx.ALIGN_CENTER_VERTICAL) rowcount += 1 gridBagSizer.Add(wx.StaticText(self, -1, text.grabBetweenPos5), (rowcount, 1), flag=wx.ALIGN_CENTER_VERTICAL) rowcount += 1 gridBagSizer.Add(wx.Size(0, 5), (rowcount, 1)) rowcount += 1 innerFGSizer = wx.FlexGridSizer(rows=1, hgap=5, vgap=5) innerFGSizer.Add(self.applyRegexRB, flag=wx.ALIGN_CENTER_VERTICAL) innerFGSizer.Add(self.regexCtl, flag=wx.ALIGN_CENTER_VERTICAL) gridBagSizer.Add(innerFGSizer, (rowcount, 0), span=(1, 2), flag=wx.ALIGN_CENTER_VERTICAL) rowcount += 1 gridBagSizer.Add(wx.StaticText(self, -1, text.applyRegex2), (rowcount, 1), flag=wx.ALIGN_CENTER_VERTICAL) rowcount += 1 gridBagSizer.Add(wx.Size(0, 5), (rowcount, 1)) rowcount += 1 sBoxSizer = wx.StaticBoxSizer( wx.StaticBox(self, -1, text.parseLog), wx.VERTICAL) sBoxSizer.Add(gridBagSizer, proportion=1, flag=wx.EXPAND) self.SetSizer(sBoxSizer)