def __init__(self): generic.GenericGui.__init__(self) window = QWidget() window.setWindowTitle('quichem-pyside') self.compiler_view = QListWidget() self.compiler_view.currentRowChanged.connect(self.show_source) self.stacked_widget = QStackedWidget() self.stacked_widget.setFrameStyle(QFrame.StyledPanel | QFrame.Raised) self.edit = QLineEdit() self.edit.setPlaceholderText('Type quichem input...') self.edit.textChanged.connect(self.change_value) self.view = QWebView() self.view.page().mainFrame().setScrollBarPolicy(Qt.Vertical, Qt.ScrollBarAlwaysOff) self.view.page().action(QWebPage.Reload).setVisible(False) self.view.setMaximumHeight(0) self.view.setUrl('qrc:/web/page.html') self.view.setZoomFactor(2) self.view.page().mainFrame().contentsSizeChanged.connect( self._resize_view) # For debugging JS: ## from PySide.QtWebKit import QWebSettings ## QWebSettings.globalSettings().setAttribute( ## QWebSettings.DeveloperExtrasEnabled, True) button_image = QPushButton('Copy as Image') button_image.clicked.connect(self.set_clipboard_image) button_image.setToolTip('Then paste into any graphics program') button_word = QPushButton('Copy as MS Word Equation') button_word.clicked.connect(self.set_clipboard_word) button_html = QPushButton('Copy as Formatted Text') button_html.clicked.connect(self.set_clipboard_html) line = QFrame() line.setFrameShape(QFrame.HLine) line.setFrameShadow(QFrame.Sunken) button_layout = QHBoxLayout() button_layout.addStretch() button_layout.addWidget(button_image) button_layout.addWidget(button_word) button_layout.addWidget(button_html) source_layout = QHBoxLayout() source_layout.addWidget(self.compiler_view) source_layout.addWidget(self.stacked_widget, 1) QVBoxLayout(window) window.layout().addWidget(self.edit) window.layout().addWidget(self.view) window.layout().addLayout(button_layout) window.layout().addWidget(line) window.layout().addLayout(source_layout, 1) window.show() window.resize(window.minimumWidth(), window.height()) # To prevent garbage collection of internal Qt object. self._window = window
def __init__(self): """ MainWindow Constructor Function""" super(MainWindow, self).__init__() wdgt = QWidget() wdgt.setWindowTitle = "ManageHD" self.setCentralWidget(wdgt) self.InitUI() self.GetParameterFileInfo()
def __init__(self): url = QLineEdit() urlLabel = QLabel('Url') messages = QTextEdit() messagesLabel = QLabel('Messages') links = QTableWidget(0, 2) linksLabel = QLabel('Links') clearMessages = QPushButton('Clear Messages') checkIfOnline = QPushButton('Check If Online') addSelectedLink = QPushButton('Add Link') removeSelectedLink = QPushButton('Remove Selected Link') messages.setReadOnly(True) links.setHorizontalHeaderLabels(['Url', 'Status']) links.horizontalHeader().setResizeMode(QHeaderView.Stretch) links.horizontalHeader().setResizeMode(1, QHeaderView.Fixed) # set the events url.returnPressed.connect(self.select_stream_from_entry) links.itemDoubleClicked.connect(self.select_stream_from_link) clearMessages.clicked.connect(self.clear_messages) checkIfOnline.clicked.connect(self.check_if_online) addSelectedLink.clicked.connect(self.add_selected_link) removeSelectedLink.clicked.connect(self.remove_selected_link) # set the layouts mainLayout = QGridLayout() # first row mainLayout.addWidget(urlLabel, 0, 0, 1, 2) # spans 2 columns mainLayout.addWidget(linksLabel, 0, 2, 1, 3) # spans 3 columns # second row (links widget occupies 2 rows and 2 columns) mainLayout.addWidget(url, 1, 0, 1, 2) # spans 2 columns mainLayout.addWidget(links, 1, 2, 2, 3) # spans 3 columns # third row (messages widget occupies 2 columns) mainLayout.addWidget(messages, 2, 0, 1, 2) # fourth row mainLayout.addWidget(messagesLabel, 3, 0) mainLayout.addWidget(clearMessages, 3, 1) mainLayout.addWidget(checkIfOnline, 3, 2) mainLayout.addWidget(addSelectedLink, 3, 3) mainLayout.addWidget(removeSelectedLink, 3, 4) window = QWidget() window.setLayout(mainLayout) window.setWindowTitle('Live Streamer') window.resize(700, 350) window.show() self.url_ui = url self.messages_ui = messages self.links_ui = links self.window_ui = window self.links = set()
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 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()
def __init__( self ): url = QLineEdit() quality = QLineEdit() urlLabel = QLabel( 'Url' ) qualityLabel = QLabel( 'Quality' ) messages = QTextEdit() messagesLabel = QLabel( 'Messages' ) links = QTableWidget( 0, 2 ) linksLabel = QLabel( 'Links' ) clearMessages = QPushButton( 'Clear Messages' ) checkIfOnline = QPushButton( 'Check If Online' ) addSelectedLink = QPushButton( 'Add Link' ) removeSelectedLink = QPushButton( 'Remove Selected Link' ) messages.setReadOnly( True ) links.setHorizontalHeaderLabels( [ 'Url', 'Status' ] ) links.horizontalHeader().setResizeMode( QHeaderView.Stretch ) links.horizontalHeader().setResizeMode( 1, QHeaderView.Fixed ) # set the events url.returnPressed.connect( self.select_stream_from_entry ) quality.returnPressed.connect( self.select_stream_from_entry ) links.itemDoubleClicked.connect( self.select_stream_from_link ) clearMessages.clicked.connect( self.clear_messages ) checkIfOnline.clicked.connect( self.check_if_online ) addSelectedLink.clicked.connect( self.add_selected_link ) removeSelectedLink.clicked.connect( self.remove_selected_link ) #set shortcut checkIfOnline.setShortcut(QKeySequence(Qt.Key_F5)) # set the layouts mainLayout = QGridLayout() # first row mainLayout.addWidget( urlLabel, 0, 0, 1, 1 ) # spans 1 column mainLayout.addWidget( qualityLabel, 0, 1, 1, 1 )# spans 1 column mainLayout.addWidget( linksLabel, 0, 2, 1, 3 ) # spans 3 columns # second row (links widget occupies 2 rows and 2 columns) mainLayout.addWidget( url, 1, 0, 1, 1 ) # spans 1 column mainLayout.addWidget( quality, 1, 1, 1, 1 ) # spans 1 column mainLayout.addWidget( links, 1, 2, 2, 3 ) # spans 3 columns # third row (messages widget occupies 2 columns) mainLayout.addWidget( messages, 2, 0, 1, 2 ) # fourth row mainLayout.addWidget( messagesLabel, 3, 0 ) mainLayout.addWidget( clearMessages, 3, 1 ) mainLayout.addWidget( checkIfOnline, 3, 2 ) mainLayout.addWidget( addSelectedLink, 3, 3 ) mainLayout.addWidget( removeSelectedLink, 3, 4 ) window = QWidget() window.setLayout( mainLayout ) window.setWindowTitle( 'Live Streamer' ) window.resize( 700, 350 ) window.show() self.url_ui = url self.quality_ui = quality self.messages_ui = messages self.links_ui = links self.window_ui = window self.links = set() self.data_file = os.path.join(os.path.expanduser("~"), ".config", "livestreamer-ui", "data.txt") folder=os.path.dirname(self.data_file) if not os.path.exists(folder): os.makedirs(folder)
from PySide.QtGui import QLabel from PySide.QtGui import QPushButton from PySide.QtGui import QWidget from PySide.QtGui import QVBoxLayout from PySide.QtGui import QHBoxLayout def foo(parent): vbox = QHBoxLayout() vbox.addWidget( QLabel('this is the label of component', parent) ) vbox.addWidget( QPushButton(parent, 'button') ) return vbox # Create the application object app = QApplication(sys.argv) # Create a simple dialog box mainw = QWidget(sys.argv) mainw.resize(250,150) mainw.setWindowTitle('Mainview (plugins)') mainlayout = QVBoxLayout() mainlayout.addLayout( foo(mainw) ) mainw.setLayout( mainlayout ) mainw.show() sys.exit(app.exec_())
import zipfile print 'import ZipFile' import sys print 'import sys' import urllib2 print 'import urllib2' import time print 'all imports done (time last import)' raise print 'Before anything apart from importing' app = QApplication(sys.argv) update_dialog = QWidget() update_dialog.resize(350, 100) update_dialog.setWindowTitle('Updater') update_dialog.show() update_dialog_lbl = QLabel(update_dialog) update_dialog_lbl.setGeometry(10, 40, 340, 25) update_dialog_lbl.setOpenExternalLinks(True) update_dialog_lbl.setText('Updating! (Screen will hang, it\'s normal.)') # sys.exit(app.exec_()) running = True versionNew = 0 success = False updater() # this code will stall the rest of the code until the thread says 'running = False'
class MyMDIApp(QMainWindow): def __init__(self): super(MyMDIApp, self).__init__() self.setGeometry(50, 40, 1200, 960) # self.setAcceptDrops(True) self.filelist = [] # ==================================== # UIの生成 # ==================================== # :: MDIワークスペースのインスタンス化 self.workspace = QWorkspace() self.workspace.setWindowTitle("Simple WorkSpace Exmaple") # :: lite_listview self.lite_listview = LiteListView() self.lite_listview.addItems(["abc", "def", "ghi", "jkl"]) self.lite_listview.resize(150, 300) self.workspace.addWindow(self.lite_listview) # :: ボタンs layout = QHBoxLayout() self.btn_ana = QPushButton("Analysis") self.btn_plot = QPushButton("Plot") self.btn_save = QPushButton("Save") layout.addWidget(self.btn_ana) layout.addWidget(self.btn_plot) layout.addWidget(self.btn_save) self.btn_wid = QWidget() self.btn_wid.setWindowTitle("Feauters Analysis") self.btn_wid.setLayout(layout) self.workspace.addWindow(self.btn_wid) # :: Figure.FigureImapctAndHarmonic # : FIH用FigureCanvasグラフオブジェクト self.fig_impandharm = FigureImapctAndHarmonic() self.fig_impandharm.setWindowTitle("Figure Impact & Harmonic") self.workspace.addWindow(self.fig_impandharm) self.fig_impandharm.close() # : 以下コントローラ layout2 = QHBoxLayout() self.fih_label = QLabel() self.fih_label.setText(self.tr("Impact & Harm")) self.fih_btn_ana = QPushButton("Analysis") self.fih_btn_plot = QPushButton("Plot") self.fih_btn_save = QPushButton("Save") layout2.addWidget(self.fih_label) layout2.addWidget(self.fih_btn_ana) layout2.addWidget(self.fih_btn_plot) layout2.addWidget(self.fih_btn_save) self.btn_wid2 = QWidget() self.btn_wid2.setWindowTitle("Imapct & Harm") self.btn_wid2.setLayout(layout2) self.workspace.addWindow(self.btn_wid2) self.fih_btn_ana.clicked.connect(self.run_FIH_analysis) self.fih_btn_plot.clicked.connect(self.run_FIH_plot) self.fih_btn_save.clicked.connect(self.fig_impandharm.save) # :: キャンバス self.sig_canvas = SignalDataCanvas() # self.sig_canvas.setWindowTitle(self.tr(u"特徴量グラフ")) self.sig_canvas.setWindowTitle(u"特徴量グラフ") self.workspace.addWindow(self.sig_canvas) self.sig_canvas.close() # :: ステータスバー self.myStatusBar = QStatusBar() self.setStatusBar(self.myStatusBar) self.myStatusBar.showMessage('Ready', 1000) # :: プログラスバー self.progressBar = QProgressBar() self.myStatusBar.addPermanentWidget(self.progressBar) self.progressBar.reset() self.progressBar.setVisible(False) self.progressBar.setValue(0) # :: MainWidgetに追加 # self.workspace.tile() self.setCentralWidget(self.workspace) self.setCSS() # ==================================== # シグナルスロットのコネクト # ==================================== # lite_listview self.lite_listview.fileDropped.connect(self.set_filelist) self.lite_listview.clicked.connect(self.file_selected) # Analysisボタンで解析実行 self.btn_ana.clicked.connect(self.run_analysis) self.btn_plot.clicked.connect(self.run_plot) # ***************************************************** # ファイルインプット用スロット # ***************************************************** @Slot() def file_selected(self, index): """listviewがクリックされたときの動作""" selected_stritem = index.data(Qt.DisplayRole) s = "Clicked[%d] : %r" % (index.row(), selected_stritem) self.flush(s) @Slot() def set_filelist(self, file_list): self.filelist = file_list self.flush("Load File List") # ***************************************************** # Window2: インパクト音&自由振動音解析用 # ***************************************************** @Slot() def run_FIH_analysis(self): """解析データの受け渡し用中間スロット""" self.flush("> (QThread) run analysis") self.p2 = thread_analysis_imp_and_hrm() self.p2.set_option(self.filelist) self.p2.progress.connect(self.progress) self.p2.start() @Slot() def run_FIH_plot(self): res = self.p2.get_result() self.fig_impandharm.plot(resuls=res) pass # ***************************************************** # Window1: 全データ統計解析用 # ***************************************************** @Slot() def run_analysis(self): """特徴量算出アルゴリズム実行""" self.flush("> (QThread) run analysis") self.p = thProcess() self.p.set_option(self.filelist) self.p.progress.connect(self.progress) self.p.start() @Slot() def run_plot(self): """特徴量マップの表示""" # ; データ取得 # res = array(self.result) res = array(self.p.get_result()) # : canvas = BubleChartCanvas() self.workspace.addWindow(canvas) canvas.show() # グラフプロット names = [os.path.basename(p) for p in self.filelist] canvas.bubbleplot(xdata=res[:, 0], data=res[:, 1], names=names) canvas.set_xlabel("Katasa").set_ylabel("Matomari").canvas_update() # ***************************************************** # 共通関数 # ***************************************************** def flush(self, s, ms=1): maxlen = 50 if len(s) > maxlen: s = s[:10] + "..." + s[-maxlen:] self.myStatusBar.showMessage(s, ms * 1000) def progress(self, value=None): if value < 0: self.progressBar.reset() self.progressBar.setVisible(False) if value >= 0: self.progressBar.setVisible(True) self.progressBar.setValue(value) def setCSS(self): """cssを読みこんでセット """ with open(CSS_PATH, "r") as f: self.setStyleSheet("".join(f.readlines()))
cpi_two_label = QLabel("CPI2 (1600):") layout.addWidget(cpi_two_label, 2, 2) cpi_two_spin_box = QSpinBox() cpi_two_spin_box.setRange(50, 6500) cpi_two_spin_box.setValue(1600) cpi_two_spin_box.setSingleStep(50) layout.addWidget(cpi_two_spin_box, 2, 3) # polling_rate polling_rate_label = QLabel("Polling rate (1000):") layout.addWidget(polling_rate_label, 3, 0) polling_rate_combo_box = QComboBox() polling_rate_combo_box.addItem("1000") polling_rate_combo_box.addItem("500") polling_rate_combo_box.addItem("250") polling_rate_combo_box.addItem("125") layout.addWidget(polling_rate_combo_box, 3, 1) save_push_button = QPushButton("Save settings") save_push_button.clicked.connect(save_slot) layout.addWidget(save_push_button, 4, 0) reset_push_button = QPushButton("Reset to factory defaults") layout.addWidget(reset_push_button, 4, 1) central_widget = QWidget() central_widget.setWindowTitle("Rivalctl-Qt") central_widget.setLayout(layout) central_widget.show() app.exec_()
class MainWindow(QMainWindow): start_acq = Signal(str) start_rec = Signal(str) collect_frame = Signal(object) collect_threshed = Signal(object) def __init__(self, parent=None): ''' sets up the whole main window ''' #standard init super(MainWindow, self).__init__(parent) #set the window title self.setWindowTitle('Open Ephys Control GUI') self.window_height = 700 self.window_width = 1100 self.screen2 = QDesktopWidget().screenGeometry(0) self.move( self.screen2.left() + (self.screen2.width() - self.window_width) / 2., self.screen2.top() + (self.screen2.height() - self.window_height) / 2.) self.get_info() self.noinfo = True while self.noinfo: loop = QEventLoop() QTimer.singleShot(500., loop.quit) loop.exec_() subprocess.Popen('start %s' % open_ephys_path, shell=True) self.collect_frame.connect(self.update_frame) self.collect_threshed.connect(self.update_threshed) self.acquiring = False self.recording = False self.video_height = self.window_height * .52 self.video_width = self.window_width * .48 self.resize(self.window_width, self.window_height) #create QTextEdit window 'terminal' for receiving stdout and stderr self.terminal = QTextEdit(self) #set the geometry self.terminal.setGeometry( QRect(self.window_width * .02, self.window_height * .15 + self.video_height, self.video_width * .96, 150)) #make widgets self.setup_video_frames() self.setup_thresh_buttons() self.overlay = True #create thread and worker for video processing self.videoThread = QThread(self) self.videoThread.start() self.videoproc_worker = VideoWorker(self) self.videoproc_worker.moveToThread(self.videoThread) self.vt_file = None """""" """""" """""" """""" """""" """""" """""" """ set up menus """ """""" """""" """""" """""" """""" """""" """""" #create a QMenuBar and set geometry self.menubar = QMenuBar(self) self.menubar.setGeometry( QRect(0, 0, self.window_width * .5, self.window_height * .03)) #set the QMenuBar as menu bar for main window self.setMenuBar(self.menubar) #create a QStatusBar statusbar = QStatusBar(self) #set it as status bar for main window self.setStatusBar(statusbar) #create icon toolbar with default image iconToolBar = self.addToolBar("iconBar.png") #create a QAction for the acquire button self.action_Acq = QAction(self) #make it checkable self.action_Acq.setCheckable(True) #grab an icon for the button acq_icon = self.style().standardIcon(QStyle.SP_MediaPlay) #set the icon for the action self.action_Acq.setIcon(acq_icon) #when the button is pressed, call the Acquire function self.action_Acq.triggered.connect(self.Acquire) #create a QAction for the record button self.action_Record = QAction(self) #make it checkable self.action_Record.setCheckable(True) #grab an icon for the button record_icon = self.style().standardIcon(QStyle.SP_DialogYesButton) #set the icon for the action self.action_Record.setIcon(record_icon) #when the button is pressed, call advanced_settings function self.action_Record.triggered.connect(self.Record) #create QAction for stop button action_Stop = QAction(self) #grab close icon stop_icon = self.style().standardIcon(QStyle.SP_MediaStop) #set icon for action action_Stop.setIcon(stop_icon) #when button pressed, close window action_Stop.triggered.connect(self.Stop) #show tips for each action in the status bar self.action_Acq.setStatusTip("Start acquiring") self.action_Record.setStatusTip("Start recording") action_Stop.setStatusTip("Stop acquiring/recording") #add actions to icon toolbar iconToolBar.addAction(self.action_Acq) iconToolBar.addAction(self.action_Record) iconToolBar.addAction(action_Stop) # self.sort_button = QPushButton('Sort Now',self) # self.sort_button.setGeometry(QRect(self.window_width*.85,0,self.window_width*.15,self.window_height*.05)) # self.sort_button.clicked.connect(self.sort_now) #show the window if minimized by windows self.showMinimized() self.showNormal() """""" """""" """""" """""" """""" """""" """""" """""" """""" """""" "" """""" """""" """""" """""" """""" """""" """""" """""" """""" """""" "" #this function acts as a slot to accept 'message' signal @Slot(str) def print_message(self, message): ''' print stdout and stderr to terminal window ''' #move terminal cursor to end self.terminal.moveCursor(QTextCursor.End) #write message to terminal self.terminal.insertPlainText(message) def setup_thresh_buttons(self): ''' set up buttons for overlay/clearing thresh view ''' self.button_frame = QFrame(self) self.button_frame.setGeometry( QRect(self.window_width * .52, self.window_height * .13 + self.video_height, self.video_width * .98, 50)) button_layout = QHBoxLayout() self.button_frame.setLayout(button_layout) self.clear_button = QPushButton('Clear') self.overlay_button = QPushButton('Overlay') button_layout.addWidget(self.clear_button) button_layout.addWidget(self.overlay_button) self.clear_button.setEnabled(False) self.clear_button.clicked.connect(self.clear_threshed) self.overlay_button.setEnabled(False) self.overlay_button.clicked.connect(self.overlay_threshed) def setup_video_frames(self): ''' set up spots for playing video frames ''' filler_frame = np.zeros((360, 540, 3)) filler_frame = qimage2ndarray.array2qimage(filler_frame) self.raw_frame = QFrame(self) self.raw_label = QLabel() self.raw_label.setText('raw') self.raw_frame.setGeometry( QRect(self.window_width * .01, self.window_height * .15, self.video_width, self.video_height)) self.raw_frame raw_layout = QVBoxLayout() self.raw_frame.setLayout(raw_layout) raw_layout.addWidget(self.raw_label) self.threshed_frame = QFrame(self) self.threshed_label = QLabel() self.threshed_label.setText('Threshed') self.threshed_frame.setGeometry( QRect(self.window_width * .51, self.window_height * .15, self.video_width, self.video_height)) threshed_layout = QVBoxLayout() self.threshed_frame.setLayout(threshed_layout) threshed_layout.addWidget(self.threshed_label) self.label_frame = QFrame(self) self.label_frame.setGeometry( QRect(self.window_width * .01, self.window_height * .11, self.video_width * 2, 50)) self.label_rawlabel = QLabel() self.label_rawlabel.setText('Raw Video') self.label_threshedlabel = QLabel() self.label_threshedlabel.setText('Threshold View') label_layout = QHBoxLayout() self.label_frame.setLayout(label_layout) label_layout.addWidget(self.label_rawlabel) label_layout.addWidget(self.label_threshedlabel) self.raw_label.setPixmap(QPixmap.fromImage(filler_frame)) self.threshed_label.setPixmap(QPixmap.fromImage(filler_frame)) def Acquire(self): if self.action_Acq.isChecked(): self.vidbuffer = [] if self.recording: while 1: try: self.sock.send('StopRecord') self.sock.recv() except: continue break self.recording = False else: #create and start a thread to transport a worker to later self.workerThread = QThread(self) self.workerThread.start() #create a worker object based on Worker class and move it to our #worker thread self.worker = Worker(self) self.worker.moveToThread(self.workerThread) try: self.start_acq.disconnect() except: pass while 1: try: self.sock.send('StartAcquisition') self.sock.recv() except: continue break self.acquiring = True self.start_acq.connect(self.worker.acquire) self.start_acq.emit('start!') self.action_Acq.setEnabled(False) self.action_Record.setChecked(False) self.action_Record.setEnabled(True) record_icon = self.style().standardIcon(QStyle.SP_DialogYesButton) #set the icon for the action self.action_Record.setIcon(record_icon) def Record(self): if self.action_Record.isChecked(): if not self.acquiring: self.workerThread = QThread(self) self.workerThread.start() self.worker = Worker(self) self.worker.moveToThread(self.workerThread) try: self.start_rec.disconnect() except: pass while 1: try: self.sock.send('StartAcquisition') self.sock.recv() except: continue break while 1: try: self.sock.send('StartRecord') self.sock.recv() except: continue break self.vidbuffer = [] self.start_rec.connect(self.worker.acquire) self.recording = True self.start_rec.emit('start!') else: while 1: try: self.sock.send('StartRecord') self.sock.recv() except: continue break self.vidbuffer = [] self.recording = True record_icon = self.style().standardIcon(QStyle.SP_DialogNoButton) #set the icon for the action self.action_Record.setIcon(record_icon) self.action_Record.setEnabled(False) self.action_Acq.setChecked(False) self.action_Acq.setEnabled(True) def Stop(self): self.acquiring = False self.recording = False while 1: try: self.sock.send('isRecording') rec = self.sock.recv() except: continue break if rec == '1': while 1: try: self.sock.send('StopRecord') self.sock.recv() except: continue break self.action_Record.setEnabled(True) self.action_Record.setChecked(False) while 1: try: self.sock.send('isAcquiring') acq = self.sock.recv_string() except: continue break if acq == '1': while 1: try: self.sock.send('StopAcquisition') self.sock.recv() except: continue break self.action_Acq.setEnabled(True) self.action_Acq.setChecked(False) try: #open a csv file for saving tracking data with open(self.vt_file, 'a') as csvfile: #create a writer vidwriter = csv.writer(csvfile, dialect='excel-tab') #check if it's an empty file for row in self.vidbuffer: vidwriter.writerow(row) except: pass record_icon = self.style().standardIcon(QStyle.SP_DialogYesButton) #set the icon for the action self.action_Record.setIcon(record_icon) def update_frame(self, image): self.raw_label.setPixmap(QPixmap.fromImage(image)) def update_threshed(self, threshed_image): self.threshed_label.setPixmap(QPixmap.fromImage(threshed_image)) def clear_threshed(self): self.green_frame = np.zeros_like(self.green_frame) self.red_frame = np.zeros_like(self.red_frame) def overlay_threshed(self): if self.overlay: self.overlay = False elif not self.overlay: self.overlay = True # def sort_now(self): # # if self.recdir is not None: # os.chdir('./kilosort_control') # #create and show the main window # self.sort_frame = kilosort_control.sort_gui.MainWindow() # self.sort_frame.show() # # #set up stream for stdout and stderr based on outputStream class # self.outputStream = kilosort_control.sort_gui.outputStream() # #when outputStream sends messages, connect to appropriate function for # #writing to terminal window # self.outputStream.message.connect(self.sort_frame.print_message) # # #connect stdout and stderr to outputStream # sys.stdout = self.outputStream # sys.stderr = self.outputStream # # self.sort_frame.run_now(self.recdir) # # self.close() def get_info(self): self.info_window = QWidget() self.info_window.resize(400, 350) #set title self.info_window.setWindowTitle('Session Info') #give layout info_layout = QVBoxLayout(self.info_window) with open('info_fields.pickle', 'rb') as f: default_fields = pickle.load(f) f.close() #set label for pic_resolution setting experimenter_label = QLabel('Experimenter:') #make a QLineEdit box for displaying/editing settings experimenter = QComboBox(self.info_window) experimenter.setEditable(True) experimenter.addItems(default_fields['experimenter']) #add label and box to current window info_layout.addWidget(experimenter_label) info_layout.addWidget(experimenter) #set label for pic_resolution setting whose_animal_label = QLabel('Whose animal?') #make a QLineEdit box for displaying/editing settings whose_animal = QComboBox(self.info_window) whose_animal.setEditable(True) whose_animal.addItems(default_fields['whose_animal']) #add label and box to current window info_layout.addWidget(whose_animal_label) info_layout.addWidget(whose_animal) animal_number_label = QLabel('Animal number:') animal_number = QComboBox(self.info_window) animal_number.setEditable(True) animal_number.addItems(default_fields['animal_number']) info_layout.addWidget(animal_number_label) info_layout.addWidget(animal_number) session_number_label = QLabel('Session number:') session_number = QTextEdit(self.info_window) session_number.setText('1') info_layout.addWidget(session_number_label) info_layout.addWidget(session_number) session_type_label = QLabel('Session type:') session_type = QComboBox(self.info_window) session_type.setEditable(True) session_type.addItems(default_fields['session_type']) info_layout.addWidget(session_type_label) info_layout.addWidget(session_type) def save_info(self): info_fields = {} info_fields['experimenter'] = [ experimenter.itemText(i) for i in range(experimenter.count()) ] info_fields['whose_animal'] = [ whose_animal.itemText(i) for i in range(whose_animal.count()) ] info_fields['animal_number'] = [ animal_number.itemText(i) for i in range(animal_number.count()) ] info_fields['session_type'] = [ session_type.itemText(i) for i in range(session_type.count()) ] with open('info_fields.pickle', 'wb') as f: pickle.dump(info_fields, f, protocol=2) f.close() current_experimenter = str(experimenter.currentText()) current_whose_animal = str(whose_animal.currentText()) current_animal_number = str(animal_number.currentText()) current_session_number = str(session_number.toPlainText()) current_session_type = str(session_type.currentText()) recdir = data_save_dir + current_whose_animal + '/' + current_animal_number if not os.path.exists(recdir): os.makedirs(recdir) self.experiment_info = '###### Experiment Info ######\r\n' self.experiment_info += 'Experimenter: %s\r\n' % current_experimenter self.experiment_info += 'Whose animal? %s\r\n' % current_whose_animal self.experiment_info += 'Animal number: %s\r\n' % current_animal_number self.experiment_info += 'Session number: %s\r\n' % current_session_number self.experiment_info += 'Session type: %s\r\n' % current_session_type self.experiment_info = self.experiment_info.encode() config_file = config_path + '/' + current_animal_number + '.xml' if not os.path.exists(config_file): shutil.copy(default_config, config_file) tree = et.parse(config_file) root = tree.getroot() for child in root: if child.tag == 'CONTROLPANEL': child.attrib['recordPath'] = recdir.replace('/', '\\') tree.write(config_file) tree.write(default_config) self.info_window.close() self.noinfo = False ready_button = QPushButton('Ready!') ready_button.clicked.connect(lambda: save_info(self)) info_layout.addWidget(ready_button) self.info_window.show()
def __init__(self): url = QLineEdit() quality = QLineEdit() urlLabel = QLabel('Url') qualityLabel = QLabel('Quality') messages = QTextEdit() messagesLabel = QLabel('Messages') links = QTableWidget(0, 2) linksLabel = QLabel('Links') clearMessages = QPushButton('Clear Messages') checkIfOnline = QPushButton('Check If Online') addSelectedLink = QPushButton('Add Link') removeSelectedLink = QPushButton('Remove Selected Link') messages.setReadOnly(True) links.setHorizontalHeaderLabels(['Url', 'Status']) links.horizontalHeader().setResizeMode(QHeaderView.Stretch) links.horizontalHeader().setResizeMode(1, QHeaderView.Fixed) # set the events url.returnPressed.connect(self.select_stream_from_entry) quality.returnPressed.connect(self.select_stream_from_entry) links.itemDoubleClicked.connect(self.select_stream_from_link) clearMessages.clicked.connect(self.clear_messages) checkIfOnline.clicked.connect(self.check_if_online) addSelectedLink.clicked.connect(self.add_selected_link) removeSelectedLink.clicked.connect(self.remove_selected_link) #set shortcut checkIfOnline.setShortcut(QKeySequence(Qt.Key_F5)) # set the layouts mainLayout = QGridLayout() # first row mainLayout.addWidget(urlLabel, 0, 0, 1, 1) # spans 1 column mainLayout.addWidget(qualityLabel, 0, 1, 1, 1) # spans 1 column mainLayout.addWidget(linksLabel, 0, 2, 1, 3) # spans 3 columns # second row (links widget occupies 2 rows and 2 columns) mainLayout.addWidget(url, 1, 0, 1, 1) # spans 1 column mainLayout.addWidget(quality, 1, 1, 1, 1) # spans 1 column mainLayout.addWidget(links, 1, 2, 2, 3) # spans 3 columns # third row (messages widget occupies 2 columns) mainLayout.addWidget(messages, 2, 0, 1, 2) # fourth row mainLayout.addWidget(messagesLabel, 3, 0) mainLayout.addWidget(clearMessages, 3, 1) mainLayout.addWidget(checkIfOnline, 3, 2) mainLayout.addWidget(addSelectedLink, 3, 3) mainLayout.addWidget(removeSelectedLink, 3, 4) window = QWidget() window.setLayout(mainLayout) window.setWindowTitle('Live Streamer') window.resize(700, 350) window.show() self.url_ui = url self.quality_ui = quality self.messages_ui = messages self.links_ui = links self.window_ui = window self.links = set() self.data_file = os.path.join(os.path.expanduser("~"), ".config", "livestreamer-ui", "data.txt") folder = os.path.dirname(self.data_file) if not os.path.exists(folder): os.makedirs(folder)
import shutil import sys import arrow from PySide.QtCore import QTimer from PySide.QtGui import QApplication, QWidget, QHBoxLayout, QFileDialog, QListWidgetItem, QPushButton, QListWidget, \ QInputDialog FILENAME_FORMAT = 'YYYY-MM-DD HH-mm-ss' AUTOSAVE_TIMEOUT = 5*60*1000 app = QApplication(sys.argv) main_window = QWidget() main_window.resize(640, 480) main_window.setWindowTitle('Save manager') box = QHBoxLayout() main_window.setLayout(box) def load_config(): _config = {} if os.path.exists("config.json"): with open("config.json") as f: _config = json.loads(f.read()) return _config