0
ここでコードは、ユーザーが選択した文字列の一部を書き込みます。各イベントの後、TextCtrlは、クリップボードにテキストをコピーする時間が来るまで、文字列のもう1つの部分を取得します。それはうまく動作しますが、コードに繰り返しが多すぎるのでエレガントではありません。ComboBoxイベントとRadioBoxイベントの両方で単一のdefを記述することは可能ですか?
import wx
import pyperclip
class Ementor(wx.Frame):
def __init__(self, parent, title):
super(Ementor, self).__init__(parent, title = title,size = (500,300))
self.InitUI()
def InitUI(self):
pnl = wx.Panel(self)
menubar=wx.MenuBar()
filem=wx.Menu()
clearmenuitem = filem.Append(wx.NewId(), "Clea&r","Clear TextBox")
self.Bind(wx.EVT_MENU, self.onClear, clearmenuitem)
exitmenuitem = filem.Append(wx.NewId(), "Exi&t", "Bye bye")
self.Bind(wx.EVT_MENU, self.onExit, exitmenuitem)
editm=wx.Menu()
copymenuitem = editm.Append(wx.NewId(), "&Copy", "Copy String")
self.Bind(wx.EVT_MENU, self.onCopy, copymenuitem)
helpm=wx.Menu()
helpmenuitem = helpm.Append(wx.NewId(), "&About","Details")
self.Bind(wx.EVT_MENU, self.onHelp, helpmenuitem)
menubar.Append(filem, '&File')
menubar.Append(editm, '&Edit')
menubar.Append(helpm, '&Help')
self.SetMenuBar(menubar)
# Campos de preenchimento da ementa
lblList = ['Processo Administrativo Sancionador. ','Processo Administrativo Contencioso. ','Processo Administrativo Simplificado. ']
self.rbox = wx.RadioBox(pnl, label = 'Tipo', pos = (10,10), choices = lblList, majorDimension = 3, style = wx.RA_SPECIFY_ROWS)
self.rbox.Bind(wx.EVT_RADIOBOX,self.onRadioBox)
statusAnalise = ['Julgamento Originario. ','Julgamento Recursal. ']
self.rbox1 = wx.RadioBox(pnl, label = 'Estágio da Análise', pos = (10,120), choices=statusAnalise, majorDimension = 2, style = wx.RA_SPECIFY_ROWS)
self.rbox1.Bind(wx.EVT_RADIOBOX,self.onRadioBox1)
tipoJulgamento = ['Recurso conhecido e provido. ','Recurso conhecido e nao provido. ','Recurso nao conhecido']
self.combo = wx.ComboBox(pnl, choices=tipoJulgamento, pos=(10,200))
self.combo.Bind(wx.EVT_COMBOBOX, self.onCombo)
tipoProcedimento = ['Fiscalizacao ordinaria - PAF. ','Fiscalizacao Extraordinaria. ']
self.combo1 = wx.ComboBox(pnl, choices=tipoProcedimento, pos=(10,230))
self.combo1.Bind(wx.EVT_COMBOBOX, self.onCombo1)
#Área de concatenação
self.t3 = wx.TextCtrl(pnl,pos=(310,10),size = (180,170),style = wx.TE_MULTILINE)
self.Centre()
self.Show(True)
# Funcoes para eventos
def onRadioBox(self, e):
rb = self.rbox.GetStringSelection()
**self.t3.AppendText(str(rb).upper())** #here set text to
def onRadioBox1(self, e):
rb1 = self.rbox1.GetStringSelection()
**self.t3.AppendText(str(rb1).upper())** #here
def onClear(self, e):
self.t3.SetValue('')
def onExit(self, e):
self.Destroy()
def onCopy(self, e):
pyperclip.copy(self.t3.GetValue())
def onCombo(self, e):
cbx = self.combo.GetValue()
**self.t3.AppendText(str(cbx).upper())** #here
def onCombo1(self, e):
cbx1 = self.combo1.GetValue()
**self.t3.AppendText(str(cbx1).upper())** #here
def onHelp(self, e):
msgbox = wx.MessageBox('Feito por ²David Gesrob ® 2016-09-04', 'About...', wx.ICON_INFORMATION | wx.STAY_ON_TOP)
ex = wx.App()
Ementor(None,'Ementor')
ex.MainLoop()
パーフェクトでそれを使用することができます。出来た。ありがとうございました! –