call local variable of a function in another function - python-2.7

I have created a setting window in python where i have a few path settings which has to be one time setting.Here is the sample demo code,
import wx
import os
class SettingWindow(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title)
panel= wx.Panel(self,-1)
font = wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.BOLD)
field1 = wx.TextCtrl(panel,pos=(120,25),size=(170,20))
vsizer = wx.BoxSizer(wx.VERTICAL)
field1_sz=wx.BoxSizer(wx.HORIZONTAL)
field2_sz=wx.BoxSizer(wx.HORIZONTAL)
field1_lbl=wx.StaticText(panel,-1, label='Repo URL path:', pos=(25, 25))
field1_lbl.SetFont(font)
field1_sz.AddSpacer(50)
field1_sz.Add(field1_lbl)
field1_sz.AddSpacer(5) # put 5px of space between
field1_sz.Add(field1)
field1_sz.AddSpacer(50)
vsizer.AddSpacer(50)
vsizer.Add(field1_sz)
vsizer.AddSpacer(15)
vsizer.Add(field2_sz)
vsizer.AddSpacer(50)
btn1 = wx.Button(panel, label='Browse',pos=(300,25),size=(60,20))
btn1.Bind(wx.EVT_BUTTON, self.opendir)
def opendir(self, event):
dlg = wx.DirDialog(self, "Choose a directory:", style=wx.DD_DEFAULT_STYLE | wx.DD_NEW_DIR_BUTTON)
if dlg.ShowModal() == wx.ID_OK:
field1.SetValue("%s",dlg.GetPath())
dlg.Destroy()
class MyApp(wx.App):
def OnInit(self):
frame= SettingWindow(None,-1,'Setting Window')
frame.Show()
self.SetTopWindow(frame)
return True
app= MyApp(0)
app.MainLoop()
I want to display the path which i get from opendir in textCtrl.I am finding an error like below,
Traceback (most recent call last):
File "D:\PROJECT\SettingWindow.py", line 58, in opendir
return (field1)
NameError: global name 'field1' is not defined

use self.field1 instead of variable field1:
self.field1 = wx.TextCtrl(panel,pos=(120,25),size=(170,20))
self.field1.SetValue(dlg.GetPath())

This code works to make the TextCtrl field hidden when clicked on the checkbox
def OnCheckBox(self,event):
if self.checkbox.Value==False:
self.field.Enable(True)
else:
self.field.Enable(False)

Related

Pyside/PyQT issues while adding a custom widget to main window

