Related
I have implemented QUndoStack with QGraphicScene and everything is working like charm with individual QGraphicItem movement/rotation, but when it comes to the multi-items movement, I couldn't find any way to do so, since I didn't find any flag/signal that will be emitted after all selected item position has been changed [ NOT DURING].
Here is a sketch code that will represent my goals.
import sys
from typing import Dict
from PyQt5.QtCore import Qt, QPoint
from PyQt5.QtGui import QPen, QColor, QBrush
from PyQt5.QtWidgets import QApplication, QGraphicsItem, QMainWindow, QGraphicsScene, QGraphicsView, \
QGraphicsEllipseItem, QUndoStack, QUndoCommand
import random
class CustomUndoRedoStack(QUndoStack):
instance = None
def __init__(self):
if not CustomUndoRedoStack.instance:
CustomUndoRedoStack.instance = self
super(CustomUndoRedoStack, self).__init__()
#staticmethod
def get_instance():
return CustomUndoRedoStack.instance
class MovingMultiItemsCommand(QUndoCommand):
def __init__(self, new_items_pos: Dict[QGraphicsItem], old_items_pos: Dict[QGraphicsItem]):
super(MovingMultiItemsCommand, self).__init__()
self.new_items_pos = new_items_pos
self.old_items_pos = old_items_pos
CustomUndoRedoStack.get_instance().push(self)
def undo(self) -> None:
for item in self.old_items_pos:
item.setPos(self.old_items_pos[item])
super(MovingMultiItemsCommand, self).undo()
def redo(self) -> None:
for item in self.new_items_pos:
item.setPos(self.new_items_pos[item])
super(MovingMultiItemsCommand, self).redo()
class CustomQGraphicsEllipseItem(QGraphicsEllipseItem):
def __init__(self, x, y):
super(CustomQGraphicsEllipseItem, self).__init__(x, y, 20, 20)
self.setFlag(QGraphicsItem.ItemIsSelectable)
self.setFlag(QGraphicsItem.ItemIsMovable)
self.setPen(QPen(QColor(255, 128, 0), 0.5, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
self.setBrush(QBrush(QColor(255, 128, 20, 128)))
class MyGraphicsView(QGraphicsView):
def __init__(self):
super(MyGraphicsView, self).__init__()
self.setDragMode(QGraphicsView.RubberBandDrag)
self._isPanning = False
self._mousePressed = False
self.setCacheMode(QGraphicsView.CacheBackground)
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
class MyGraphicsScene(QGraphicsScene):
def __init__(self):
super(MyGraphicsScene, self).__init__()
self.setBackgroundBrush(QBrush(QColor(50, 50, 50)))
self.old_items_pos = {}
self.new_items_pos = {}
# ------- I want something like the following -----------------------------
def selected_items_before_change(self):
for item in self.selectedItems():
self.old_items_pos[item] = item.pos()
def selected_items_after_change(self):
for item in self.selectedItems():
self.new_items_pos[item] = item.pos()
def selected_item_position_changed(self):
"""
This method must be triggered only and only once after selected items position has been changed (NOT WHILE)
"""
MovingMultiItemsCommand(self.new_items_pos, self.old_items_pos)
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
class MyMainWindow(QMainWindow):
def __init__(self):
super(MyMainWindow, self).__init__()
self.setWindowTitle("Test")
self.resize(800, 600)
self.gv = MyGraphicsView()
self.gv.setScene(MyGraphicsScene())
self.setCentralWidget(self.gv)
self.populate()
def populate(self):
scene = self.gv.scene()
for i in range(500):
x = random.randint(0, 1000)
y = random.randint(0, 1000)
rect = CustomQGraphicsEllipseItem(x, y)
scene.addItem(rect)
def main():
app = QApplication(sys.argv)
ex = MyMainWindow()
ex.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
C++ answers will be good as well, but Python is preferable :)
The mouse movement of selectable items is handled by the graphics scene, starting with its mousePressEvent() and ending with the corresponding mouseReleaseEvent().
This means that you can create a QUndoCommand based on the selected items (if any) after the default implementation of mouse button press/release is called. This will be valid for any movement, including when just one item has been moved.
class ItemMovedUndoCommand(QUndoCommand):
def __init__(self, oldPositions, newPositions):
if len(oldPositions) == 1:
pos = oldPositions.values()[0]
text = 'Item moved to {}x{}'.format(
pos.x(), pos.y())
else:
text = '{} items moved'.format(len(oldPositions))
super().__init__(text)
self.oldPositions = oldPositions
self.newPositions = newPositions
def redo(self):
for item, pos in self.newPositions.items():
item.setPos(pos)
def undo(self):
for item, pos in self.oldPositions.items():
item.setPos(pos)
class CustomQGraphicsEllipseItem(QGraphicsEllipseItem):
def __init__(self, x, y):
super(CustomQGraphicsEllipseItem, self).__init__(-10, -10, 20, 20)
self.setPos(x, y)
self.setFlag(QGraphicsItem.ItemIsSelectable)
self.setFlag(QGraphicsItem.ItemIsMovable)
self.setPen(QPen(QColor(255, 128, 0),
0.5, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
self.setBrush(QBrush(QColor(255, 128, 20, 128)))
class MyGraphicsView(QGraphicsView):
def __init__(self):
super(MyGraphicsView, self).__init__()
self.setDragMode(QGraphicsView.RubberBandDrag)
self._isPanning = False
self._mousePressed = False
self.setCacheMode(QGraphicsView.CacheBackground)
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
class MyGraphicsScene(QGraphicsScene):
itemsMoved = pyqtSignal(object, object)
def __init__(self):
super(MyGraphicsScene, self).__init__()
self.setBackgroundBrush(QBrush(QColor(50, 50, 50)))
self.oldPositions = {}
def mousePressEvent(self, event):
super().mousePressEvent(event)
if event.button() == Qt.LeftButton:
self.oldPositions = {i:i.pos() for i in self.selectedItems()}
def mouseReleaseEvent(self, event):
super().mouseReleaseEvent(event)
if event.button() == Qt.LeftButton and self.oldPositions:
self.itemsMoved.emit(self.oldPositions,
{i:i.pos() for i in self.oldPositions.keys()})
self.oldPositions = {}
class MyMainWindow(QMainWindow):
def __init__(self):
super(MyMainWindow, self).__init__()
self.setWindowTitle("Test")
self.resize(800, 600)
self.gv = MyGraphicsView()
self.scene = MyGraphicsScene()
self.gv.setScene(self.scene)
self.setCentralWidget(self.gv)
toolBar = QToolBar()
self.addToolBar(Qt.TopToolBarArea, toolBar)
self.undoStack = QUndoStack()
toolBar.addAction(self.undoStack.createUndoAction(self.scene))
toolBar.addAction(self.undoStack.createRedoAction(self.scene))
self.populate()
self.scene.itemsMoved.connect(self.itemsMoved)
def itemsMoved(self, oldPositions, newPositions):
self.undoStack.push(ItemMovedUndoCommand(oldPositions, newPositions))
def populate(self):
scene = self.gv.scene()
for i in range(500):
x = random.randint(0, 1000)
y = random.randint(0, 1000)
rect = CustomQGraphicsEllipseItem(x, y)
scene.addItem(rect)
After an event is triggered, I want to change the font of a specific tab to use a bold font, rather than non-bold.
qtabwidget.tabs[4].setFontWeight(Bold)
How to do this?
One possible solution is to use a QProxyStyle:
import sys
from PySide2 import QtCore, QtGui, QtWidgets
class TabBarStyle(QtWidgets.QProxyStyle):
def drawControl(self, element, option, painter, widget=None):
index = -1
if element == QtWidgets.QStyle.CE_TabBarTab:
if isinstance(widget, TabBar):
for i in widget.fonts.keys():
if widget.tabRect(i) == option.rect:
index = i
break
if index > -1:
painter.save()
painter.setFont(widget.fonts[index])
super(TabBarStyle, self).drawControl(element, option, painter, widget)
if index > -1:
painter.restore()
class TabBar(QtWidgets.QTabBar):
def __init__(self, parent=None):
super(TabBar, self).__init__(parent)
self._fonts = dict()
#property
def fonts(self):
return self._fonts
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.tab_widget = QtWidgets.QTabWidget()
self.setCentralWidget(self.tab_widget)
self.tab_bar = TabBar()
self.tabbar_style = TabBarStyle(self.tab_bar.style())
self.tab_bar.setStyle(self.tabbar_style)
self.tab_widget.setTabBar(self.tab_bar)
self.tab_widget.addTab(QtWidgets.QWidget(), "Foo")
self.tab_widget.addTab(QtWidgets.QWidget(), "Bar")
self.tab_widget.addTab(QtWidgets.QWidget(), "Baz")
font = self.tab_widget.font()
font.setBold(True)
self.tab_bar.fonts[1] = font
self.tab_bar.update()
def main():
app = QtWidgets.QApplication(sys.argv)
app.setStyle("fusion")
w = MainWindow()
w.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
I have tried to boil down my program to be as simple as possible and still be functional. First is my UI file with the tabs that I want. It has a graph in the Control tab and I want the play button to start the plot.
When I start it I can't get the graph to show up. any help would be appreciated.
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(800, 600)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.tabWidget = QtGui.QTabWidget(self.centralwidget)
self.tabWidget.setGeometry(QtCore.QRect(0, 0, 801, 421))
self.tabWidget.setStyleSheet(_fromUtf8(""))
self.tabWidget.setObjectName(_fromUtf8("tabWidget"))
self.tab_4 = QtGui.QWidget()
self.tab_4.setObjectName(_fromUtf8("tab_4"))
self.tabWidget.addTab(self.tab_4, _fromUtf8(""))
self.tab_2 = QtGui.QWidget()
self.tab_2.setObjectName(_fromUtf8("tab_2"))
self.tabWidget.addTab(self.tab_2, _fromUtf8(""))
self.tab = QtGui.QWidget()
self.tab.setObjectName(_fromUtf8("tab"))
self.pushButton = QtGui.QPushButton(self.tab)
self.pushButton.setGeometry(QtCore.QRect(290, 340, 75, 31))
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(_fromUtf8("play_button.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.pushButton.setIcon(icon)
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.pushButton_2 = QtGui.QPushButton(self.tab)
self.pushButton_2.setGeometry(QtCore.QRect(460, 340, 75, 31))
icon1 = QtGui.QIcon()
icon1.addPixmap(QtGui.QPixmap(_fromUtf8("pause_button.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.pushButton_2.setIcon(icon1)
self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
self.pushButton_3 = QtGui.QPushButton(self.tab)
self.pushButton_3.setGeometry(QtCore.QRect(630, 340, 75, 31))
icon2 = QtGui.QIcon()
icon2.addPixmap(QtGui.QPixmap(_fromUtf8("resume_button.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.pushButton_3.setIcon(icon2)
self.pushButton_3.setObjectName(_fromUtf8("pushButton_3"))
self.graphicsView = QtGui.QGraphicsView(self.tab)
self.graphicsView.setGeometry(QtCore.QRect(205, 1, 591, 341))
self.graphicsView.setObjectName(_fromUtf8("graphicsView"))
self.tabWidget.addTab(self.tab, _fromUtf8(""))
self.tab_3 = QtGui.QWidget()
self.tab_3.setObjectName(_fromUtf8("tab_3"))
self.tabWidget.addTab(self.tab_3, _fromUtf8(""))
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setObjectName(_fromUtf8("statusbar"))
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
self.tabWidget.setCurrentIndex(2)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_4), _translate("MainWindow", "Calibration", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), _translate("MainWindow", "Material", None))
self.pushButton.setText(_translate("MainWindow", "Start Plot", None))
self.pushButton_2.setText(_translate("MainWindow", "Pause", None))
self.pushButton_3.setText(_translate("MainWindow", "Resume", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _translate("MainWindow", "Control", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_3), _translate("MainWindow", "Operator", None))
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
MainWindow = QtGui.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
The second is my graphing class which does work when I make a gui with code, but I would like to be able to plug it into a program with a ui file.
import sys
import time
import datetime
from PyQt4 import QtCore, QtGui, uic
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import pyqtgraph as pg
import random
from workingraspitab2 import Ui_MainWindow
class Main(QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
super(Main, self).__init__(parent)
self.setupUi(self)
self.graphicsView = QtGui.QStackedWidget()
self.login_widget = LoginWidget(self)
self.graphicsView.addWidget(self.login_widget)
self.pushButton.clicked.connect(self.plotter)#the play button
self.curve = self.login_widget.it1
self.curve2 =self.login_widget.it2
def plotter(self):
self.data =[0]
self.data2 = [0]
self.timer = QtCore.QTimer()
self.timer.timeout.connect(self.updater)
self.timer.start(0)
print self.data
def updater(self):
self.data.append(self.data[-1]+10*(0.5-random.random()))
self.curve.setData(self.data, pen=pg.mkPen('b', width=1))
self.data2.append(self.data2[-1]+0.1*(0.5-random.random()))
self.curve2.setData(self.data2, pen=pg.mkPen('r', width=1))
print self.data
class LoginWidget(QtGui.QWidget):
def __init__(self, parent=None):
super(LoginWidget, self).__init__(parent)
pg.setConfigOption('background', 'w')
pg.setConfigOption('foreground', 'k')
self.plot = pg.PlotWidget(title='Force and Extension vs. Time')
p1 = self.plot.plotItem
p2 = pg.ViewBox()
p1.showAxis('right')
p1.scene().addItem(p2)
p1.getAxis('right').linkToView(p2)
p2.setXLink(p1)
self.plot.getAxis('bottom').setLabel('Time', units='s')
self.plot.getAxis('left').setLabel('Force', units='lbf', color="#0000ff")
p1.getAxis('right').setLabel('Extension', units='in.', color="#ff0000")
def updateViews():
p2.setGeometry(p1.vb.sceneBoundingRect())
p2.linkedViewChanged(p1.vb, p2.XAxis)
updateViews()
p1.vb.sigResized.connect(updateViews)
self.it1 = p1.plot()
self.it2 = pg.PlotCurveItem()
p2.addItem(self.it2)
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
window = Main()
window.show()
sys.exit(app.exec_())
Had to put everything in the Main class to get it to work. I was hoping for a more elegant solution. I still cant get the background or foreground to change, but it is working and here is the code:
class Main(QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
super(Main, self).__init__(parent)
self.setupUi(self)
pv = self.graphicsView
pv.setTitle('Force and Extension vs. Time')
pg.setConfigOption('background', 'w')
pg.setConfigOption('foreground', 'k')
p1 = pv.plotItem
p2 = pg.ViewBox()
p1.showAxis('right')
p1.scene().addItem(p2)
p1.getAxis('right').linkToView(p2)
p2.setXLink(p1)
pv.getAxis('bottom').setLabel('Time', units='s')
pv.getAxis('left').setLabel('Force', units='lbf', color="#0000ff")
p1.getAxis('right').setLabel('Extension', units='in.', color="#ff0000")
def updateViews():
p2.setGeometry(p1.vb.sceneBoundingRect())
p2.linkedViewChanged(p1.vb, p2.XAxis)
updateViews()
p1.vb.sigResized.connect(updateViews)
self.it1 = p1.plot()
self.it2 = pg.PlotCurveItem()
p2.addItem(self.it2)
self.pushButton.clicked.connect(self.plotter)
self.pushButton_2.clicked.connect(lambda: self.timer.stop())
self.pushButton_3.clicked.connect(self.timer_start)
self.curve = self.it1
self.curve2 = self.it2
I want to set value into sheet using thread.
import time
import wx
from wx.lib import sheet
from threading import Thread
EVT_RESULT_ID = wx.NewId()
def EVT_RESULT(win, func):
win.Connect(-1, -1, EVT_RESULT_ID, func)
class ResultEvent(wx.PyEvent):
def __init__(self, data):
wx.PyEvent.__init__(self)
self.SetEventType(EVT_RESULT_ID)
self.data = data
class TestThread(Thread):
def __init__(self, wxObject,sheet):
Thread.__init__(self)
self.wxObject = wxObject
self.sheet=sheet
self.start()
def run(self):
self.sheet.sheetload()
wx.PostEvent(self.wxObject, ResultEvent(self.sheet))
class MySheet(sheet.CSheet):
def __init__(self, parent):
sheet.CSheet.__init__(self, parent)
self.SetNumberRows(100)
self.SetNumberCols(30)
def sheetload(self):
self.SetNumberRows(200)
self.SetNumberCols(30)
self.EnableEditing(False)
for i in range(200):
for j in range(30):
self.SetCellValue(i,j,str(i))
class Newt(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None,-1, "Tutorial")
self.box = wx.BoxSizer(wx.VERTICAL)
toolbar2 = wx.ToolBar(self, wx.TB_HORIZONTAL | wx.TB_TEXT,size = (1000, 40))
self.show_btn =wx.Button(toolbar2, label="show")
self.show_btn.Enable(True)
self.Bind(wx.EVT_BUTTON, self.onShow,self.show_btn)
toolbar2.AddControl(self.show_btn)
self.box.Add((5,5) , 0)
self.box.Add(toolbar2)
self.box.Add((5,10) , 0)
toolbar2.Realize()
self.notebook = wx.Notebook(self, -1, style=wx.RIGHT)
self.box.Add(self.notebook, 1, wx.EXPAND)
self.Maximize(True)
self.SetSizer(self.box)
EVT_RESULT(self, self.updateDisplay)
def onShow(self, event):
sheet=MySheet(self.notebook)
TestThread(self,sheet)
def updateDisplay(self, msg):
t = msg.data
self.notebook.AddPage(t,"Logs")
app = wx.PySimpleApp()
frame = Newt().Show()
app.MainLoop()
Here I am using sheetload function defined in Mysheet to execute in TestThread. So i can set value into sheet in background without blocking main gui.
But i am getting this error, and my gui is crashing.
(python2.7:10775): GLib-CRITICAL **: Source ID 559 was not found when attempting to remove it
can you help me, what is wrong with this code.
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()