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 createView(self): """Creates the module-specific view for the FilterBox module.""" view = QWidget() layout = QGridLayout() self.filter_label = QLabel("") layout.addWidget(self.filter_label, 0, 0, 1, 1) view.setLayout(layout) view.resize(20, 20) return view
def createView(self): """Creates the module-specific view for the FilterBox module.""" view = QWidget() layout = QHBoxLayout() self.filter_label = QLabel("") layout.addWidget(self.filter_label) layout.addItem(QSpacerItem(3, 3)) self.spinner = FilterSpinBox(self, list()) self.spinner.valueChanged.connect(self.spinnerValueChanged) layout.addWidget(self.spinner) view.setLayout(layout) view.resize(200, 20) return view
def createView(self): """Creates the module-specific view for the FilterSpin module.""" view = QWidget() layout = QHBoxLayout() self.filter_label = QLabel("") layout.addWidget(self.filter_label) layout.addItem(QSpacerItem(3,3)) self.spinner = FilterSpinBox(self, list()) self.spinner.valueChanged.connect(self.spinnerValueChanged) layout.addWidget(self.spinner) view.setLayout(layout) view.resize(200, 20) return view
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 BrowserApp(object): def __init__(self): self.app = QApplication(sys.argv) self.window = QWidget() self.window.resize(1280, 1024) self.main_layout = QHBoxLayout() self.window.setLayout(self.main_layout) self.window.show() self.left_pane = self.create_browser_pane('Left') self.main_layout.addWidget(self.left_pane['main']) self.right_pane = self.create_browser_pane('Right') self.main_layout.addWidget(self.right_pane['main']) self.panes = [self.left_pane, self.right_pane] def run(self): self.window.show() self.app.exec_() def create_browser_pane(self, title): # Create the pane widget pane = QWidget() layout = QVBoxLayout() pane.setLayout(layout) # Create a label for the title title_bar = QLabel("") # title_bar.setFixedHeight(32) title_bar.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Minimum) title_bar.show() layout.addWidget(title_bar) # Create the "address" box address_bar = QLineEdit() layout.addWidget(address_bar) # todo: we could add some tool buttons here.. toolbar_layout = QHBoxLayout() toolbar = QWidget() toolbar.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Minimum) toolbar.setLayout(toolbar_layout) tool_stop = QPushButton() tool_stop.setText('Stop') toolbar_layout.addWidget(tool_stop) tool_back = QPushButton() tool_back.setText('Back') toolbar_layout.addWidget(tool_back) tool_forward = QPushButton() tool_forward.setText('Forward') toolbar_layout.addWidget(tool_forward) tool_reload = QPushButton() tool_reload.setText('Reload') toolbar_layout.addWidget(tool_reload) layout.addWidget(toolbar) # Create the web view web_view = QWebView() web_view.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding) layout.addWidget(web_view) # Create a status bar status_bar = QLabel("") status_bar.setFixedHeight(32) status_bar.show() status_bar.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Minimum) layout.addWidget(status_bar) # Attach signal handlers address_bar.editingFinished.connect(functools.partial( self._addrbar_changed, address_bar, web_view)) web_view.loadStarted.connect( lambda: status_bar.setText('Loading...')) web_view.loadProgress.connect( lambda p: status_bar.setText('Loading ({0}%)...'.format(p))) web_view.loadFinished.connect( lambda p: status_bar.setText('Ready.'.format(p))) web_view.statusBarMessage.connect(status_bar.setText) web_view.titleChanged.connect(title_bar.setText) web_view.urlChanged.connect(functools.partial( self._url_changed, web_view)) web_view.urlChanged.connect( lambda url: address_bar.setText(url.toString())) # Connect tool buttons tool_stop.clicked.connect(web_view.stop) tool_back.clicked.connect(web_view.back) tool_forward.clicked.connect(web_view.forward) tool_reload.clicked.connect(web_view.reload) return { 'main': pane, 'layout': layout, 'title': title_bar, 'address': address_bar, 'web_view': web_view, 'status': status_bar, } def _addrbar_changed(self, addrbar, webview): webview.load(addrbar.text()) def _url_changed(self, webview, qurl): """ The url in a webview just changed: update URLs in other panes as well! """ print("URL Changed -- updating other panes") url = urlparse.urlparse(qurl.toString()) for pane in self.panes: if pane['web_view'] is webview: continue # Update the pane url with path/query/fragment try: this_pane_url = urlparse.urlparse( pane['web_view'].url().toString()) except: pass # todo: mark error else: u = this_pane_url._replace( path=url.path, query=url.query, fragment=url.fragment) new_url = urlparse.urlunparse(u) # Check here is to prevent bouncing! if pane['web_view'].url().toString() != new_url: pane['web_view'].load(new_url)
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)
if __name__ == '__main__': app = 0 if QApplication.instance(): app = QApplication.instance() else: app = QApplication(sys.argv) l1 = QTreeWidgetItem(["ALFA", "100"]) l2 = QTreeWidgetItem(["GRUMA", "200"]) for i in range(3): l1_child = QTreeWidgetItem([None, str(i * 10), "Child C" + str(i)]) l1.addChild(l1_child) for j in range(2): l2_child = QTreeWidgetItem([None, str(j * 20), "Child CC" + str(j)]) l2.addChild(l2_child) w = QWidget() w.resize(510, 210) tw = QTreeWidget(w) tw.resize(500, 200) tw.setColumnCount(3) tw.setHeaderLabels(["Asset", "Gross Amount", "Payment Date"]) tw.addTopLevelItem(l1) tw.addTopLevelItem(l2) w.show() sys.exit(app.exec_())
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_())
print 'import os' 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()
def showTooltip(self, tooltip, align, main_window): logging.warning("The floating widget of type %s with reference widget of type %s, could not be deployed", type(tooltip.widget()).__name__, type(tooltip.hoveredWidget()).__name__) widget = QWidget() widget.resize(0, 0) # De esta forma el widget nunca va a contener al mouse return widget
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 os 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