I have a working program that parses data from excel with Pandas. I tried several ways to display the output dataframe in a Qtextedit, but could never get the formatting to show up correctly. Long story short, I found a workaround online with a custom widget that works nicely. The problem I've run into is that the workaround example I found will display my data correctly in its own window, but I have not been able to figure out how to add the widget to my application. It seems to be an OOP issue. I'm learning, but cannot quite grasp what the problem is.
Below is the example widget that I have tried to add to my main application.
''' ps_QAbstractTableModel_solvents.py
use PySide's QTableView and QAbstractTableModel for tabular data
sort columns by clicking on the header title
here applied to solvents commonly used in Chemistry
PySide is the official LGPL-licensed version of PyQT
tested with PySide112 and Python27/Python33 by vegaseat 15feb2013
'''
import operator
from PySide.QtCore import *
from PySide.QtGui import *
class MyWindow(QWidget):
def __init__(self, data_list, header, *args):
QWidget.__init__(self, *args)
# setGeometry(x_pos, y_pos, width, height)
self.setGeometry(300, 200, 570, 450)
self.setWindowTitle("Widget Title.")
table_model = MyTableModel(self, data_list, header)
table_view = QTableView()
table_view.setModel(table_model)
# set font
font = QFont("Courier New", 14)
table_view.setFont(font)
# set column width to fit contents (set font first!)
table_view.resizeColumnsToContents()
# enable sorting
table_view.setSortingEnabled(True)
layout = QVBoxLayout(self)
layout.addWidget(table_view)
self.setLayout(layout)
class MyTableModel(QAbstractTableModel):
def __init__(self, parent, mylist, header, *args):
QAbstractTableModel.__init__(self, parent, *args)
self.mylist = mylist
self.header = header
def rowCount(self, parent):
return len(self.mylist)
def columnCount(self, parent):
return len(self.mylist[0])
def data(self, index, role):
if not index.isValid():
return None
elif role != Qt.DisplayRole:
return None
return self.mylist[index.row()][index.column()]
def headerData(self, col, orientation, role):
if orientation == Qt.Horizontal and role == Qt.DisplayRole:
return self.header[col]
return None
def sort(self, col, order):
"""sort table by given column number col"""
self.emit(SIGNAL("layoutAboutToBeChanged()"))
self.mylist = sorted(self.mylist,
key=operator.itemgetter(col))
if order == Qt.DescendingOrder:
self.mylist.reverse()
self.emit(SIGNAL("layoutChanged()"))
# the solvent data ...
header = ['Solvent Name', ' BP (deg C)', ' MP (deg C)', ' Density (g/ml)']
# use numbers for numeric data to sort properly
data_list = [
('ACETIC ACID', 117.9, 16.7, 1.049),
('ACETIC ANHYDRIDE', 140.1, -73.1, 1.087),
('ACETONE', 56.3, -94.7, 0.791),
('ACETONITRILE', 81.6, -43.8, 0.786),
('ANISOLE', 154.2, -37.0, 0.995),
('BENZYL ALCOHOL', 205.4, -15.3, 1.045),
('BENZYL BENZOATE', 323.5, 19.4, 1.112),
('BUTYL ALCOHOL NORMAL', 117.7, -88.6, 0.81),
('BUTYL ALCOHOL SEC', 99.6, -114.7, 0.805),
]
app = QApplication([])
win = MyWindow(data_list, header)
win.show()
app.exec_()
Below is what I have attempted while trying to add the widget to my PyQT application.
#from PySide.QtCore import *
import sys
from PySide import QtCore, QtGui
import operator
##############################THIS IS THE EXAMPLE###############
# from PySide.QtCore import *
# from PySide.QtGui import *
class MyWindow(QtGui.QWidget): #changed from QWidget to QtGui.QWidget because of import difference.
def __init__(self, data_list, header, *args):
QtGui.QWidget.__init__(self, *args) #added QtGui. to QWidget..
# setGeometry(x_pos, y_pos, width, height)
self.setGeometry(300, 200, 570, 450)
self.setWindowTitle("Widget Title.")
table_model = MyTableModel(self, data_list, header)
table_view = QtGui.QTableView() #Added QtGui. to QTableView..
table_view.setModel(table_model)
# set font
font = QtGui.QFont("Courier New", 14) #Added QtGui. to QFont..
table_view.setFont(font)
# set column width to fit contents (set font first!)
table_view.resizeColumnsToContents()
# enable sorting
table_view.setSortingEnabled(True)
layout = QtGui.QVBoxLayout(self) #Added QtGui. to QVBox..
layout.addWidget(table_view)
self.setLayout(layout)
class MyTableModel(QtCore.QAbstractTableModel): #changed from QAbstractTableModel to QtCore.QAbstractTableModel
def __init__(self, parent, mylist, header, *args):
QtCore.QAbstractTableModel.__init__(self, parent, *args) #changed from QAbstract to QtCore.QAbstract
self.mylist = mylist
self.header = header
def rowCount(self, parent):
return len(self.mylist)
def columnCount(self, parent):
return len(self.mylist[0])
def data(self, index, role):
if not index.isValid():
return None
elif role != QtCore.Qt.DisplayRole: #Added QtCore. to Qt.Display..
return None
return self.mylist[index.row()][index.column()]
def headerData(self, col, orientation, role):
if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole: #Added QtCore. to Qt.Horiz.. and Qt.Display..
return self.header[col]
return None
def sort(self, col, order):
"""sort table by given column number col"""
self.emit(QtCore.SIGNAL("layoutAboutToBeChanged()")) #Added QtCore. to SIGNAL..
self.mylist = sorted(self.mylist,
key=operator.itemgetter(col))
if order == QtCore.Qt.DescendingOrder: #added QtCore. to Qt.Descending...
self.mylist.reverse()
self.emit(QtCore.SIGNAL("layoutChanged()"))
# the solvent data ...
header = ['Solvent Name', ' BP (deg C)', ' MP (deg C)', ' Density (g/ml)']
# use numbers for numeric data to sort properly
data_list = [
('ACETIC ACID', 117.9, 16.7, 1.049),
('ACETIC ANHYDRIDE', 140.1, -73.1, 1.087),
('ACETONE', 56.3, -94.7, 0.791),
('ACETONITRILE', 81.6, -43.8, 0.786),
('ANISOLE', 154.2, -37.0, 0.995),
('BENZYL ALCOHOL', 205.4, -15.3, 1.045),
('BENZYL BENZOATE', 323.5, 19.4, 1.112),
('BUTYL ALCOHOL NORMAL', 117.7, -88.6, 0.81),
('BUTYL ALCOHOL SEC', 99.6, -114.7, 0.805),
]
# app = QApplication([])
# win = MyWindow(data_list, header)
# win.show()
# app.exec_()
###############################END EXAMPLE############################
######################THIS IS THE GUI FILE######################
class Ui_mainForm(object):
def setupUi(self, mainForm):
mainForm.setObjectName("mainForm")
mainForm.resize(1075, 643)
self.pushButton = QtGui.QPushButton(mainForm)
self.pushButton.setGeometry(QtCore.QRect(510, 40, 93, 31))
self.pushButton.setObjectName("pushButton")
self.lineEdit = QtGui.QLineEdit(mainForm)
self.lineEdit.setGeometry(QtCore.QRect(40, 40, 451, 31))
self.lineEdit.setObjectName("lineEdit")
self.lineEdit_2 = QtGui.QLineEdit(mainForm)
self.lineEdit_2.setGeometry(QtCore.QRect(40, 90, 451, 31))
self.lineEdit_2.setObjectName("lineEdit_2")
self.pushButton_2 = QtGui.QPushButton(mainForm)
self.pushButton_2.setGeometry(QtCore.QRect(510, 90, 93, 31))
self.pushButton_2.setObjectName("pushButton_2")
self.procButton = QtGui.QPushButton(mainForm)
self.procButton.setGeometry(QtCore.QRect(260, 130, 93, 28))
self.procButton.setObjectName("procButton")
self.placeholderWidget = QtGui.QWidget (MyWindow(data_list, header)) ############Trying to activate the custom class in gui.. was mainForm
self.placeholderWidget.setGeometry(QtCore.QRect(20, 179, 1011, 451))
self.placeholderWidget.setObjectName("placeholderWidget")
self.placeholderWidget.setAutoFillBackground(True)
self.retranslateUi(mainForm)
QtCore.QMetaObject.connectSlotsByName(mainForm)
def retranslateUi(self, mainForm):
mainForm.setWindowTitle(QtGui.QApplication.translate("mainForm", "Parser", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton.setText(QtGui.QApplication.translate("mainForm", "Browse", None, QtGui.QApplication.UnicodeUTF8))
self.lineEdit.setPlaceholderText(QtGui.QApplication.translate("mainForm", "Select report", None, QtGui.QApplication.UnicodeUTF8))
self.lineEdit_2.setPlaceholderText(QtGui.QApplication.translate("mainForm", "Select log file", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton_2.setText(QtGui.QApplication.translate("mainForm", "Browse", None, QtGui.QApplication.UnicodeUTF8))
self.procButton.setText(QtGui.QApplication.translate("mainForm", "Process files", None, QtGui.QApplication.UnicodeUTF8))
self.placeholderWidget.setToolTip(QtGui.QApplication.translate("mainForm", "THIS IS TOOLTIP", None, QtGui.QApplication.UnicodeUTF8))
###############THIS IS THE MAIN PROGRAM####################
class MainDialog(QtGui.QDialog, Ui_mainForm, MyWindow, MyTableModel): #Attempting to add custom widget to main window. getting error "Internal C++ object (PySide.QtGui.QWidget) already deleted."
def __init__(self, parent=None):
super(MainDialog, self).__init__(parent)
self.setupUi(self)
app = QtGui.QApplication(sys.argv) #Changed from QApplication to QtGui.QApplication because of different import method from seperate gui file.
mainForm = MainDialog()
mainForm.show()
# win = MyWindow(data_list, header) #These two lines display the custom example widget outside of the main window.
# win.show() #These two lines display the custom example widget outside of the main window.
app.exec_()
##########END MAIN PROGRAM##########
# app = QtGui.QApplication([]) #Added QtGui. to QApplication
# win = MyWindow(data_list, header) #Now to somehow add this to main window............
# win.show()
# app.exec_()
I have not been able make the custom widget appear in the main application. Additionally I am getting an error message at execution. Below is the full error message.
C:\Python27\python.exe C:/Users/Dirk/PycharmProjects/QwidgetTest_fromExample/Attempt-incorporate-example2.py
Traceback (most recent call last):
File "C:/Users/Dirk/PycharmProjects/QwidgetTest_fromExample/Attempt-incorporate-example2.py", line 143, in <module>
mainForm = MainDialog()
File "C:/Users/Dirk/PycharmProjects/QwidgetTest_fromExample/Attempt-incorporate-example2.py", line 139, in __init__
self.setupUi(self)
File "C:/Users/Dirk/PycharmProjects/QwidgetTest_fromExample/Attempt-incorporate-example2.py", line 116, in setupUi
self.placeholderWidget.setGeometry(QtCore.QRect(20, 179, 1011, 451))
RuntimeError: Internal C++ object (PySide.QtGui.QWidget) already deleted.
Process finished with exit code 1

How to delete Entry text when disabling and re-enabling widget

Is there any way that i can delete the user input in an entry widget when it's state is disabled and re-enabled? The user input stays as is, I would like to it without having to add a button event.
from Tkinter import *
class Interface():
def __init__(self, window):
frame = Frame(window)
frame.pack()
self.hopLabel = Label(frame, text="Number:", anchor=E)
self.hopLabel.grid(row=0, column=0, sticky=EW)
options = range(0,6)
options.append("Other")
self.variable = StringVar(frame)
self.variable.set(options[0])
self.options = OptionMenu(frame, self.variable, *options, command=self.this)
self.options.grid(row=0, column=2, sticky=EW)
self.button = Button(frame,text = "Print Value",width=20,command = self.printit(self.variable.get()))
self.button.grid(row=1)
self.otherEntry = Entry(frame, state=DISABLED)
self.otherEntry.grid(row=0, column=1, sticky=EW)
def this(self, value):
if value == "Other":
self.otherEntry.config(state=NORMAL)
else:
self.otherEntry.config(state=DISABLED)
def printit(self,value):
print value
if __name__ == "__main__":
root = Tk()
app = Interface(root)
root.mainloop()
In order to save space, i didn't add the function that prints the value of the "Other" option. My question again is: Is there anyway to delete the value in the entry box when the state of the widget goes from DISABLED to NORMAL without having to press a button?
To delete the text in an entry widget when the state is disabled, you simply need to set the state to normal first and then call the delete method:
def this(self, value):
if value == "Other":
self.otherEntry.config(state=NORMAL)
self.otherEntry.delete(0, "end")
...

Tkinter Instance has no attributes

I am having an error against an innocent wish to play an audio in audio player using Tkinter. Error is:
Traceback (most recent call last):
File "C:\Users\Mudassar\workspace\Player\main_gui.py", line 43, in
<module>
app = GUI(playerobj)
File "C:\Users\Mudassar\workspace\Player\main_gui.py", line 10, in
__init__
self.create_button_frame()
AttributeError: GUI instance has no attribute 'create_button_frame'
My Code main_gui.py is:
from Tkinter import *
import tkFileDialog
import player
class GUI:
def __init__(self, player):
self.player = player
player.parent = player
self.root = Tk()
self.create_button_frame()
self.create_bottom_frame()
self.root.mainloop()
def create_button_frame(self):
buttonframe = Frame(self.root)
self.playicon = PhotoImage(file='../icons/play.gif')
self.stopicon = PhotoImage(file='../icons/stop.gif')
self.playbtn=Button(buttonframe, text ='play', image=self.playicon,
borderwidth=0, command=self.toggle_play_pause)
self.playbtn.image = self.playicon
self.playbtn.grid(row=3, column=3)
buttonframe.grid(row=1, pady=4, padx=5)
def create_bottom_frame(self):
bottomframe = Frame(self.root)
add_fileicon = PhotoImage(file='../icons/add_file.gif')
add_filebtn = Button(bottomframe, image=add_fileicon, borderwidth=0,
text='Add File', command = self.add_file)
add_filebtn.image = add_fileicon
add_filebtn.grid(row=2, column=1)
bottomframe.grid(row=2, sticky='w', padx=5)
def toggle_play_pause(self):
if self.playbtn['text'] == 'play':
self.playbtn.config(text='stop', image=self.stopicon)
self.player.start_play_thread()
elif self.playbtn['text'] == 'stop':
self.playbtn.config(text = 'play', image=self.playicon)
self.player.pause()
def add_file(self):
tfile = tkFileDialog.askopenfilename(filetypes = [('All supported',
'.mp3 .wav .ogg'), ('All files', '*.*')])
self.currentTrack = tfile
if __name__=='__main__':
playerobj = player.Player()
app = GUI(playerobj)
My Player button functions in another (as they have nothing to do with error)are:
import pyglet
from threading import Thread
class Player():
parent = None
def play_media(self):
try:
self.myplayer=pyglet.media.Player()
self.source = pyglet.media.load(self.parent.currentTrack)
self.myplayer.queue(self.source)
self.myplayer.queue(self.source)
self.myplayer.play()
pyglet.app.run()
except:
pass
def start_play_thread(self):
player_thread = Thread(target=self.play_media)
player_thread.start()
def pause(self):
try:
self.myplayer.pause()
self.paused = True
except: pass
Please help.
Seems like your problem is indentation. Your create_button_frame() function is not an attribute of the class GUI, it is a global function. Indent all the functions taking parameter self four spaces to the right. Then they will be methods of your class GUI.

NameError: global name 'Ui_DiabeticRetinopathy3' is not defined

I am working on an multiform application where I am able to link the (form1 to form2 and form3), (form2 to form3) but when I am trying to create a link from (form2 to form1) and from3 to (form2 or form1) link to the backward page it is giving me the error NameError: global name is not defined.
Here is my calling methods code where form3 can call form4 but form4 does not call form3;
Code : form3.py
class Ui_DiabeticRetinopathy3(QtGui.QMainWindow):
def __init__(self,parent=None):
super(Ui_DiabeticRetinopathy3, self).__init__(parent)
self.imgPreProc = imagePreProcessor()
#self.imgPreProc = imagePreProcessor()
self.setupUi(self)
def setupUi(self, DiabeticRetinopathy):
DiabeticRetinopathy.setObjectName(_fromUtf8("DiabeticRetinopathy"))
DiabeticRetinopathy.resize(672, 608)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(_fromUtf8("../im0003.jpg")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
DiabeticRetinopathy.setWindowIcon(icon)
self.pushButton_6 = QtGui.QPushButton(self.verticalLayoutWidget_2)
self.pushButton_6.setStyleSheet(_fromUtf8("background-color: rgb(191, 191, 191);\n"
"font: 75 8pt \"Verdana\";"))
self.pushButton_6.setObjectName(_fromUtf8("pushButton_6"))
self.verticalLayout_2.addWidget(self.pushButton_6)
self.pushButton_6.clicked.connect(self.on_clicked_hemo)
def on_clicked_hemo(self):
self.obj4=Ui_DiabeticRetinopathy4(self)
self.obj4.show()
Code : form4.py
class Ui_DiabeticRetinopathy4(QtGui.QMainWindow):
def __init__(self,parent=None):
super(Ui_DiabeticRetinopathy4, self).__init__(parent)
self.imgPreProc = imagePreProcessor()
#self.obj3=Ui_DiabeticRetinopathy3()
#self.imgPreProc = imagePreProcessor()
self.setupUi(self)
def setupUi(self, DiabeticRetinopathy):
DiabeticRetinopathy.setObjectName(_fromUtf8("DiabeticRetinopathy"))
DiabeticRetinopathy.resize(672, 608)
DiabeticRetinopathy.setWindowIcon(icon)
self.pushButton_6 = QtGui.QPushButton(self.verticalLayoutWidget)
self.pushButton_6.setObjectName(_fromUtf8("pushButton_6"))
self.verticalLayout_2.addWidget(self.pushButton_6)
#self.pushButton_6.clicked.connect(self.on_clicked_micro)#####
def on_clicked_micro(self):
self.obj3=Ui_DiabeticRetinopathy3(self)
#self.obj3.setupUi(self)
self.obj3.show()
Any help will be greatly appreciated!
NameError: name 'Ui_DiabeticRetinopathy3' is not defined
If it possibility, please check your import module. Have you import form3.py into form4.py?
In form4.py, It should be possibility like this in head;
from form3 import *
from form3 import Ui_DiabeticRetinopathy3

how to print TextEntryDialog value in list box?

I want to know how I can use the value from a text entry dialog
from the def textentry function in the def __init__ function of the
class such as in the wx.ListBox where asd is printing on the right
side.
Here is the code :
import wx
class main_window(wx.Frame):
def SetOutput(self, output):
self.output = output
def OnSelChanged(self, event):
"""
If an output function is defined, we try to print some
informative, interesting and thought-provoking stuff to it.
If it has a __doc__ string, we print it. If it's a function or
unbound class method, we attempt to find the python source.
"""
item = event.GetItem()
def textentry(self, event):
dlg = wx.TextEntryDialog(self, 'Enter URL','URL Parsing')
dlg.SetValue("Default")
if dlg.ShowModal() == wx.ID_OK:
self.SetStatusText('You entered: %s\n' % dlg.GetValue())
return (dlg.GetValue())
def opendir(self, event):
dlg = wx.DirDialog(self, "Choose a directory:", style=wx.DD_DEFAULT_STYLE | wx.DD_NEW_DIR_BUTTON)
if dlg.ShowModal() == wx.ID_OK:
self.SetStatusText('You selected: %s\n' % dlg.GetPath())
dlg.Destroy()
def OnExit(self,e):
self.Close(True)
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, title=title, size=(500, 500),style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)
status=self.CreateStatusBar()
splitter = wx.SplitterWindow(self, style=wx.SP_3D)
splitter.SetMinimumPaneSize(1)
menubar=wx.MenuBar()
first=wx.Menu()
second=wx.Menu()
third=wx.Menu()
first.Append(106,"a","a")
first.Append(104,"Open","Browse")
first.Append(100,"anything","yup")
first.Append(105,"Exit","Quit")
second.Append(101,"s","s")
menubar.Append(first,"File")
menubar.Append(second,"Tool")
menubar.Append(third,"Contact us")
self.SetMenuBar(menubar)
self.Bind(wx.EVT_MENU, self.textentry, id=106)
self.Bind(wx.EVT_MENU, self.OnExit, id=105)
self.Bind(wx.EVT_MENU, self.opendir, id=104)
self.tree = wx.TreeCtrl(splitter,1, style=wx.TR_HIDE_ROOT|wx.TR_HAS_BUTTONS)
"""
If an output function is defined, we try to print some
informative, interesting and thought-provoking stuff to it.
If it has a __doc__ string, we print it. If it's a function or
unbound class method, we attempt to find the python source.
"""
root = self.tree.AddRoot('wd')
os = self.tree.AppendItem(root, 'sa')
cl = self.tree.AppendItem(root, 'a')
self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelChanged, self.tree)
cunt=wx.ListBox(splitter, -1, (100,100), (100,100), 'asd', wx.LB_SINGLE)
cunt.SetSelection(1)
splitter.SplitVertically(self.tree, cunt,200)
splitter.SetSashPosition(180, True)
self.Show(True)
"""
If an output function is defined, we try to print some
informative, interesting and thought-provoking stuff to it.
If it has a __doc__ string, we print it. If it's a function or
unbound class method, we attempt to find the python source.
"""
class App(wx.App):
def OnInit(self):
frame = main_window(None, 'S2A vulnerability Scanner')
return True
if __name__ == '__main__':
app = App(0)
app.MainLoop()
You just need to insert the input value into the list box.
use self.cunt to replace the cunt
in textentry use self.cunt.Insert(val, 0) to insert the input value into list
Try following code:
import wx
class main_window(wx.Frame):
def SetOutput(self, output):
self.output = output
def OnSelChanged(self, event):
"""
If an output function is defined, we try to print some
informative, interesting and thought-provoking stuff to it.
If it has a __doc__ string, we print it. If it's a function or
unbound class method, we attempt to find the python source.
"""
item = event.GetItem()
def textentry(self, event):
dlg = wx.TextEntryDialog(self, 'Enter URL','URL Parsing')
dlg.SetValue("Default")
if dlg.ShowModal() == wx.ID_OK:
val = dlg.GetValue()
self.SetStatusText('You entered: %s\n' % val)
self.cunt.Insert(val, 0)
return (dlg.GetValue())
def opendir(self, event):
dlg = wx.DirDialog(self, "Choose a directory:", style=wx.DD_DEFAULT_STYLE | wx.DD_NEW_DIR_BUTTON)
if dlg.ShowModal() == wx.ID_OK:
self.SetStatusText('You selected: %s\n' % dlg.GetPath())
dlg.Destroy()
def OnExit(self,e):
self.Close(True)
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, title=title, size=(500, 500),style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)
status=self.CreateStatusBar()
splitter = wx.SplitterWindow(self, style=wx.SP_3D)
splitter.SetMinimumPaneSize(1)
menubar=wx.MenuBar()
first=wx.Menu()
second=wx.Menu()
third=wx.Menu()
first.Append(106,"a","a")
first.Append(104,"Open","Browse")
first.Append(100,"anything","yup")
first.Append(105,"Exit","Quit")
second.Append(101,"s","s")
menubar.Append(first,"File")
menubar.Append(second,"Tool")
menubar.Append(third,"Contact us")
self.SetMenuBar(menubar)
self.Bind(wx.EVT_MENU, self.textentry, id=106)
self.Bind(wx.EVT_MENU, self.OnExit, id=105)
self.Bind(wx.EVT_MENU, self.opendir, id=104)
self.tree = wx.TreeCtrl(splitter,1, style=wx.TR_HIDE_ROOT|wx.TR_HAS_BUTTONS)
"""
If an output function is defined, we try to print some
informative, interesting and thought-provoking stuff to it.
If it has a __doc__ string, we print it. If it's a function or
unbound class method, we attempt to find the python source.
"""
root = self.tree.AddRoot('wd')
os = self.tree.AppendItem(root, 'sa')
cl = self.tree.AppendItem(root, 'a')
self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelChanged, self.tree)
self.cunt=wx.ListBox(splitter, -1, (100,100), (100,100), 'asd', wx.LB_SINGLE)
self.cunt.SetSelection(1)
splitter.SplitVertically(self.tree, self.cunt,200)
splitter.SetSashPosition(180, True)
self.Show(True)
"""
If an output function is defined, we try to print some
informative, interesting and thought-provoking stuff to it.
If it has a __doc__ string, we print it. If it's a function or
unbound class method, we attempt to find the python source.
"""
class App(wx.App):
def __init__(self, redirect):
wx.App.__init__(self, redirect)
def OnInit(self):
frame = main_window(None, 'S2A vulnerability Scanner')
return True
if __name__ == '__main__':
app = App(0)
app.MainLoop()