def setButton(self): """ Function to add a quit button """ myButton = QPushButton('Quit', self) myButton.move(20, 100) # myButton.clicked.connect(myApp.quit) myButton.clicked.connect(self.quitApp)
def setupComponents(self): btnAgregar = QPushButton('Agregar una maquina', self.Window) btnAgregar.move(50,50) btnAgregar.clicked.connect(self.AgregarMaquina()) btnBuscar = QPushButton('Buscar una maquina', self.Window) btnBuscar.move(50,100) btnBuscar.clicked.connect(self.BuscarMaquina())
def set_button(self, title='', position=(), action=None): """ Set a generic button title: str, title of the butten position: tuple, position of the button action: a callable that should be executed uppon button push """ myButton = QPushButton(title, self) myButton.move(position[0], position[1]) myButton.clicked.connect(action)
class SampleWindow(QWidget): """ Main Window Class""" def __init__(self): QWidget.__init__(self) self.setWindowTitle("Sample Window") self.setGeometry(300, 300, 200, 150) self.setMinimumHeight(100) self.setMinimumWidth(250) self.setMaximumHeight(500) self.setMaximumWidth(800) def setButton(self): """Function to add a quit button""" myButton=QPushButton("QUIT", self) myButton.move(50,100) myButton.clicked.connect(self.quitter) def quitter(self): """Function to confirm before quittin""" userInfo=QMessageBox.question(self, 'Confirmation', "This will quit the application. Continue?", QMessageBox.Yes | QMessageBox.No) if userInfo==QMessageBox.Yes: print "answer yes" myApp.quit() else: print "answer no" pass def center(self): """Function to center the application window""" qRect=self.frameGeometry() centerPoint=QDesktopWidget().availableGeometry().center() qRect.moveCenter(centerPoint) self.move(qRect.topLeft()) def setAboutButton(self): """Function to set About Button""" self.aboutButton=QPushButton('About', self) self.aboutButton.move(100, 100) self.aboutButton.clicked.connect(self.showAbout) def showAbout(self): """Function to show About box""" QMessageBox.about(self.aboutButton, "About PySide", "PySide is a cross-platform tool for generating GUI programs")
class MainWindow(QMainWindow): def __init__(self, parent=None): super(MainWindow, self).__init__(parent) #widnow setup resolution = QDesktopWidget().screenGeometry() self.screen_w = resolution.width() self.screen_h = resolution.height() self.setGeometry(0, 0, 650, 200) self.setWindowTitle('bento dumper' + mof.get_version_suffix()) self.setWindowIcon(QIcon('icons/run.png')) #center window qr = self.frameGeometry() cp = QtGui.QDesktopWidget().availableGeometry().center() qr.moveCenter(cp) self.move(qr.topLeft()) #adjust size self.resize(self.screen_w / 2, self.screen_h / 16) self.Menu() self.Layout() central_widget = QtGui.QWidget() central_widget.setLayout(self.main_layout) self.setCentralWidget(central_widget) def Menu(self): #this creates an action exit, a shortcut and status tip exitAction = QAction(QIcon('icons/exit.png'), '&Exit', self) exitAction.setShortcut('Ctrl+Q') exitAction.setStatusTip('Exit application') exitAction.triggered.connect(self.close) openFile = QAction(QIcon('icons/open.png'), '&Open', self) openFile.setShortcut('Ctrl+O') openFile.setStatusTip('Open new File') openFile.triggered.connect(self.browse) runAction = QAction(QIcon('icons/run.png'), '&Run', self) runAction.setShortcut('Ctrl+R') runAction.setStatusTip('Run Mars') runAction.triggered.connect(self.run_event) def Layout(self): #LAYOUT self.directory_prompt = QLabel(self) self.directory_prompt.setText("Directory Selected:") self.directory_prompt.move(25, 50) self.directory_prompt.resize(150, 30) self.browse_btn = QPushButton("Browse", self) self.browse_btn.move(130, 50) self.browse_btn.setStatusTip(" Browse Folder") # self.browse_btn.setStyleSheet("background-color: rgb(186, 186, 186); border-radius: 15px;border-style: solid;border-width: 2px;border-color: black;"); self.browse_btn.clicked.connect(self.browse) self.dir_shower = QLabel(self) self.dir_shower.setText("Directory") self.run_mars = QPushButton("Dump BENTO", self) self.run_mars.setVisible(True) self.run_mars.move(25, 160) self.run_mars.resize(self.screen_w / 2 - 150, 50) self.run_mars.setStatusTip('') self.run_mars.setStyleSheet( "background-color: rgb(142, 229, 171); border-radius: 15px;") self.run_mars.clicked.connect(self.run_event) self.menu_layout = QtGui.QHBoxLayout() self.menu_layout.addWidget(self.browse_btn) self.menu_layout.addWidget(self.directory_prompt) self.menu_layout.addWidget(self.dir_shower) self.menu_layout.addStretch() self.run_layout = QtGui.QHBoxLayout() self.run_layout.addWidget(self.run_mars) self.main_layout = QtGui.QVBoxLayout() self.main_layout.addLayout(self.menu_layout) self.main_layout.addLayout(self.run_layout) self.main_layout.addStretch() def browse(self): # sender = self.sender() dialog = QtGui.QFileDialog() dialog.setFileMode(QtGui.QFileDialog.Directory) dialog.setOption(QtGui.QFileDialog.ShowDirsOnly) self.dirname = dialog.getExistingDirectory(self, 'Choose Directory', os.path.curdir) if os.path.exists(self.dirname) and os.path.isdir(self.dirname): self.dir_shower.setText(self.dirname) return else: QMessageBox.information(self, " Wrong file selected", "Select a folder containing .seq files!") def run_event(self): self.genericThread = GenericThread(self.dirname) self.genericThread.start()
class Airport_project_UI(QWidget): airports = ['KRK', 'LA', 'LIS'] elitism_possibly_values = ['true', 'false'] max_flights_list = ['1', '2', '3', '4', '5'] def __init__(self): QWidget.__init__(self) self.params = {} # self.setMinimumSize(600, 250) #self.setWindowTitle("Medody Optymalizacji - Projekt") # self.setIcon() self.start_airport_label = QLabel("Start airport:", self) self.start_airport_label.move(5, 10) self.start_airport = QLineEdit(self) self.start_airport.setText('1') #self.start_airport.addItems(self.airports) self.start_airport.setMinimumHeight(20) self.start_airport.setMaximumHeight(20) self.start_airport.setMinimumWidth(60) self.start_airport.setMaximumWidth(60) self.start_airport.move(150, 5) #TODO function to convert names of airport to indexes self.destination_airport_label = QLabel("Destination airport:", self) self.destination_airport_label.move(5, 40) self.destination_airport = QLineEdit(self) self.destination_airport.setText('2') # self.destination_airport.addItems(self.airports) self.destination_airport.setMinimumHeight(20) self.destination_airport.setMaximumHeight(20) self.destination_airport.setMaximumWidth(60) self.destination_airport.setMinimumWidth(60) self.destination_airport.move(150, 35) self.max_flights_label = QLabel("max number of flights:", self) self.max_flights_label.move(5, 70) self.max_flights = QLineEdit(self) self.max_flights.setText("3") #self.max_flights.addItems(self.max_flights_list) self.max_flights.setMaximumHeight(20) self.max_flights.setMinimumHeight(20) self.max_flights.setMaximumWidth(60) self.max_flights.setMinimumWidth(60) #self.max_flights.setMinimumWidth(60) self.max_flights.move(150, 65) self.cost_weight_label = QLabel("max cost weights:", self) self.cost_weight_label.move(5, 100) self.cost_weight = QLineEdit(self) self.cost_weight.setText("4") self.cost_weight.setMinimumWidth(60) self.cost_weight.setMaximumWidth(60) self.cost_weight.setMinimumHeight(20) self.cost_weight.setMaximumHeight(20) self.cost_weight.move(150, 95) self.time_weight_label = QLabel("time weight:", self) self.time_weight_label.move(5, 130) self.time_weight = QLineEdit(self) self.time_weight.setText("5") self.time_weight.setMinimumWidth(60) self.time_weight.setMaximumWidth(60) self.time_weight.setMinimumHeight(20) self.time_weight.setMaximumHeight(20) self.time_weight.move(150, 125) self.pop_size_label = QLabel("pop size:", self) self.pop_size_label.move(5, 160) # +30 self.pop_size = QLineEdit(self) self.pop_size.setText("6") self.pop_size.setMinimumWidth(60) self.pop_size.setMaximumWidth(60) self.pop_size.setMinimumHeight(20) self.pop_size.setMaximumHeight(20) self.pop_size.move(150, 155) # +30 self.generation_label = QLabel("generations:", self) self.generation_label.move(5, 190) # +30 self.generation = QLineEdit(self) self.generation.setText("7") self.generation.setMinimumWidth(60) self.generation.setMaximumWidth(60) self.generation.setMinimumHeight(20) self.generation.setMaximumHeight(20) self.generation.move(150, 185) # +30 self.mutation_rate_label = QLabel("mutation rate:", self) self.mutation_rate_label.move(5, 210) # +30 self.mutation_rate = QLineEdit(self) self.mutation_rate.setText("8") self.mutation_rate.setMinimumWidth(60) self.mutation_rate.setMaximumWidth(60) self.mutation_rate.setMinimumHeight(20) self.mutation_rate.setMaximumHeight(20) self.mutation_rate.move(150, 215) # +30 self.tournament_size_label = QLabel("tournament size:", self) self.tournament_size_label.move(5, 240) # +30 self.tournament_size = QLineEdit(self) self.tournament_size.setText("9") self.tournament_size.setMinimumWidth(60) self.tournament_size.setMaximumWidth(60) self.tournament_size.setMinimumHeight(20) self.tournament_size.setMaximumHeight(20) self.tournament_size.move(150, 245) # +30 self.elitism_label = QLabel("elitism:", self) self.elitism_label.move(5, 270) # +30 self.elitism = QComboBox(self) self.elitism.addItems(self.elitism_possibly_values) self.elitism.setMinimumWidth(60) self.elitism.setMaximumWidth(60) self.elitism.setMinimumHeight(20) self.elitism.setMaximumHeight(20) self.elitism.move(150, 275) # +30 self.destination_min_label = QLabel("dest min:", self) self.destination_min_label.move(5, 300) # +30 self.dest_min = QLineEdit(self) self.dest_min.setText("4") self.dest_min.setMinimumWidth(60) self.dest_min.setMaximumWidth(60) self.dest_min.setMinimumHeight(20) self.dest_min.setMaximumHeight(20) self.dest_min.move(150, 305) # +30 self.destination_max_label = QLabel("dest max:", self) self.destination_max_label.move(5, 330) # +30 self.dest_max = QLineEdit(self) self.dest_max.setText("10") self.dest_max.setMinimumWidth(60) self.dest_max.setMaximumWidth(60) self.dest_max.setMinimumHeight(20) self.dest_max.setMaximumHeight(20) self.dest_max.move(150, 335) # +30 self.generate_graph_button = QPushButton("Generate graph!", self) self.generate_graph_button.setMinimumWidth(170) self.generate_graph_button.move(25, 365) self.start_evolution_button = QPushButton("Start evolution!", self) self.start_evolution_button.setMinimumWidth(170) self.start_evolution_button.move(25, 395) self.start_evolution_button.clicked.connect(self.start_evolution) self.generate_graph_button.clicked.connect(self.generate_graph) #self.get_list_of_possibly_airports() #TODO to have full list of airports in QComboBox def generate_graph(self): self.params = { 'graph': None, 'start_idx': int(self.start_airport.text()), 'end_idx': int(self.destination_airport.text()), 'max_flights': int(self.max_flights.text()), 'cost_weight': int(self.cost_weight.text()), 'time_weight': int(self.time_weight.text()), 'pop_size': int(self.pop_size.text()), 'generations': int(self.generation.text()), 'mutation_rate': float(self.mutation_rate.text()), 'tournament_size': int(self.tournament_size.text()), 'elitism': bool(self.elitism.currentText()), 'dest_min': int(self.dest_min.text()), 'dest_max': int(self.dest_max.text()), 'max_flights': 4, } data = DataGenerator() DataGenerator.DESTINATIONS_MIN = self.params['dest_min'] DataGenerator.DESTINATIONS_MAX = self.params['dest_max'] # if input_graph_file is not None: # data.load_saved_graph(input_graph_file) # # else: #TODO ilosc lotnisk data.load_new_data(10) data.create_graph() # if graph_save_file is not None: # data.save_graph(graph_save_file) testsuite_airports = data.get_airports() testsuite_graph = data.get_graph() self.graph = GraphManager(self.params['max_flights']) self.graph.set_graph(testsuite_graph, testsuite_airports) airports_parser = Testsuite_airports_parser(testsuite_airports) def start_evolution(self): import pprint self.params = { 'graph': self.graph, 'start_idx': int(self.start_airport.text()), 'end_idx': int(self.destination_airport.text()), 'max_flights': int(self.max_flights.text()), 'cost_weight': int(self.cost_weight.text()), 'time_weight': int(self.time_weight.text()), 'pop_size': int(self.pop_size.text()), 'generations': int(self.generation.text()), 'mutation_rate': float(self.mutation_rate.text()), 'tournament_size': int(self.tournament_size.text()), 'elitism': bool(self.elitism.currentText()), 'dest_min': int(self.dest_min.text()), 'dest_max': int(self.dest_max.text()), } # pprint.pprint(params) self.output_of_algorithm = sys.__stdout__ GA.run_with_params(self.params) self.newwindow() def newwindow(self): import pprint print("##############") pprint.pprint(self.output_of_algorithm) print("##############") self.wid = QWidget() self.wid.resize(250, 150) self.wid.setWindowTitle('NewWindow') self.result = QTextEdit(self.wid) self.result.setText(str(self.output_of_algorithm)) #self.start_airport.addItems(self.airports) self.result.setMinimumHeight(200) self.result.setMaximumHeight(200) self.result.setMinimumWidth(600) self.start_airport.setMaximumWidth(600) # self.start_airport.move(150, 5) self.output_of_algorithm = None self.wid.show()
class SampleWindow(QWidget): """ Our main window class """ def __init__(self): """ Constructor Function """ QWidget.__init__(self) self.setWindowTitle("Icon Sample") self.center() #self.setGeometry(300, 300, 200, 150) def setIcon(self): """ Function to set Icon """ appIcon = QIcon('icon.png') self.setWindowIcon(appIcon) def setIconModes(self): myIcon1 = QIcon('icon.png') myLabel1 = QLabel('sample', self) pixmap1 = myIcon1.pixmap(50, 50, QIcon.Active, QIcon.On) myLabel1.setPixmap(pixmap1) myLabel1.setToolTip('active icon') myIcon2 = QIcon('icon.png') myLabel2 = QLabel('sample', self) pixmap2 = myIcon2.pixmap(50, 50, QIcon.Disabled, QIcon.Off) myLabel2.setPixmap(pixmap2) myLabel2.move(50, 0) myIcon3 = QIcon('icon.png') myLabel3 = QLabel('sample', self) pixmap3 = myIcon3.pixmap(50, 50, QIcon.Selected, QIcon.On) myLabel3.setPixmap(pixmap3) myLabel3.move(100, 0) def setButton(self): """ Function to add a quit button """ myButton = QPushButton('Quit', self) myButton.move(50, 100) myButton.clicked.connect(self.quitApp) def quitApp(self): """ Function to confirm a message from the user """ userInfo = QMessageBox.question( self, 'Confirmation', "This will quit the application. Do you want to Continue?", QMessageBox.Yes | QMessageBox.No) if userInfo == QMessageBox.Yes: myApp.quit() if userInfo == QMessageBox.No: pass def center(self): """ Function to center the application """ qRect = self.frameGeometry() centerPoint = QDesktopWidget().availableGeometry().center() qRect.moveCenter(centerPoint) self.move(qRect.topLeft()) def setAboutButton(self): """ Function to set About Button """ self.aboutButton = QPushButton("About Me", self) self.aboutButton.move(130, 100) self.aboutButton.clicked.connect(self.showAbout) def showAbout(self): """ Function to show About Box """ QMessageBox.about( self.aboutButton, "About MyWin", "PySide is a cross-platform tool for generating GUI Programs.") def setQtAboutButton(self): """ Function to set About Button """ self.aboutQtButton = QPushButton("About Qt", self) self.aboutQtButton.move(130, 130) self.aboutQtButton.clicked.connect(self.showQtAbout) def showQtAbout(self): """ Function to show About Box """ QMessageBox.aboutQt(self.aboutQtButton, "About PySide")
class SampleWindow(QWidget): """ Our Main Window Class """ # Constructor Function def __init__(self): # type: () -> object QWidget.__init__(self) self.setWindowTitle("Icon Sample") self.setGeometry(200, 300, 400, 150) QToolTip.setFont(QFont("Decorative", 8, QFont.Bold)) self.setToolTip('Our Main WIndow') self.setMinimumHeight(100) self.setMinimumWidth(250) self.setMaximumHeight(300) self.setMaximumWidth(800) def setIcon(self): """ Function to set Icon""" appIcon = QIcon('pyside_logo.png') self.setWindowIcon(appIcon) def setIconMode(self): myIcon1 = QIcon('pyside_logo.png') myLabel1 = QLabel('sample', self) pixmap1 = myIcon1.pixmap(50, 50, QIcon.Active, QIcon.On) myLabel1.setPixmap(pixmap1) myLabel1.setToolTip('Active') myIcon2 = QIcon('pyside_logo.png') myLabel2 = QLabel('sample', self) pixmap2 = myIcon2.pixmap(50, 50, QIcon.Disabled, QIcon.Off) myLabel2.setPixmap(pixmap2) myLabel2.move(50, 0) myLabel2.setToolTip('Disabled') myIcon3 = QIcon('pyside_logo.png') myLabel3 = QLabel('sample', self) pixmap3 = myIcon3.pixmap(50, 50, QIcon.Selected, QIcon.On) myLabel3.setPixmap(pixmap3) myLabel3.move(100, 0) myLabel3.setToolTip('Selected') def setButton(self): """Function to add a quit button """ myButton = QPushButton('Quit', self) myButton.move(50, 100) myButton.clicked.connect(self.quitApp) def quitApp(self): """ Function to confirm a message from the user """ userInfo = QMessageBox.question( self, 'Confirmation', "This will quit the application. Do you want to Continue?", QMessageBox.Yes | QMessageBox.No) if userInfo == QMessageBox.Yes: myApp.quit() if userInfo == QMessageBox.No: pass def center(self): """ Function ti center the application """ qRect = self.frameGeometry() centerPoint = QDesktopWidget().availableGeometry().center() qRect.moveCenter(centerPoint) self.move(qRect.topLeft()) def setAboutButton(self): """ Function to set about button """ self.aboutButton = QPushButton("About", self) self.aboutButton.move(150, 100) self.aboutButton.clicked.connect(self.showAbout) def showAbout(self): """ Funtion to show about button """ QMessageBox.about(self.aboutButton, "About Pyside", "Copyright 2016 Timothy P Marion") def setAboutQtButton(self): """ Function to set Qt button """ self.aboutQtButton = QPushButton("Qt", self) self.aboutQtButton.move(250, 100) self.aboutQtButton.clicked.connect(self.showQtAbout) def showQtAbout(self): """ Function to set Qt Button """ QMessageBox.aboutQt(self.aboutQtButton)
class Airport_project_UI(QWidget): airports = [ 'KRK', 'LA', 'LIS' ] elitism_possibly_values = ['true', 'false'] max_flights_list = ['1', '2', '3', '4', '5'] def __init__(self): QWidget.__init__(self) self.params = {} # self.setMinimumSize(600, 250) #self.setWindowTitle("Medody Optymalizacji - Projekt") # self.setIcon() self.start_airport_label = QLabel("Start airport:", self) self.start_airport_label.move(5, 10) self.start_airport = QLineEdit(self) self.start_airport.setText('1') #self.start_airport.addItems(self.airports) self.start_airport.setMinimumHeight(20) self.start_airport.setMaximumHeight(20) self.start_airport.setMinimumWidth(60) self.start_airport.setMaximumWidth(60) self.start_airport.move(150, 5) #TODO function to convert names of airport to indexes self.destination_airport_label = QLabel("Destination airport:", self) self.destination_airport_label.move(5, 40) self.destination_airport = QLineEdit(self) self.destination_airport.setText('2') # self.destination_airport.addItems(self.airports) self.destination_airport.setMinimumHeight(20) self.destination_airport.setMaximumHeight(20) self.destination_airport.setMaximumWidth(60) self.destination_airport.setMinimumWidth(60) self.destination_airport.move(150, 35) self.max_flights_label = QLabel("max number of flights:", self) self.max_flights_label.move(5, 70) self.max_flights = QLineEdit(self) self.max_flights.setText("3") #self.max_flights.addItems(self.max_flights_list) self.max_flights.setMaximumHeight(20) self.max_flights.setMinimumHeight(20) self.max_flights.setMaximumWidth(60) self.max_flights.setMinimumWidth(60) #self.max_flights.setMinimumWidth(60) self.max_flights.move(150, 65) self.cost_weight_label = QLabel("max cost weights:", self) self.cost_weight_label.move(5, 100) self.cost_weight = QLineEdit(self) self.cost_weight.setText("4") self.cost_weight.setMinimumWidth(60) self.cost_weight.setMaximumWidth(60) self.cost_weight.setMinimumHeight(20) self.cost_weight.setMaximumHeight(20) self.cost_weight.move(150, 95) self.time_weight_label = QLabel("time weight:", self) self.time_weight_label.move(5, 130) self.time_weight = QLineEdit(self) self.time_weight.setText("5") self.time_weight.setMinimumWidth(60) self.time_weight.setMaximumWidth(60) self.time_weight.setMinimumHeight(20) self.time_weight.setMaximumHeight(20) self.time_weight.move(150, 125) self.pop_size_label = QLabel("pop size:", self) self.pop_size_label.move(5, 160) # +30 self.pop_size = QLineEdit(self) self.pop_size.setText("6") self.pop_size.setMinimumWidth(60) self.pop_size.setMaximumWidth(60) self.pop_size.setMinimumHeight(20) self.pop_size.setMaximumHeight(20) self.pop_size.move(150, 155) # +30 self.generation_label = QLabel("generations:", self) self.generation_label.move(5, 190) # +30 self.generation = QLineEdit(self) self.generation.setText("7") self.generation.setMinimumWidth(60) self.generation.setMaximumWidth(60) self.generation.setMinimumHeight(20) self.generation.setMaximumHeight(20) self.generation.move(150, 185) # +30 self.mutation_rate_label = QLabel("mutation rate:", self) self.mutation_rate_label.move(5, 210) # +30 self.mutation_rate = QLineEdit(self) self.mutation_rate.setText("8") self.mutation_rate.setMinimumWidth(60) self.mutation_rate.setMaximumWidth(60) self.mutation_rate.setMinimumHeight(20) self.mutation_rate.setMaximumHeight(20) self.mutation_rate.move(150, 215) # +30 self.tournament_size_label = QLabel("tournament size:", self) self.tournament_size_label.move(5, 240) # +30 self.tournament_size = QLineEdit(self) self.tournament_size.setText("9") self.tournament_size.setMinimumWidth(60) self.tournament_size.setMaximumWidth(60) self.tournament_size.setMinimumHeight(20) self.tournament_size.setMaximumHeight(20) self.tournament_size.move(150, 245) # +30 self.elitism_label = QLabel("elitism:", self) self.elitism_label.move(5, 270) # +30 self.elitism = QComboBox(self) self.elitism.addItems(self.elitism_possibly_values) self.elitism.setMinimumWidth(60) self.elitism.setMaximumWidth(60) self.elitism.setMinimumHeight(20) self.elitism.setMaximumHeight(20) self.elitism.move(150, 275) # +30 self.destination_min_label = QLabel("dest min:", self) self.destination_min_label.move(5, 300) # +30 self.dest_min = QLineEdit(self) self.dest_min.setText("4") self.dest_min.setMinimumWidth(60) self.dest_min.setMaximumWidth(60) self.dest_min.setMinimumHeight(20) self.dest_min.setMaximumHeight(20) self.dest_min.move(150, 305) # +30 self.destination_max_label = QLabel("dest max:", self) self.destination_max_label.move(5, 330) # +30 self.dest_max = QLineEdit(self) self.dest_max.setText("10") self.dest_max.setMinimumWidth(60) self.dest_max.setMaximumWidth(60) self.dest_max.setMinimumHeight(20) self.dest_max.setMaximumHeight(20) self.dest_max.move(150, 335) # +30 self.generate_graph_button = QPushButton("Generate graph!", self) self.generate_graph_button.setMinimumWidth(170) self.generate_graph_button.move(25, 365) self.start_evolution_button = QPushButton("Start evolution!", self) self.start_evolution_button.setMinimumWidth(170) self.start_evolution_button.move(25, 395) self.start_evolution_button.clicked.connect(self.start_evolution) self.generate_graph_button.clicked.connect(self.generate_graph) #self.get_list_of_possibly_airports() #TODO to have full list of airports in QComboBox def generate_graph(self): self.params = { 'graph' : None, 'start_idx' : int(self.start_airport.text()), 'end_idx' : int(self.destination_airport.text()), 'max_flights' : int(self.max_flights.text()), 'cost_weight' : int(self.cost_weight.text()), 'time_weight' : int(self.time_weight.text()), 'pop_size' : int(self.pop_size.text()), 'generations' : int(self.generation.text()), 'mutation_rate' : float(self.mutation_rate.text()), 'tournament_size' : int(self.tournament_size.text()), 'elitism' : bool(self.elitism.currentText()), 'dest_min' : int(self.dest_min.text()), 'dest_max' : int(self.dest_max.text()), 'max_flights' : 4, } data = DataGenerator() DataGenerator.DESTINATIONS_MIN = self.params['dest_min'] DataGenerator.DESTINATIONS_MAX = self.params['dest_max'] # if input_graph_file is not None: # data.load_saved_graph(input_graph_file) # # else: #TODO ilosc lotnisk data.load_new_data(10) data.create_graph() # if graph_save_file is not None: # data.save_graph(graph_save_file) testsuite_airports = data.get_airports() testsuite_graph = data.get_graph() self.graph = GraphManager(self.params['max_flights']) self.graph.set_graph(testsuite_graph, testsuite_airports) airports_parser = Testsuite_airports_parser(testsuite_airports) def start_evolution(self): import pprint self.params = { 'graph' : self.graph, 'start_idx' : int(self.start_airport.text()), 'end_idx' : int(self.destination_airport.text()), 'max_flights' : int(self.max_flights.text()), 'cost_weight' : int(self.cost_weight.text()), 'time_weight' : int(self.time_weight.text()), 'pop_size' : int(self.pop_size.text()), 'generations' : int(self.generation.text()), 'mutation_rate' : float(self.mutation_rate.text()), 'tournament_size' : int(self.tournament_size.text()), 'elitism' : bool(self.elitism.currentText()), 'dest_min' : int(self.dest_min.text()), 'dest_max' : int(self.dest_max.text()), } # pprint.pprint(params) self.output_of_algorithm = sys.__stdout__ GA.run_with_params(self.params) self.newwindow() def newwindow(self): import pprint print("##############") pprint.pprint(self.output_of_algorithm) print("##############") self.wid = QWidget() self.wid.resize(250, 150) self.wid.setWindowTitle('NewWindow') self.result = QTextEdit(self.wid) self.result.setText(str(self.output_of_algorithm)) #self.start_airport.addItems(self.airports) self.result.setMinimumHeight(200) self.result.setMaximumHeight(200) self.result.setMinimumWidth(600) self.start_airport.setMaximumWidth(600) # self.start_airport.move(150, 5) self.output_of_algorithm = None self.wid.show()
class LabelImage(QLabel): _pixmap = None _image = None _hide_icons = False _icon_size = 28 download_started = Signal() download_ended = Signal() button_download_clicked = Signal() def __init__(self, parent=None): QLabel.__init__(self, parent) self.setText(self.tr("<u>can't obtain picture</u>")) self.lblLoadProcess = QLabel("...", self) self.lblLoadProcess.setMovie(QMovie(":/loading.gif")) self.lblLoadProcess.setAlignment(Qt.AlignCenter) self.lblLoadProcess.hide() self.btnDownload = QPushButton("", self) self.btnDownload.setIcon(QIcon(":/folder.png")) self.btnDownload.setIconSize(QSize(self._icon_size, self._icon_size)) self.btnDownload.setFlat(True) self.btnDownload.clicked.connect(self.save_image) self.btnDownload.clicked.connect(self.button_download_clicked) self.download_ended.connect(self.check_image) self.download_ended.connect(self.lblLoadProcess.hide) self.download_ended.connect(self.btnDownload.show) self.download_ended.connect(self.end_load_anim) self.download_started.connect(self.start_load_anim) self.download_started.connect(self.btnDownload.hide) self.download_started.connect(self.lblLoadProcess.show) # self.destroyed.connect(self.on_destroyed) def start_load_anim(self): self.lblLoadProcess.movie().start() def end_load_anim(self): self.lblLoadProcess.movie().stop() @property def save_path(self): return os.path.join(config.save_dir, self._image.celeb.full_name, self._image.name) def save_image_thread_callback(self): self.download_started.emit() b = self._image.full_image_bytes path = self.save_path if not os.path.exists(os.path.dirname(path)): os.makedirs(os.path.dirname(path)) img = Image.open(BytesIO(b)) img.save(self.save_path) # f = open(path, 'w') # f.write(b) # f.close() try: self.download_ended.emit() except RuntimeError as e: log.debug(sys.exc_traceback) log.debug(sys.exc_info()) def save_image(self): thread = Thread(target=self.save_image_thread_callback) thread.start() def check_image(self): if self._image: if os.path.exists(self.save_path): self.btnDownload.setIcon(QIcon(":/check.png")) return True self.btnDownload.setIcon(QIcon(":/folder.png")) return False def __setProp(self): if self._pixmap: QLabel.setPixmap(self, self._pixmap.scaled( self.width(), self.height(), Qt.KeepAspectRatio, Qt.SmoothTransformation)) else: QLabel.setPixmap(self, QPixmap()) @property def image(self): return self._image @image.setter def image(self, image): assert isinstance(image, ThePlaceImage) self._image = image path = os.path.abspath(image.icon_cache_path).replace('\\', '/') self.check_image() self.setPixmap(QPixmap(path)) def setPixmap(self, px): self._pixmap = px self.__setProp() self.btnDownload.setVisible(not self.hide_icons and px is not None) def resizeEvent(self, *args, **kwargs): super(LabelImage, self).resizeEvent(*args, **kwargs) self.__setProp() self.btnDownload.move(self.width() - self.btnDownload.width() - 3, self.height() - self.btnDownload.height() - 2) self.lblLoadProcess.setGeometry(self.btnDownload.geometry()) @property def hide_icons(self): return self._hide_icons @hide_icons.setter def hide_icons(self, value): self._hide_icons = value self.btnDownload.setVisible(not self.hide_icons)
def initUI(self): self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) # Select analysis file button button = QPushButton('Select analysis file', self) button.setToolTip('*.inp CalculiX analysis file.') button.move(10, 10) button.clicked.connect(self.on_click) # Text box - file path and name self.textbox_file_name = QLineEdit(self) self.textbox_file_name.move(120, 15) self.textbox_file_name.resize(420, 20) self.textbox_file_name.setText("None analysis file selected") self.textbox_file_name.setToolTip('Analysis file.') # Update button button1 = QPushButton('Update domains', self) button1.setToolTip( 'Update naming inputs and material data from FreeCAD.') button1.move(10, 50) button1.clicked.connect(self.on_click1) # Domains definition # Label above domains definition label21 = QLabel('Domain 0', self) label21.setStyleSheet("font-weight: bold") label21.move(120, 50) label21 = QLabel('Domain 1', self) label21.setStyleSheet("font-weight: bold") label21.move(260, 50) label21 = QLabel('Domain 2', self) label21.setStyleSheet("font-weight: bold") label21.move(400, 50) label24 = QLabel('Material object', self) label24.move(20, 80) label25 = QLabel('Thickness object', self) label25.move(20, 110) label26 = QLabel('As design domain', self) label26.move(20, 140) label27 = QLabel('Stress limit [MPa]', self) label27.move(20, 170) # Combo box - select domain by material object self.combo = QComboBox(self) self.combo.setToolTip('Material object to define the domain.') self.combo.move(120, 80) self.combo.resize(140, 30) self.combo.currentIndexChanged.connect(self.on_change) self.combo1 = QComboBox(self) self.combo1.setToolTip('Material object to define the domain.') self.combo1.move(260, 80) self.combo1.resize(140, 30) self.combo1.currentIndexChanged.connect(self.on_change1) self.combo2 = QComboBox(self) self.combo2.setToolTip('Material object to define the domain.') self.combo2.move(400, 80) self.combo2.resize(140, 30) self.combo2.currentIndexChanged.connect(self.on_change2) # Combo box - select thickness object self.combo0t = QComboBox(self) self.combo0t.setToolTip( 'Thickness object to specify if domain is for shells.') self.combo0t.move(120, 110) self.combo0t.resize(140, 30) self.combo1t = QComboBox(self) self.combo1t.setToolTip( 'Thickness object to specify if domain is for shells.') self.combo1t.move(260, 110) self.combo1t.resize(140, 30) self.combo2t = QComboBox(self) self.combo2t.setToolTip( 'Thickness object to specify if domain is for shells.') self.combo2t.move(400, 110) self.combo2t.resize(140, 30) self.textbox3 = QLineEdit(self) self.textbox3.move(120, 170) self.textbox3.resize(40, 20) # self.textbox3.setText("") self.textbox3.setToolTip( 'Thickness [mm] of shell elements in the domain.\n' 'This value overwrites thickness defined in FreeCAD') self.textbox4 = QLineEdit(self) self.textbox4.move(260, 170) self.textbox4.resize(40, 20) # self.textbox4.setText("") self.textbox4.setToolTip( 'Thickness [mm] of shell elements in the domain.\n' 'This value overwrites thickness defined in FreeCAD') self.textbox5 = QLineEdit(self) self.textbox5.move(400, 170) self.textbox5.resize(40, 20) # self.textbox5.setText("") self.textbox5.setToolTip( 'Thickness [mm] of shell elements in the domain.\n' 'This value overwrites thickness defined in FreeCAD') # Check box - design or nondesign self.checkbox = QCheckBox('', self) self.checkbox.setChecked(True) self.checkbox.setToolTip('Check to be the design domain.') self.checkbox.move(120, 140) self.checkbox1 = QCheckBox('', self) self.checkbox1.setChecked(True) self.checkbox1.setToolTip('Check to be the design domain.') self.checkbox1.move(260, 140) self.checkbox2 = QCheckBox('', self) self.checkbox2.setChecked(True) self.checkbox2.setToolTip('Check to be the design domain.') self.checkbox2.move(400, 140) # Text box - stress limit self.textbox = QLineEdit(self) self.textbox.move(120, 170) self.textbox.resize(40, 20) # self.textbox.setText("") self.textbox.setToolTip( 'Von Mises stress [MPa] limit, when reached, material removing will stop.' ) self.textbox1 = QLineEdit(self) self.textbox1.move(260, 170) self.textbox1.resize(40, 20) # self.textbox1.setText("") self.textbox1.setToolTip( 'Von Mises stress [MPa] limit, when reached, material removing will stop.' ) self.textbox2 = QLineEdit(self) self.textbox2.move(400, 170) self.textbox2.resize(40, 20) # self.textbox2.setText("") self.textbox2.setToolTip( 'Von Mises stress [MPa] limit, when reached, material removing will stop.' ) # Filters # Label above filter definition label31 = QLabel('Filter 0', self) label31.setStyleSheet("font-weight: bold") label31.move(120, 210) label32 = QLabel('Filter 1', self) label32.setStyleSheet("font-weight: bold") label32.move(260, 210) label33 = QLabel('Filter 2', self) label33.setStyleSheet("font-weight: bold") label33.move(400, 210) label34 = QLabel('Type', self) label34.move(20, 240) label35 = QLabel('Range [mm]', self) label35.move(20, 270) label36 = QLabel('Direction vector', self) label36.move(20, 300) label37 = QLabel('Apply to', self) label37.move(20, 330) # Combo box - select filter type self.combo6 = QComboBox(self) self.combo6.setToolTip( 'Filters:\n' '"simple" to suppress checkerboard effect,\n' '"casting" to prescribe casting direction (opposite to milling direction)\n' 'Recommendation: for casting use as first "casting" and as second "simple"' ) self.combo6.addItem("None") self.combo6.addItem("simple") self.combo6.addItem("casting") self.combo6.setCurrentIndex(1) self.combo6.move(120, 240) self.combo6.currentIndexChanged.connect(self.on_change6) self.combo7 = QComboBox(self) self.combo7.setToolTip( 'Filters:\n' '"simple" to suppress checkerboard effect,\n' '"casting" to prescribe casting direction (opposite to milling direction)\n' 'Recommendation: for casting use as first "casting" and as second "simple"' ) self.combo7.addItem("None") self.combo7.addItem("simple") self.combo7.addItem("casting") self.combo7.move(260, 240) self.combo7.currentIndexChanged.connect(self.on_change7) self.combo8 = QComboBox(self) self.combo8.setToolTip( 'Filters:\n' '"simple" to suppress checkerboard effect,\n' '"casting" to prescribe casting direction (opposite to milling direction)\n' 'Recommendation: for casting use as first "casting" and as second "simple"' ) self.combo8.addItem("None") self.combo8.addItem("simple") self.combo8.addItem("casting") self.combo8.move(400, 240) self.combo8.currentIndexChanged.connect(self.on_change8) # Text box - filter range self.textbox6 = QLineEdit(self) self.textbox6.move(120, 270) self.textbox6.resize(50, 20) # self.textbox6.setText("") self.textbox6.setToolTip( 'Filter range [mm], recommended two times mesh size.') self.textbox7 = QLineEdit(self) self.textbox7.move(260, 270) self.textbox7.resize(50, 20) # self.textbox7.setText("") self.textbox7.setToolTip( 'Filter range [mm], recommended two times mesh size.') self.textbox7.setEnabled(False) self.textbox8 = QLineEdit(self) self.textbox8.move(400, 270) self.textbox8.resize(50, 20) # self.textbox8.setText("") self.textbox8.setToolTip( 'Filter range [mm], recommended two times mesh size.') self.textbox8.setEnabled(False) # Text box - casting direction self.textbox9 = QLineEdit(self) self.textbox9.move(120, 300) self.textbox9.resize(80, 20) self.textbox9.setText("0, 0, 1") self.textbox9.setEnabled(False) self.textbox9.setToolTip( 'Casting direction vector, e.g. direction in z axis:\n' '0, 0, 1\n\n' 'solid void\n' 'XXXXXX.................\n' 'XXX........................\n' 'XX........................... --> z axis\n' 'XXXXX....................\n' 'XXXXXXXXXXX......') self.textbox10 = QLineEdit(self) self.textbox10.move(260, 300) self.textbox10.resize(80, 20) self.textbox10.resize(80, 20) self.textbox10.setText("0, 0, 1") self.textbox10.setEnabled(False) self.textbox10.setToolTip( 'Casting direction vector, e.g. direction in z axis:\n' '0, 0, 1\n\n' 'solid void\n' 'XXXXXX.................\n' 'XXX........................\n' 'XX........................... --> z axis\n' 'XXXXX....................\n' 'XXXXXXXXXXX......') self.textbox11 = QLineEdit(self) self.textbox11.move(400, 300) self.textbox11.resize(80, 20) self.textbox11.setText("0, 0, 1") self.textbox11.setEnabled(False) self.textbox11.setToolTip( 'Casting direction vector, e.g. direction in z axis:\n' '0, 0, 1\n\n' 'solid void\n' 'XXXXXX.................\n' 'XXX........................\n' 'XX........................... --> z axis\n' 'XXXXX....................\n' 'XXXXXXXXXXX......') # list widget - select domains self.widget = QListWidget(self) self.widget.setToolTip( 'Domains affected by the filter.\n' 'Select only from domains which you defined above.') self.widget.move(120, 330) self.widget.resize(140, 120) self.widget.setSelectionMode(QAbstractItemView.MultiSelection) self.widget1 = QListWidget(self) self.widget1.setToolTip( 'Domains affected by the filter.\n' 'Select only from domains which you defined above.') self.widget1.move(260, 330) self.widget1.resize(140, 120) self.widget1.setSelectionMode(QAbstractItemView.MultiSelection) self.widget1.setEnabled(False) self.widget2 = QListWidget(self) self.widget2.setToolTip( 'Domains affected by the filter.\n' 'Select only from domains which you defined above.') self.widget2.move(400, 330) self.widget2.resize(140, 120) self.widget2.setSelectionMode(QAbstractItemView.MultiSelection) self.widget2.setEnabled(False) # Other settings label40 = QLabel('Other settings', self) label40.setStyleSheet("font-weight: bold") label40.move(10, 470) # AR, RR slider label41 = QLabel('Change per iteration: low', self) label41.setFixedWidth(150) label41.move(10, 500) label42 = QLabel('high', self) label42.move(240, 500) self.slider = QSlider(Qt.Horizontal, self) self.slider.setRange(1, 3) self.slider.setSingleStep(1) self.slider.setValue(2) self.slider.move(150, 500) self.slider.resize(80, 30) self.slider.setToolTip( 'Sets mass change per iteration, which is controlled as\n' 'slow: mass_addition_ratio=0.01, mass_removal_ratio=0.02\n' 'middle: mass_addition_ratio=0.015, mass_removal_ratio=0.03\n' 'fast: mass_addition_ratio=0.03, mass_removal_ratio=0.06') # optimization base combobox label51 = QLabel('Optimization base', self) label51.move(10, 530) self.combo51 = QComboBox(self) self.combo51.setToolTip( 'Basic principle to determine if element should remain or be removed:\n' '"stiffness" to maximize stiffness (minimize compliance),\n' '"heat" to maximize heat flow.') self.combo51.addItem("stiffness") self.combo51.addItem("heat") self.combo51.move(120, 530) # mass goal ratio label52 = QLabel('Mass goal ratio', self) label52.move(10, 560) self.textbox52 = QLineEdit(self) self.textbox52.move(120, 560) self.textbox52.resize(50, 20) self.textbox52.setText("0.4") self.textbox52.setToolTip( 'Fraction of all design domains masses to be achieved;\n' 'between 0 and 1.') # generate conf. file button button21 = QPushButton('Generate conf. file', self) button21.setToolTip( 'Writes configuration file with optimization parameters.') button21.move(10, 600) button21.clicked.connect(self.on_click21) # edit conf. file button button22 = QPushButton('Edit conf. file', self) button22.setToolTip('Opens configuration file for hand modifications.') button22.move(10, 630) button22.clicked.connect(self.on_click22) # run optimization button button23 = QPushButton('Run optimization', self) button23.setToolTip('Writes configuration file and runs optimization.') button23.move(10, 660) button23.clicked.connect(self.on_click23) # generate conf file and run optimization button button24 = QPushButton('Generate conf.\nfile and run\noptimization', self) button24.setToolTip('Writes configuration file and runs optimization.') button24.move(120, 600) button24.resize(100, 90) button24.clicked.connect(self.on_click24) # help buttons label41 = QLabel('Help', self) label41.move(440, 560) button31 = QPushButton('Example', self) button31.setToolTip( 'https://github.com/fandaL/beso/wiki/Example-4:-GUI-in-FreeCAD') button31.move(440, 590) # button31.resize(80, 50) button31.clicked.connect(self.on_click31) button32 = QPushButton('Conf. comments', self) button32.setToolTip( 'https://github.com/fandaL/beso/blob/master/beso_conf.py') button32.move(440, 620) # button32.resize(80, 50) button32.clicked.connect(self.on_click32) button33 = QPushButton('Close', self) button33.move(440, 690) # button33.resize(80, 50) button33.clicked.connect(self.on_click33) # open log file button40 = QPushButton('Open log file', self) button40.setToolTip('Opens log file in your text editor.\n' '(Does not refresh automatically.)') button40.move(10, 690) button40.clicked.connect(self.on_click40) self.on_click1() # first update self.show()
class SampleWindow(QWidget): """ Our main window class """ def __init__(self): """ Constructor Function """ QWidget.__init__(self) self.setWindowTitle("Icon Sample") self.setGeometry(300, 300, 200, 150) QToolTip.setFont(QFont("Decorative", 8, QFont.Bold)) self.setToolTip('Our Main Window') def setIcon(self): """ Function to set Icon """ appIcon = QIcon('iconos/prueba.png') self.setWindowIcon(appIcon) def setIconModes(self): myIcon1 = QIcon('iconos/prueba.png') myLabel1 = QLabel('sample', self) pixmap1 = myIcon1.pixmap(50, 50, QIcon.Active, QIcon.On) myLabel1.setPixmap(pixmap1) myLabel1.setToolTip('Active Icon') myIcon2 = QIcon('iconos/prueba.png') myLabel2 = QLabel('sample', self) pixmap2 = myIcon2.pixmap(50, 50, QIcon.Disabled, QIcon.Off) myLabel2.setPixmap(pixmap2) myLabel2.move(50, 0) myLabel2.setToolTip('Disabled Icon') myIcon3 = QIcon('iconos/prueba.png') myLabel3 = QLabel('sample', self) pixmap3 = myIcon3.pixmap(50, 50, QIcon.Selected, QIcon.On) myLabel3.setPixmap(pixmap3) myLabel3.move(100, 0) myLabel3.setToolTip('Selected Icon') def quitApp(self): """ Function to confirm a message from the user """ userInfo = QMessageBox.question(self, 'Confirmation', "This will quit the application. Do you want to Continue?", QMessageBox.Yes | QMessageBox.No) if userInfo == QMessageBox.Yes: myApp.quit() if userInfo == QMessageBox.No: pass def setButton(self): """ Function to add a quit button """ myButton = QPushButton('Quit', self) myButton.move(50, 120) myButton.clicked.connect(self.quitApp) def setAboutButton(self): """ Function to set About Button """ self.aboutButton = QPushButton("About", self) self.aboutButton.move(50, 90) self.aboutButton.clicked.connect(self.showAbout) def setAboutQTButton(self): """ Function to set About QT Button """ self.aboutQTButton = QPushButton("AboutQT", self) self.aboutQTButton.move(50, 60) self.aboutQTButton.clicked.connect(self.showAboutQT) def showAbout(self): """ Function to show About Box """ QMessageBox.about(self.aboutButton, "About PySide", "PySide is a cross-platform tool for generating GUI Programs.") def showAboutQT(self): QMessageBox.aboutQt(self.aboutQTButton, "About QT") def center(self): """ Function to center the application """ qRect = self.frameGeometry() centerPoint = QDesktopWidget().availableGeometry().center() qRect.moveCenter(centerPoint) self.move(qRect.topLeft())
class UIWindow(QWidget): def __init__(self, parent=None): super(UIWindow, self).__init__(parent) # mainwindow.setWindowIcon(QtGui.QIcon('PhotoIcon.png')) self.ToolsBTN = QPushButton('text', self) self.ToolsBTN.move(50, 350)
class UIToolTab(QWidget): def __init__(self, parent=None): super(UIToolTab, self).__init__(parent) self.CPSBTN = QPushButton("text2", self) self.CPSBTN.move(100, 350)
def setButton(self): """Function to add a quit button""" myButton=QPushButton("QUIT", self) myButton.move(50,100) myButton.clicked.connect(self.quitter)
class SampleWindow(QWidget): """ Our main window class """ def __init__(self): """ Constructor Function """ # QWidget.__init__(self) # self.setWindowTitle("Icon Sample") # self.setGeometry(300, 300, 200, 150) QWidget.__init__(self) self.setWindowTitle("Icon Sample") self.setGeometry(300, 300, 200, 150) QToolTip.setFont(QFont("Decorative", 8, QFont.Bold)) self.setToolTip('Our Main Window') self.icon = 'C:\Users\Hamed\Documents\soheil sites image\imageedit__9411602959.gif' def setAboutButton(self): """ Function to set About Button """ self.aboutButton = QPushButton("About", self) self.aboutButton.move(110, 100) self.aboutButton.clicked.connect(self.showAbout) def showAbout(self): """ Function to show About Box """ QMessageBox.about( self.aboutButton, "About PySide", "PySide is a cross-platform tool for generating GUI Programs.") def center(self): """ Function to center the application """ qRect = self.frameGeometry() centerPoint = QDesktopWidget().availableGeometry().center() qRect.moveCenter(centerPoint) self.move(qRect.topLeft()) def quitApp(self): """ Function to confirm a message from the user """ userInfo = QMessageBox.question( self, 'Confirmation', "This will quit the application. Do you want to Continue?", QMessageBox.Yes | QMessageBox.No) if userInfo == QMessageBox.Yes: myApp.quit() if userInfo == QMessageBox.No: pass def setIconModes(self): myIcon1 = QIcon(self.icon) myLabel1 = QLabel('sample', self) pixmap1 = myIcon1.pixmap(50, 50, QIcon.Active, QIcon.On) myLabel1.setPixmap(pixmap1) myIcon2 = QIcon(self.icon) myLabel2 = QLabel('sample', self) pixmap2 = myIcon2.pixmap(50, 50, QIcon.Disabled, QIcon.Off) myLabel2.setPixmap(pixmap2) myLabel2.move(50, 0) myIcon3 = QIcon(self.icon) myLabel3 = QLabel('sample', self) pixmap3 = myIcon3.pixmap(50, 50, QIcon.Selected, QIcon.On) myLabel3.setPixmap(pixmap3) myLabel3.move(100, 0) def setIcon(self): """ Function to set Icon """ appIcon = QIcon( 'C:\Users\Hamed\Documents\soheil sites image\imageedit__9411602959.gif' ) self.setWindowIcon(appIcon) def setButton(self): """ Function to add a quit button """ myButton = QPushButton('Quit', self) myButton.move(20, 100) # myButton.clicked.connect(myApp.quit) myButton.clicked.connect(self.quitApp)
class MainWindow(QMainWindow): """ Starting point of the GUI based application """ isMyProgressTimer = False def __init__(self): """ MainWindow Constructor Function""" super(MainWindow, self).__init__() wdgt = QWidget() wdgt.setWindowTitle = "ManageHD" self.setCentralWidget(wdgt) self.InitUI() self.GetParameterFileInfo() def InitUI(self): """ Initialize user created UI elements """ self.qlVidsDone = QLabel('0', self) self.qlVidsInProgress = QLabel('0', self) self.qlStartTime = QLabel(datetime.now().strftime("%a, %d %b %Y %H:%M:%S"), self) self.qlEndTime = QLabel('', self) self.qlTimeLeft = QLabel('', self) self.qlDestinationSpace = QLabel('', self) self.qlArcSpace = QLabel('', self) self.qlProcessingSpeed = QLabel('', self) self.qleSourceDir = QLineEditDirectoriesOnly() self.qleArchiveDir = QLineEditDirectoriesOnly() self.qleDestinationDir = QLineEditDirectoriesOnly() self.qleMaxVidsCap = QLineEditIntsOnly() self.qleVideoTypes = QLineEditNoPeriodsOrCommas() self.qleVideoTypes.installEventFilter(self) self.qpbSourceDir = self.__CreateButton('folder.png',"", 50, self.SelectSingleFileForSourceDirectory) self.qpbArchiveDir = self.__CreateButton('folder.png',"", 50, self.SelectSingleFileForArchiveDirectory) self.qpbTargetDir = self.__CreateButton('folder.png',"", 50, self.SelectSingleFileForTargetDirectory) self.qpbRun = self.__CreateButton(None,"Run", 75, self.Process) self.setWindowTitle("Manage HD Video") self.videoExtensionFileFilter = "Video (*.mkv *.mp4 *.avi)" self.qleVideoTypes.setText("mkv mp4 avi") self.statusLabel = QLabel('Showing Progress') self.progressBar = QProgressBar() self.progressBar.setMinimum(0) self.progressBar.setMaximum(100) self.__CreateActions() self.__CreateMenus() self.fileMenu.addAction(self.stdAction) self.fileMenu.addAction(self.altAction) if Progress.runPlatform == 'win': self.stdAction.setIcon(QIcon('checked.jpg')) self.stdAction.setChecked(True) self.fileMenu.addSeparator() self.fileMenu.addAction(self.exitAction) self.fileMenu.addSeparator() self.helpMenu.addAction(self.aboutAction) self.__SetIcon() self.__CenterWindow() self.__CreateGrid() def eventFilter(self, source, event): #Override """ Override the QMainWindow eventFilter method to add File Mask Validation. """ if (event.type() == QEvent.FocusOut and source is self.qleVideoTypes): self.ValidateFileMask() return QMainWindow.eventFilter(self, source, event) def DisableGuiElements(self): """ Change the setEnabled property of the main GUI elements to False. """ self.qleArchiveDir.setEnabled(False) self.qleDestinationDir.setEnabled(False) self.qleMaxVidsCap.setEnabled(False) self.qleSourceDir.setEnabled(False) self.qleVideoTypes.setEnabled(False) self.qpbArchiveDir.setEnabled(False) self.qpbSourceDir.setEnabled(False) self.qpbTargetDir.setEnabled(False) self.qpbRun.setEnabled(False) def EnableGuiElements(self): """ Change the setEnabled property of the main GUI elements to True. """ self.qleArchiveDir.setEnabled(True) self.qleDestinationDir.setEnabled(True) self.qleMaxVidsCap.setEnabled(True) self.qleSourceDir.setEnabled(True) self.qleVideoTypes.setEnabled(True) self.qpbArchiveDir.setEnabled(True) self.qpbSourceDir.setEnabled(True) self.qpbTargetDir.setEnabled(True) self.qpbRun.setEnabled(True) def __AddGridLabel(self, grid, lblText, custFont, row, column, justification): sd = QLabel(lblText, self) sd.setFont(custFont) grid.addWidget(sd, row, column, alignment = justification) def SelectSingleFileForSourceDirectory(self): self.qleSourceDir.setText( self.InvokeSingleSelectionDirectoryDialog() ) self.ValidateFileMask() def SelectSingleFileForArchiveDirectory(self): self.qleArchiveDir.setText( self.InvokeSingleSelectionDirectoryDialog() ) def SelectSingleFileForTargetDirectory(self): self.qleDestinationDir.setText( self.InvokeSingleSelectionDirectoryDialog() ) def InvokeSingleSelectionFileDialog(self): """ Prompts the user to select a single file from a file dialog window. """ dialog = QFileDialog() dialog.setFileMode(QFileDialog.ExistingFile) dialog.setFilter(self.videoExtensionFileFilter) ret = dialog.exec_() FileNames = dialog.selectedFiles() if len(FileNames) == 0: FileNames.append(None) return FileNames[0] def InvokeSingleSelectionDirectoryDialog(self): """ Prompts the user to select a single directory from a directory dialog window. """ dialog = QFileDialog() dialog.setFileMode(QFileDialog.DirectoryOnly) DirectoryName = dialog.getExistingDirectory() if len(DirectoryName) == 0: DirectoryName = None return DirectoryName def ValidateFileMask(self): """ Function to validate that the entered file mask is valid. """ extensionList = "" if len(self.qleVideoTypes.text().split(" ")) > 0: for videoExtension in self.qleVideoTypes.text().split(" "): extensionList += ("*." + videoExtension + " ") extensionList = extensionList[:-1] self.videoExtensionFileFilter = "Video ({})".format(extensionList) def __CreateGrid(self): g1 = QGridLayout() self.centralWidget().setLayout(g1) g1.setSpacing(5) bold = QFont() bold.setBold(True) self.__AddGridLabel(g1, 'Source Directory:', QFont(), 0, 0, -1) self.__AddGridLabel(g1, 'Archive Directory:', QFont(), 1, 0, -1) self.__AddGridLabel(g1, 'Target Directory:', QFont(), 2, 0, -1) self.__AddGridLabel(g1, 'Max Number of Videos:', QFont(), 3, 0, -1) self.__AddGridLabel(g1, 'Video File Types:', QFont(), 3, 2, -1) #self.__AddGridLabel(g1, 'Max Run Time in Hours:', QFont(), 4, 2, -1) g1.addWidget(self.qleSourceDir, 0, 1, 1, 3) g1.addWidget(self.qleArchiveDir, 1, 1, 1, 3) g1.addWidget(self.qleDestinationDir, 2, 1, 1, 3) g1.addWidget(self.qleMaxVidsCap, 3, 1) g1.addWidget(self.qleVideoTypes, 3, 3) #g1.addWidget(self.qleRunTimeMax, 4, 3) g1.addWidget(self.qpbRun, 10, 3, alignment = -1) g1.addWidget(QLabel('', self), 4, 0,) # Empty Column As Separator g1.addWidget(QLabel('', self), 5, 0,) # Empty Column As Separator self.__AddGridLabel(g1, 'Videos Completed:', bold, 5, 0, -1) self.__AddGridLabel(g1, 'Start Time:', bold, 5, 2, -1) self.__AddGridLabel(g1, 'Videos In Progress:', bold, 6, 0, -1) self.__AddGridLabel(g1, 'Time Remaining:', bold, 7, 2, -1) self.__AddGridLabel(g1, 'Target Space Left:', bold, 7, 0, -1) self.__AddGridLabel(g1, 'Archive Space Left:', bold, 8, 0, -1) self.__AddGridLabel(g1, 'End Time:', bold, 6, 2, -1) self.__AddGridLabel(g1, 'Processing Speed:', bold, 8, 2, -1) g1.addWidget(self.qlVidsDone, 5, 1,) g1.addWidget(self.qlVidsInProgress, 6, 1) g1.addWidget(self.qlStartTime, 5, 3,) g1.addWidget(self.qlEndTime, 6, 3,) g1.addWidget(self.qlTimeLeft, 7, 3,) g1.addWidget(self.qlDestinationSpace, 7, 1,) g1.addWidget(self.qlArcSpace, 8, 1,) g1.addWidget(self.qlProcessingSpeed, 8, 3,) g1.addWidget(self.qpbSourceDir, 0, 4,) g1.addWidget(self.qpbArchiveDir, 1, 4,) g1.addWidget(self.qpbTargetDir, 2, 4,) self.show def GetParameterFileInfo(self): Progress.DeterminePlatform() fm = FileManip() #params = Progress.cliParams.copy() params = fm.ReadSettingsFile() self.qlProcessingSpeed.setText(str(Progress.cliParams['ProcessingSpeedInGBperHour'])) self.qleSourceDir.setText(params['sourceDir']) self.qleArchiveDir.setText(params['archiveDir']) self.qleDestinationDir.setText(params['destinationDir']) def GetDriveSpace(self, path): """ Call the GetDriveSpace() method using an instance of the FileManip class. """ fm = FileManip() return fm.GetDriveSpace(path) def ResetStats(self): """ Change statistical data displays back to their original initialized values. """ Progress.ResetStatuses() self.qlVidsDone.setText( '0') self.qlVidsInProgress.setText('0') self.qlStartTime.setText(datetime.now().strftime("%a, %d %b %Y %H:%M:%S")) self.qlTimeLeft.setText("") if self.qleDestinationDir.text() != "": self.qlDestinationSpace.setText(str(self.GetDriveSpace(self.qleDestinationDir.text()))) if self.qleArchiveDir.text() != "": self.qlArcSpace.setText(str(self.GetDriveSpace(self.qleArchiveDir.text()))) self.qlEndTime.setText("") self.qlProcessingSpeed.setText("") def VerifyRequiredFieldsFilled(self): """ Cancels the RUN functionality and informs the user via Message Box if the required fields are not all completed. """ if self.qleSourceDir.text() == "" or \ self.qleVideoTypes.text() == "" or \ self.qleDestinationDir.text() == "": QMessageBox.critical(self, "Required Field Error", "You have not filled out the three required fields. " "'Source Directory', " "'Target Directory' and " "'Video File Types' " "are all required Fields.", QMessageBox.Ok) return 0 return True def Process(self): """ Batch processing of the source video files begins here. """ result = self.VerifyRequiredFieldsFilled() if result != True: return self.ResetStats() Progress.statuses['ProcessingComplete'] = False self.DisableGuiElements() Params = Progress.cliParams.copy() Params['sourceDir'] = self.qleSourceDir.text() Params['archiveDir'] = self.qleArchiveDir.text() Params['destinationDir'] = self.qleDestinationDir.text() maximumNumVids = "" for idx in range(0, len(self.qleMaxVidsCap.text())): if self.qleMaxVidsCap.text()[idx] != '.': maximumNumVids = maximumNumVids + self.qleMaxVidsCap.text()[idx] if maximumNumVids.isnumeric(): Params['maxNumberOfVideosToProcess'] = '%1.f' % float(self.qleMaxVidsCap.text()) if len(self.qleVideoTypes.text().split(" ")) > 0: extensionList = "" for videoExtension in self.qleVideoTypes.text().split(" "): extensionList += (videoExtension + ",") else: extensionList = None Params['videoTypes'] = extensionList #Create and instance of the processing class pm = ProcessMovies() #Disable applicable GUI elements self.DisableGuiElements #Spawn a thread to run this Thread(target=pm.StartWithGUI, args=(Params,)).start() sleep(1) self.qlTimeLeft.setText(Progress.CalculateTimeRemaining()) Progress.statuses['StatusesHaveChanged'] = True return def __CreateButton(self, folderIcon, txt, pxSize, actionFunction): """ Function to add a button """ if folderIcon != None: folderIcon = QIcon('folder.png') myButton = QPushButton(folderIcon, "") else: myButton = QPushButton(txt) myButton.setMaximumWidth(pxSize) myButton.clicked.connect(actionFunction) return myButton def aboutHelp(self): """ Displays the ABOUT box and sets its content. """ QMessageBox.about(self, "About ManageHD", "Program written in Python v3.4 \n\n" "ManageHD allows you to select an entire " "directory of HD video files and lower their " "resolution from 1080 HD to 720 HD, in batch. " "It calls the HandBrake Command Line Interface " "(CLI) in order to re-encode each video. \n\nYou must " "have the Handbrake CLI installed to use this " "software. " "The CLI (command line interface) can be downloaded at:\n\n " " http://handbrake.fr/downloads2.php \n\n" "The average video file at 720 HD " "is generally one fourth to one sixth the size " "of its 1080 HD source file. \n\n" "Coding was done by InfanteLabz. \n\n" "This sofware is released under GPL v3 " "licensing. \n\n Developed on Wing IDE") def exitFile(self): """ Exits the Main Window, ending the program. """ self.close() def __CreateActions(self): """ Function to create actions for menus """ self.stdAction = QAction(QIcon('convert.png'), 'Create MKV files', self, shortcut = "Ctrl+K", statusTip = "File format set to MKV container", triggered = self.stdConversion, checkable = True) self.altAction = QAction(QIcon('convert.png'), 'Create MP4 files', self, shortcut = "Ctrl+P", statusTip = "File format set to MP4 file", triggered = self.altConversion, checkable = True) self.exitAction = QAction(QIcon('exit.png'), '&Quit', self, shortcut="Ctrl+Q", statusTip = "Exit the Application", triggered=self.exitFile) #self.copyAction = QAction(QIcon('copy.png'), 'C&opy', #self, shortcut="Ctrl+C", #statusTip="Copy", #triggered=self.CopyFunction) self.aboutAction = QAction(QIcon('about.png'), 'A&bout', self, statusTip="Displays info about ManageHD", triggered=self.aboutHelp) def __CreateMenus(self): """ Function to create actual menu bar """ self.fileMenu = self.menuBar().addMenu("&File") self.helpMenu = self.menuBar().addMenu("&Help") def __CenterWindow(self): """ Function to center the window """ qRect = self.frameGeometry() centerPoint = QDesktopWidget().availableGeometry().center() qRect.moveCenter(centerPoint) self.move(qRect.topLeft()) def __SetAboutBox(self): """ Function to position and wire the ABOUT box """ self.aboutButton = QPushButton("About", self) self.aboutButton.move(200, 100) self.aboutButton.clicked.connect(self.ShowAbout) def __SetIcon(self): """ Function to set Icon """ appIcon = QIcon('ManageHD_Icon.png') self.setWindowIcon(appIcon) def DisplayAbnormalTerminationStatus(self, status): # Not Implemented pass def GetArchiveDirectory(self): # Not Implemented pass def stdConversion(self): """ Called by the STANDARD menu item under FILE. Sets ManageHD to perform the standard Handbrake conversion. """ Progress.statuses['HandbrakeOptionsString'] = str(" -i {0} -o {1} -f mkv --width 1280 --crop 0:0:0:0 --decomb -s 1 -N eng -m --large-file --encoder x264 -q 19 -E ffac3") Progress.statuses['OutputExtension'] = 'mkv' self.altAction.setChecked(False) if Progress.runPlatform == "win": self.altAction.setIcon(QIcon('convert.png')) self.stdAction.setIcon(QIcon('checked.jpg')) self.stdAction.setChecked(True) def altConversion(self): """ Called by the ALTERNATE menu item under FILE. Sets ManageHD to perform Handbrake conversions using an alternate series of settings. """ Progress.statuses['HandbrakeOptionsString'] = str(" -i {0} -o {1} -f mp4 --width 1280 --crop 0:0:0:0 --decomb -s 1 -N eng -m --large-file --encoder x264 -q 19 -E ffac3") Progress.statuses['OutputExtension'] = 'mp4' self.stdAction.setChecked(False) if Progress.runPlatform == "win": self.altAction.setIcon(QIcon('checked.jpg')) self.stdAction.setIcon(QIcon('convert.png')) self.altAction.setChecked(True) def CopyFunction(): # Not Implemented pass def ValidateAndRun(self): # Not Implemented pass
class SampleWindow(QWidget): """ Our main window class """ def __init__(self): """ Constructor Function """ # QWidget.__init__(self) # self.setWindowTitle("Icon Sample") # self.setGeometry(300, 300, 200, 150) QWidget.__init__(self) self.setWindowTitle("Icon Sample") self.setGeometry(300, 300, 200, 150) QToolTip.setFont(QFont("Decorative", 8, QFont.Bold)) self.setToolTip('Our Main Window') self.icon='C:\Users\Hamed\Documents\soheil sites image\imageedit__9411602959.gif' # Actual menu bar item creation def CreateMenus(self): """ Function to create actual menu bar """ self.fileMenu = self.menuBar().addMenu("&File") self.editMenu = self.menuBar().addMenu("&Edit") self.helpMenu = self.menuBar().addMenu("&Help") def setAboutButton(self): """ Function to set About Button """ self.aboutButton = QPushButton("About", self) self.aboutButton.move(110, 100) self.aboutButton.clicked.connect(self.showAbout) def showAbout(self): """ Function to show About Box """ QMessageBox.about(self.aboutButton, "About PySide", "PySide is a cross-platform tool for generating GUI Programs.") def center(self): """ Function to center the application """ qRect = self.frameGeometry() centerPoint = QDesktopWidget().availableGeometry().center() qRect.moveCenter(centerPoint) self.move(qRect.topLeft()) def quitApp(self): """ Function to confirm a message from the user """ userInfo = QMessageBox.question(self, 'Confirmation', "This will quit the application. Do you want to Continue?", QMessageBox.Yes | QMessageBox.No) if userInfo == QMessageBox.Yes: myApp.quit() if userInfo == QMessageBox.No: pass def setIconModes(self): myIcon1 = QIcon( self.icon) myLabel1 = QLabel('sample', self) pixmap1 = myIcon1.pixmap(50, 50, QIcon.Active, QIcon.On) myLabel1.setPixmap(pixmap1) myIcon2 = QIcon( self.icon) myLabel2 = QLabel('sample', self) pixmap2 = myIcon2.pixmap(50, 50, QIcon.Disabled, QIcon.Off) myLabel2.setPixmap(pixmap2) myLabel2.move(50, 0) myIcon3 = QIcon( self.icon) myLabel3 = QLabel('sample', self) pixmap3 = myIcon3.pixmap(50, 50, QIcon.Selected, QIcon.On) myLabel3.setPixmap(pixmap3) myLabel3.move(100, 0) def setIcon(self): """ Function to set Icon """ appIcon = QIcon('C:\Users\Hamed\Documents\soheil sites image\imageedit__9411602959.gif') self.setWindowIcon(appIcon) def setButton(self): """ Function to add a quit button """ myButton = QPushButton('Quit', self) myButton.move(20, 100) # myButton.clicked.connect(myApp.quit) myButton.clicked.connect(self.quitApp)
class SampleWindow(QMainWindow): """ Our main window class """ def __init__(self,fileName=None): """ Constructor Function """ # QWidget.__init__(self) # self.setWindowTitle("Icon Sample") # self.setGeometry(300, 300, 200, 150) QMainWindow.__init__(self) self.setWindowTitle("Icon Sample") self.setGeometry(300, 300, 200, 150) QToolTip.setFont(QFont("Decorative", 8, QFont.Bold)) self.setToolTip('Our Main Window') self.icon='C:\Users\Hamed\Documents\soheil sites image\imageedit__9411602959.gif' self.textEdit = QTextEdit() self.setCentralWidget(self.textEdit) self.fileName = None self.filters = "Text files (*.txt)" openFile = QAction(QIcon('open.png'), 'Open', self) openFile.setShortcut('Ctrl+O') openFile.setStatusTip('Open new File') openFile.triggered.connect(self.showDialog) menubar = self.menuBar() # fileMenu = menubar.addMenu('&File') # fileMenu.addAction(openFile) self.setGeometry(300, 300, 350, 300) self.setWindowTitle('Example - File Dialog') # self.myNameLE = QLineEdit(self) # self.myAgeLE = QLineEdit(self) # self.myChoiceLE = QLineEdit(self) self.statusLabel = QLabel('Showing Progress') self.progressBar = QProgressBar() self.progressBar.setMinimum(0) self.progressBar.setMaximum(100) ##################@@@@@@@@@@@@@@2 self.threads = [] self.addWorker(MyWorkerThread(1)) self.addWorker(MyWorkerThread(2)) #######################@@@@@@@@@@@@@ self.show() ##########################@@@@@@@@@@ def addWorker(self, worker): worker.message.connect(self.printMessage, QtCore.Qt.QueuedConnection) # connect the finished signal to method so that we are notified worker.finished.connect(self.workersFinished) self.threads.append(worker) def startWorkers(self): for worker in self.threads: worker.start() # no wait, no finished. you start the threads and leave. def workersFinished(self): if all(worker.isFinished() for worker in self.threads): # wait until all the threads finished QtCore.QCoreApplication.instance().quit() @QtCore.Slot(str) def printMessage(self, text): sys.stdout.write(text+'\n') sys.stdout.flush() ################################ def openAbout(self): aboutDialog = QtGui.QDialog(self) # aboutUi = about.About_Dialog() # aboutUi.setupUi(aboutDialog) aboutDialog.show() def newwindow(self): # w = W1() # w.show() # self.hide() # form = Form() # form.show() w2 = chooseoption.Form1(self) w2.show() import webbrowser your_swf_url='E:\soheil\web_site_root\ieee\all_functions\linux server\python GUI\Double_angle_off.swf' webbrowser.open(your_swf_url) # self.wid = QWidget() # self.wid.resize(250, 150) # self.wid.setWindowTitle('NewWindow') # self.wid.show() # self.actionAbout.triggered.connect(self.openAbout) def retranslateUi(self, Dialog): Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8)) self.aboutLbl.setText(QtGui.QApplication.translate("Dialog", "Mailer version 0.0.1 by .....", None, QtGui.QApplication.UnicodeUTF8)) def showNameDialog(self): text, ok = QInputDialog.getText(self, 'Input Text Dialog', 'Enter your name:') if ok: self.myNameLE.setText(str(text)) def showDialog(self): fileName, _ = QFileDialog.getOpenFileName(self, "Open Text Files", "c:/", "Text files(*.txt)") try: contents = open(fileName, 'r') with contents: data = contents.read() self.textEdit.setText(data) except: pass def CreateStatusBar(self): """ Function to create the status bar """ self.myStatusBar = QStatusBar() self.progressBar.setValue(10) self.myStatusBar.addWidget(self.statusLabel, 1) self.myStatusBar.addWidget(self.progressBar, 2) self.setStatusBar(self.myStatusBar) def ShowProgress(self): """ Function to show progress """ import time while(self.progressBar.value() < self.progressBar.maximum()): self.progressBar.setValue(self.progressBar.value() + 10) # time.sleep(1) self.statusLabel.setText('Ready') def SetupComponents(self): """ Function to setup status bar, central widget, menu bar """ self.myStatusBar = QStatusBar() self.setStatusBar(self.myStatusBar) self.myStatusBar.showMessage('Ready', 10000) self.textEdit = QTextEdit() self.setCentralWidget(self.textEdit) # self.CreateActions() # self.CreateMenus() # self.fileMenu.addAction(self.newAction) # self.fileMenu.addSeparator() # self.fileMenu.addAction(self.exitAction) # self.editMenu.addAction(self.copyAction) # self.fileMenu.addSeparator() # self.editMenu.addAction(self.pasteAction) # self.helpMenu.addAction(self.aboutAction) self.myStatusBar = QStatusBar() self.setStatusBar(self.myStatusBar) self.myStatusBar.showMessage('Ready', 10000) self.CreateActions() self.CreateMenus() self.CreateToolBar() self.fileMenu.addAction(self.newAction) self.fileMenu.addAction(self.openAction) self.fileMenu.addAction(self.saveAction) self.fileMenu.addSeparator() self.fileMenu.addAction(self.exitAction) self.editMenu.addAction(self.cutAction) self.editMenu.addAction(self.copyAction) self.editMenu.addAction(self.pasteAction) self.editMenu.addSeparator() self.editMenu.addAction(self.undoAction) self.editMenu.addAction(self.redoAction) self.editMenu.addAction(self.ss_image) self.editMenu.addSeparator() self.editMenu.addAction(self.selectAllAction) self.formatMenu.addAction(self.fontAction) self.helpMenu.addAction(self.aboutAction) self.helpMenu.addSeparator() self.helpMenu.addAction(self.aboutQtAction) self.mainToolBar.addAction(self.newAction) self.mainToolBar.addAction(self.openAction) self.mainToolBar.addAction(self.saveAction) self.mainToolBar.addSeparator() self.mainToolBar.addAction(self.cutAction) self.mainToolBar.addAction(self.copyAction) self.mainToolBar.addAction(self.pasteAction) self.mainToolBar.addSeparator() self.mainToolBar.addAction(self.undoAction) self.mainToolBar.addAction(self.redoAction) def openFile(self): self.fileName, self.filterName =QFileDialog.getOpenFileName(self) try: self.textEdit.setText(open(self.fileName).read()) except: pass # Slots called when the menu actions are triggered def newFile(self): self.textEdit.setText('') def exitFile(self): self.close() def aboutHelp(self): QMessageBox.about(self, "About Simple Text Editor", "This example demonstrates the use " "of Menu Bar") def fontChange(self): (font, ok) = QFontDialog.getFont(QFont("Helvetica [Cronyx]", 10), self) if ok: self.textEdit.setCurrentFont(font) def saveFile(self): if self.fileName == None or self.fileName == '': self.fileName, self.filterName = QFileDialog.getSaveFileName(self, \ filter=self.filters) if(self.fileName != ''): file = open(self.fileName, 'w') file.write(self.textEdit.toPlainText()) self.statusBar().showMessage("File saved", 2000) def image_ss(self): from PySide import QtGui, QtCore import wxpython_flash_Simple_working hbox = QtGui.QHBoxLayout(self) pixmap = QtGui.QPixmap('C:\Users\Hamed\Pictures\LED\led.jpg') lbl = QtGui.QLabel(self) lbl.setPixmap(pixmap) hbox.addWidget(lbl) self.setLayout(hbox) self.setGeometry(300, 300, 280, 170) self.setWindowTitle('Red Rock') self.show() # from PIL import Image # from PySide.QtGui import QImage, QImageReader, QLabel, QPixmap, QApplication # # im = Image.open('C:\Users\Hamed\Documents\soheil sites image\imageedit__9411602959.gif') # data = im.tostring('raw') # ##app = QApplication([]) ## image = QImage(data); # image = QImage(data, im.size[0], im.size[1], QImage.Format_ARGB32) # pix = QPixmap.fromImage(image) # lbl = QLabel() # lbl.setPixmap(pix) # lbl.show() def image_ss_main(self): from PySide import QtGui, QtCore hbox = QtGui.QHBoxLayout(self) pixmap = QtGui.QPixmap('C:\Users\Hamed\Pictures\LED\led.jpg') lbl = QtGui.QLabel(self) lbl.setPixmap(pixmap) hbox.addWidget(lbl) self.setLayout(hbox) self.setGeometry(300, 300, 280, 170) self.setWindowTitle('Red Rock') self.show() # from PIL import Image # from PySide.QtGui import QImage, QImageReader, QLabel, QPixmap, QApplication # # im = Image.open('C:\Users\Hamed\Documents\soheil sites image\imageedit__9411602959.gif') # data = im.tostring('raw') # ##app = QApplication([]) ## image = QImage(data); # image = QImage(data, im.size[0], im.size[1], QImage.Format_ARGB32) # pix = QPixmap.fromImage(image) # lbl = QLabel() # lbl.setPixmap(pix) # lbl.show( def CreateActions(self): """ Function to create actions for menus """ self.newAction = QAction( QIcon('new.png'), '&New', self, shortcut=QKeySequence.New, statusTip="Create a New File", triggered=self.newFile) self.exitAction = QAction( QIcon(self.icon), 'E&xit', self, shortcut="Ctrl+Q", statusTip="Exit the Application", triggered=self.exitFile) self.copyAction = QAction( QIcon('copy.png'), 'C&opy', self, shortcut="Ctrl+C", statusTip="Copy", triggered=self.textEdit.copy) self.pasteAction = QAction( QIcon('paste.png'), '&Paste', self, shortcut="Ctrl+V", statusTip="Paste", triggered=self.textEdit.paste) self.aboutAction = QAction( QIcon('about.png'), 'A&bout', self, statusTip="Displays info about text editor", triggered=self.aboutHelp) self.openAction = QAction( QIcon('open.png'), 'O&pen', self, shortcut=QKeySequence.Open, statusTip="Open an existing file", triggered=self.openFile) self.saveAction = QAction( QIcon('save.png'), '&Save', self, shortcut=QKeySequence.Save, statusTip="Save the current file to disk", triggered=self.saveFile) self.cutAction = QAction( QIcon('cut.png'), 'C&ut', self, shortcut=QKeySequence.Cut, statusTip="Cut the current selection to clipboard", triggered=self.textEdit.cut) self.undoAction = QAction( QIcon('undo.png'),'Undo', self, shortcut=QKeySequence.Undo, statusTip="Undo previous action", triggered=self.textEdit.undo) self.redoAction = QAction( QIcon('redo.png'),'Redo', self, shortcut=QKeySequence.Redo, statusTip="Redo previous action", triggered=self.textEdit.redo) self.selectAllAction = QAction( QIcon('selectAll.png'), 'Select All', self, statusTip="Select All", triggered=self.textEdit.selectAll) self.fontAction = QAction( 'F&ont', self, statusTip = "Modify font properties", triggered = self.fontChange) self.aboutAction = QAction( QIcon('about.png'), 'A&bout', self, statusTip="Displays info about text editor", # triggered=self.aboutHelp) triggered=self.newwindow) self.aboutQtAction = QAction("About &Qt", self, statusTip="Show the Qt library's About box", triggered=qApp.aboutQt) self.ss_image = QAction("Insert &.SWF(flash)", self, statusTip="Show the Qt library's About box", triggered=self.image_ss) self.actionAbout = QAction("image &Qt", self, statusTip="Show the Qt library's About box", triggered=self.openAbout) # Actual menu bar item creation def CreateToolBar(self): """ Function to create actual menu bar """ self.mainToolBar = self.addToolBar('Main') self.mainToolBar.addAction(self.newAction) self.mainToolBar.addSeparator() self.mainToolBar.addAction(self.copyAction) self.mainToolBar.addAction(self.pasteAction) # Actual menu bar item creation def CreateMenus(self): """ Function to create actual menu bar """ self.fileMenu = self.menuBar().addMenu("&File") self.fileMenu.addSeparator() self.editMenu = self.menuBar().addMenu("&Edit") self.helpMenu = self.menuBar().addMenu("&Help") self.formatMenu = self.menuBar().addMenu("F&ormat") def setAboutButton(self): """ Function to set About Button """ self.aboutButton = QPushButton("About", self) self.aboutButton.move(110, 100) self.aboutButton.clicked.connect(self.showAbout) def showAbout(self): """ Function to show About Box """ QMessageBox.about(self.aboutButton, "About PySide", "PySide is a cross-platform tool for generating GUI Programs.") def center(self): """ Function to center the application """ qRect = self.frameGeometry() centerPoint = QDesktopWidget().availableGeometry().center() qRect.moveCenter(centerPoint) self.move(qRect.topLeft()) def quitApp(self): """ Function to confirm a message from the user """ userInfo = QMessageBox.question(self, 'Confirmation', "This will quit the application. Do you want to Continue?", QMessageBox.Yes | QMessageBox.No) if userInfo == QMessageBox.Yes: myApp.quit() if userInfo == QMessageBox.No: pass def setIconModes(self): myIcon1 = QIcon( self.icon) myLabel1 = QLabel('sample', self) pixmap1 = myIcon1.pixmap(50, 50, QIcon.Active, QIcon.On) myLabel1.setPixmap(pixmap1) myIcon2 = QIcon( self.icon) myLabel2 = QLabel('sample', self) pixmap2 = myIcon2.pixmap(50, 50, QIcon.Disabled, QIcon.Off) myLabel2.setPixmap(pixmap2) myLabel2.move(50, 0) myIcon3 = QIcon( self.icon) myLabel3 = QLabel('sample', self) pixmap3 = myIcon3.pixmap(50, 50, QIcon.Selected, QIcon.On) myLabel3.setPixmap(pixmap3) myLabel3.move(100, 0) def setIcon(self): """ Function to set Icon """ from PySide.QtGui import QPixmap pixmap = QPixmap(r'C:\Users\Hamed\Pictures\LED\led.jpg') # appIcon = QIcon('C:\Users\Hamed\Documents\soheil sites image\imageedit__9411602959.gif') appIcon = QIcon(pixmap) self.setWindowIcon(appIcon) def setButton(self): """ Function to add a quit button """ myButton = QPushButton('Quit', self) myButton.move(20, 100) # myButton.clicked.connect(myApp.quit) myButton.clicked.connect(self.quitApp)