def transition_to_main_window(project): logging.info("Transitioning to main window.") global main_window driver = Driver(project) settings_service.save_settings() main_window = MainWindow(transition_back_to_create_project, driver) main_window.show()
def main(): app = QgsApplication([], True) app.setPrefixPath("C:/OSGeo4W64/apps/qgis", True) app.initQgis() window = MainWindow() window.show() window.raise_() bb = (635432, 5616219, 635939, 5616575) # WestSouthEastNorth # bb = (633612, 5619141, 634424, 5619713) # highway # # streets streetsPath = ("files/cir/streets.shp") osmStreets = OsmStreets(extent=bb, extentEPSG=25832) osmStreets.getBufferedStreets(savePath=streetsPath) loadVectorLayer(streetsPath, "streets") streetMaskPath = ("files/cir/streets_mask.tiff") vector2raster(bb, streetsPath, streetMaskPath) loadRasterLayer(streetMaskPath, "streetsMask") # clipping dop with streetMask dop = ("files/colour/streets_dop.tif") clippedPathTemp = ("files/colour/streets_clipped_temp.tiff") clipping(streetMaskPath, dop, clippedPathTemp) # copy extent and EPSG from streetMaskPath clippedPath = ("files/colour/streets_clipped.tiff") CopyExtentandEPSG(streetMaskPath, clippedPathTemp, clippedPath) loadRasterLayer(clippedPath, "clippedSteets") # # # buildings # buildingsPath = ("files/buildings.shp") # osmBuildings = OsmBuildings(extent=bb, extentEPSG=25832) # osmBuildings.getBuildingPolygons(savePath=buildingsPath, onlyWithHeight=False) # loadVectorLayer(buildingsPath, "buildings") # buildingMaskPath = ("files/buildings.tiff") # vector2raster(bb, buildingsPath, buildingMaskPath) # loadRasterLayer(buildingMaskPath, "buildingsMask") # water # waterPath = "files/water.shp" # osmWater = OsmWater(extent=bb, extentEPSG=25832) # osmWater.getWaterPolygons(savePath=waterPath) # loadVectorLayer(waterPath, "water") # waterMaskPath = "files/water.tiff" # vector2raster(bb, waterPath, waterMaskPath) # loadRasterLayer(waterMaskPath, "waterMask") # set CRS to the one of image and zoom to extent crs = QgsCoordinateReferenceSystem() crs.createFromId(25832) window.canvas.setDestinationCrs(crs) exitcode = app.exec_() QgsApplication.exitQgis() sys.exit(exitcode)
class MainState(State): def __init__(self): super().__init__("Main") self.window = None def act(self): logging.info("Entered Main state.") self.window = MainWindow() self.window.show()
def run(): import argparse parser = argparse.ArgumentParser() parser.add_argument( '-m', dest='module', default='pynodegl_utils.examples', help='set the module name containing the scene functions') parser.add_argument( '-a', dest='assets_dir', help='set the assets directory to be used by the scene functions') parser.add_argument('--hooks-dir', dest='hooksdir', help='set the directory path containing event hooks') pargs = parser.parse_args(sys.argv[1:]) app = QtWidgets.QApplication(sys.argv) window = MainWindow(pargs.module, pargs.assets_dir, pargs.hooksdir) window.show() app.exec_()
def run(): import argparse parser = argparse.ArgumentParser() parser.add_argument( '-m', dest='module', default='pynodegl_utils.examples', help='set the module name containing the scene functions') parser.add_argument( '-a', dest='assets_dir', help='set the assets directory to be used by the scene functions') parser.add_argument('--hooks-dir', dest='hooksdir', help='set the directory path containing event hooks') pargs = parser.parse_args(sys.argv[1:]) app = QtWidgets.QApplication(sys.argv) # Fixes ui freezes with the native gl view on macos 10.14 (mojave) app.setAttribute(QtCore.Qt.AA_DontCreateNativeWidgetSiblings) window = MainWindow(pargs.module, pargs.assets_dir, pargs.hooksdir) window.show() app.exec_()
class GUIApplication: host = HostValidator() port = PortValidator() def __init__(self): self.config_window = None self.stat_window = None self.main_window = None self.config = get_config_from_yaml() dictConfig(LOGGING) self.logger = getLogger('server') def __enter__(self): self.logger.info('Server GUI was rendered.') return self def __exit__(self, exc_type, exc_val, exc_tb): if exc_type: self.logger.critical( f'GUI closed with error: {exc_type}: {exc_val}') else: self.logger.info('GUI closed.') return True def render(self): app = QApplication(sys.argv) self.config_window = ConfigWindow() self.stat_window = ClientStatsWindow() self.main_window = MainWindow() self.show_main_window() self.make_signals_connection() app.exec_() def show_main_window(self): self.main_window.statusBar().showMessage('Server running') self.connect_main_window_buttons() self.render_connections_table() self.main_window.show() def connect_main_window_buttons(self): self.main_window.show_history_button.triggered.connect( self.show_client_stats_window) self.main_window.config_btn.triggered.connect(self.show_config_window) def render_connections_table(self): self.main_window.connections_table.setModel(get_connections_table()) self.main_window.connections_table.resizeColumnsToContents() self.main_window.connections_table.resizeRowsToContents() def show_client_stats_window(self): self.stat_window.history_table.setModel(get_client_stats_table()) self.stat_window.history_table.resizeColumnsToContents() self.stat_window.history_table.resizeRowsToContents() self.stat_window.show() def show_config_window(self): if self.config: self.config_window.db_path.insert(self.config.get('db_path')) self.config_window.db_file.insert(self.config.get('db_file')) self.config_window.port.insert(self.config.get('db_port')) self.config_window.host.insert(self.config.get('db_host')) self.config_window.show() self.config_window.save_btn.clicked.connect(self.save_config_to_file) def save_config_to_file(self): message = QMessageBox() errors = self.get_validation_errors() if errors: err = ''.join([f'{error}\n'.capitalize() for error in errors]) message.warning(self.config_window, 'Error', err) else: self.config['db_path'] = self.config_window.db_path.text() self.config['db_file'] = self.config_window.db_file.text() self.config['port'] = self.port self.config['host'] = self.host write_config_to_yaml(self.config) message.information(self.config_window, 'OK', 'Config is set up!') def get_validation_errors(self): errors = list() try: self.host = self.config_window.host.text() except ValueError as error: errors.append(error) try: self.port = int(self.config_window.port.text()) except ValueError as error: errors.append(error) return errors def make_signals_connection(self): SIGNAL.active_client_signal.connect(self.render_connections_table)
from ui.main_window import MainWindow if __name__ == '__main__': app = QApplication([]) app.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5()) if os.path.isfile('config.json'): with open('config.json') as f: config = json.load(f) application = MainWindow(app, config) # Disable window resize and the maximize button application.setWindowFlags(Qt.WindowCloseButtonHint | Qt.WindowMinimizeButtonHint) application.show() application.setFixedSize(application.size()) sys.exit(app.exec_()) else: msg = QMessageBox() msg.setWindowTitle('Config missing') msg.setText( """<p style='text-align: center;'><img src='ui/assets/warning-icon.png' alt='' width='42' height='42'/></p> <p style='align: center;'><strong>config.json file is missing, cannot continue !</strong></p>""" ) msg.exec_()
def main(): app = gui.QApplication(sys.argv) mw = MainWindow() mw.show() sys.exit(app.exec_())
#!/usr/bin/env python # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui from ui.main_window import MainWindow if __name__ == '__main__': import sys app = QtGui.QApplication(sys.argv) w = MainWindow() w.show() sys.exit(app.exec_())
import sys from ui.main_window import MainWindow from PyQt5 import QtWidgets if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) main = MainWindow() main.show() sys.exit(app.exec_())
from PyQt5.Qt import QApplication from PyQt5.QtWidgets import QMessageBox from ui.main_window import MainWindow from core.session import Session from core.util import Utility import sys import logging CONFIG_FILE_PATH = "config/config.conf" if __name__ == '__main__': app = QApplication(sys.argv) logging.basicConfig(level=logging.INFO) try: session = Session(CONFIG_FILE_PATH) except ValueError as e: QMessageBox.warning(None, "Error", "Error parsing config file...") sys.exit(1) except (OSError, IOError) as e: QMessageBox.warning(None, "Error", "Couldn't open config file") sys.exit(1) main_window = MainWindow(app.desktop(), session) main_window.show() sys.exit(app.exec_())
def main(): app = QApplication(sys.argv) window = MainWindow() window.show() sys.exit(app.exec_())
def setup_hook(): _excepthook = sys.excepthook def hook(exctype, value, traceback): print(exctype, value, traceback) _excepthook(exctype, value, traceback) sys.exit(1) sys.excepthook = hook if __name__ == '__main__': setup_hook() QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) app = QApplication(sys.argv) app.setWindowIcon(QIcon(':/icon/img/logo.png')) w = MainWindow() cp = QDesktopWidget().availableGeometry().center() qr = w.frameGeometry() qr.moveCenter(cp) w.move(qr.topLeft()) w.show() w.tabs_container.setCurrentIndex(0) try: sys.exit(app.exec_()) except: pass
# Joao Victor Fagundes # Salomao Rodrigues Jacinto # INE5421 - Trablho Prático II Junho 2018 import sys from ui.main_window import MainWindow from PyQt5.QtWidgets import QApplication if __name__ == "__main__": app = QApplication(sys.argv) window = MainWindow() window.show() sys.exit(app.exec_())
import resource import sys from PyQt5.QtWidgets import QApplication from ui.main_window import MainWindow if __name__ == "__main__": # Increasing size of stack to be able to pickle print(resource.getrlimit(resource.RLIMIT_STACK)) print(sys.getrecursionlimit()) max_rec = 0x100000 # May segfault without this line. 0x100 is a guess at the size of each stack frame. resource.setrlimit(resource.RLIMIT_STACK, [0x100 * max_rec, resource.RLIM_INFINITY]) sys.setrecursionlimit(max_rec) app = QApplication(sys.argv) mySW = MainWindow() mySW.show() sys.exit(app.exec_())
def main(): app = QApplication(sys.argv) print('start main window...') w = MainWindow() w.show() sys.exit(app.exec_())
class Peer: def __init__(self,ip='',port=9011,peer_id=-1,build_ui = True, log = None): # Node state if ip == '': self.ip = self._getIP() else: self.ip = ip if not log: log = Log('livesession') self.id = peer_id self.port = port self.log = log self.name = '{0}:{1}'.format(self.ip,port) self.state = PeerState(peer_id, self.log) self.state.ip = self.ip self.state.port = self.port self.state.ips.append(self.state.ip) self.state.ports.append(self.state.port) # Print start log.blue('\n\nINIT', self.id) log.blue('-'*(len(self.ip.__str__())+len(self.port.__str__())+3)) self.log.blue(self.ip, ":", self.port) log.blue('-'*(len(self.ip.__str__())+len(self.port.__str__())+3)) # Init main UI if build_ui: self.window = MainWindow(self.state) self.window.show() self.window.raise_() self.state.window = self.window self.state.newStrokesSignal.connect(self.window.scribbleArea.strokesSignalHandler) # Handler for the RPC requests self.RPCresponder = RPCresponder(self.state) # Accept incoming connections in a background thread self.server = SimpleXMLRPCServer((ip,port),logRequests=False,bind_and_activate=False) self.server.server_bind() self.server.server_activate() self.server.register_introspection_functions() self.server.register_instance(self.RPCresponder) t = Thread(target = self._run,name='{0}:{1}'.format(ip,port)) t.daemon = True t.start() def __str__(self): return 'peer {0} - {1}'.format(self.id,self.name) def _run(self): """ Accept incoming connection till exit """ self.server.serve_forever() def _getIP(self): s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) s.connect(('google.com',80)) ip = s.getsockname()[0] s.close() return ip def kill(self): self.log.red( self,'=> killed') self.RPCresponder.kill() def revive(self): self.log.green( self,'=> revived') self.RPCresponder.revive() def setUnreliable(self): self.log.red( self,'=> unreliable') self.RPCresponder.setUnreliable() def setReliable(self): self.log.green( self,'=> reliable') self.RPCresponder.setReliable() def addPeer(self,ip,port): """ Add a new peer """ self.state.addPeer(ip,port) def getStrokes(self): return self.state.getStrokes() def thaw(self, sid): self.state.thaw(sid) def freeze(self, sid): self.state.freeze(sid)
import sys from PySide.QtGui import QApplication from ui.main_window import MainWindow APP_NAME = 'Dreamer' class DreamerApp(QApplication): def __init__(self, *args, **kwargs): QApplication.__init__(self, *args, **kwargs) self.setApplicationName(APP_NAME) app = DreamerApp(sys.argv) if __name__ == "__main__": window = MainWindow() window.setWindowTitle(APP_NAME) window.show() return_code = app.exec_() sys.exit(return_code)
class GUIApplication: def __init__(self, client): self.client = client self.login_window = None self.signup_window = None self.main_window = None self.add_contact_window = None self.del_contact_window = None self.client_name = None self.current_friend = None dictConfig(LOGGING) self.logger = getLogger('client') def __enter__(self): self.make_signals_connection() self.logger.info('Client GUI was rendered.') return self def __exit__(self, exc_type, exc_val, exc_tb): if self.client.client_name: set_client_last_visit_date(self.client.client_name) if exc_type and not exc_type == SystemExit and exc_val: self.logger.critical( f'Client GUI closed with error: {exc_type}: {exc_val}.' ) else: self.logger.info('Client GUI closed.') return True def render(self): app = QApplication(sys.argv) self.set_up_login_window() self.set_up_signup_window() self.set_up_add_contact_window() self.set_up_del_contact_window() if self.client.client_name: max_waiting_time = 0 while True: # TODO: переделать этот костыль if self.client.token: last_visit_date = get_client_last_visit_date(self.client.client_name) set_client_to_active(self.client.client_name) self.get_new_messages_from_server(last_visit_date) break sleep(0.5) max_waiting_time += 0.5 if max_waiting_time == 10: QMessageBox.critical( self.main_window, 'Error', 'Server timed out.' ) # TODO: не доходит до exit, виснет на сообщении qApp.exit() self.show_main_window() else: self.show_login_window() sys.exit(app.exec_()) def set_up_login_window(self): self.login_window = LoginWindow() self.login_window.login_signal.connect(self.login) self.login_window.switch_to_signup.connect(self.show_signup_window) def set_up_signup_window(self): self.signup_window = SignupWindow() self.signup_window.signup_signal.connect(self.signup) self.signup_window.back_to_login_signal.connect(self.show_login_window) def set_up_add_contact_window(self): self.add_contact_window = AddContactWindow() self.add_contact_window.add_contact_signal.connect(self.add_contact) def set_up_del_contact_window(self): self.del_contact_window = DelContactWindow() self.del_contact_window.del_contact_signal.connect(self.del_contact) def show_login_window(self): self.login_window.login.clear() self.login_window.password.clear() if self.signup_window: self.signup_window.close() if self.main_window: self.main_window.close() self.login_window.show() def show_signup_window(self): self.signup_window.login.clear() self.signup_window.password_1.clear() self.signup_window.password_2.clear() if self.login_window: self.login_window.close() self.signup_window.show() def show_main_window(self): self.main_window = MainWindow(self.client.client_name) self.main_window.logout_signal.connect(self.logout) self.main_window.start_chatting_signal.connect(self.start_chatting) self.main_window.send_message_signal.connect(self.send_message) self.main_window.switch_to_add_contact.connect(self.show_add_contact_window) self.main_window.switch_to_del_contact.connect(self.show_del_contact_window) self.make_main_window_signals_connection() self.main_window.set_elements_disable_status(True) self.main_window.render_welcome_message() contacts = self.get_contacts() self.main_window.render_contacts(contacts) if self.login_window: self.login_window.close() if self.signup_window: self.signup_window.close() self.main_window.show() def show_add_contact_window(self): self.add_contact_window.contact_name.clear() self.add_contact_window.show() def show_del_contact_window(self): self.del_contact_window.selector.clear() self.del_contact_window.render_del_contacts_list(self.get_contacts()) self.del_contact_window.show() def login(self, login, password): self.client_name = login action = 'login' data = {'login': login, 'password': password} self.write(action, data) def signup(self, login, password, photo): self.client_name = login action = 'register' data = {'login': login, 'password': password, 'photo': photo} self.write(action, data) def logout(self): action = 'logout' self.write(action) self.main_window.close() self.client.client_name = None set_client_to_inactive() qApp.exit() # TODO: Вместо qApp.exit() показать окно логина, удалить connect к текущей db def create_account(self, code, data): if code == 200: add_client_to_clients_db(self.client_name) self.set_client_name_and_connect_to_db() last_visit_date = get_client_last_visit_date(self.client_name) set_client_to_active(self.client_name) self.get_new_messages_from_server(last_visit_date) self.show_main_window() else: if isinstance(data.get('errors'), dict): errors = ', '.join([ f'{key}: {val}' for key, val in data.get('errors').items() ]) else: errors = data.get('errors') self.login_window.message.critical(self.login_window, 'Error', errors) def set_client_name_and_connect_to_db(self): if self.client_name: self.client.client_name = self.client_name self.client.database = LocalStorage(self.client_name) self.client.database.connect() def start_chatting(self, friend): self.current_friend = friend messages = self.get_messages(self.current_friend) self.main_window.render_messages( self.current_friend, self.client.client_name, messages ) def get_messages(self, friend): action = 'get_local_messages' data = { 'from_client': self.client.client_name, 'to_client': friend, 'get_last': 20, } return self.write(action, data) def send_message(self, to_client_name, message): action = 'message' data = {'text': message, 'to_client': to_client_name} self.write(action, data) local_action = 'local_message' local_data = { 'text': message, 'to_client': to_client_name, 'from_client': self.client.client_name } message = self.write(local_action, local_data) self.main_window.render_message( to_client_name, self.client.client_name, message ) def add_contact(self, contact): action = 'add_contact' data = {'friend_name': contact} self.write(action, data) def del_contact(self, contact): self.main_window.messages_model.clear() action = 'del_contact' data = {'friend': contact} self.write(action, data) def get_contacts(self): action = 'get_contacts' return self.write(action) def get_new_messages_from_server(self, from_date): time = from_date.timestamp() action = 'get_messages' data = {'from_date': time} self.write(action, data) def write(self, action, data=None): try: result = self.client.write(action, data) except: self.main_window.message.critical( self.main_window, 'Error', 'Can\'t send data to server.' ) else: return result def validate_render_message(self, friend, client_name, messages): if friend == self.current_friend: self.main_window.render_message(friend, client_name, messages) def make_signals_connection(self): SIGNAL.auth_signal.connect(self.create_account) SIGNAL.new_message.connect(self.validate_render_message) def make_main_window_signals_connection(self): SIGNAL.contact_signal.connect( lambda: self.main_window.render_contacts(self.get_contacts()) )
from PyQt5.QtWidgets import QApplication from application_service.get_map_uc import GetMapUseCase from serveces.YandexMapAdapter import YandexMapAdapter from ui.main_window import MainWindow adapter = YandexMapAdapter() use_case = GetMapUseCase(adapter) app = QApplication([]) win = MainWindow(use_case) win.show() app.exec()
import resource import sys from PyQt5.QtWidgets import QApplication from engine.world import World from engine.world_constants import WorldConstants from ui.main_window import MainWindow if __name__ == "__main__": # Increasing size of stack to be able to pickle print(resource.getrlimit(resource.RLIMIT_STACK)) print(sys.getrecursionlimit()) max_rec = 0x100000 # May segfault without this line. 0x100 is a guess at the size of each stack frame. # resource.setrlimit(resource.RLIMIT_STACK, [0x100 * max_rec, resource.RLIM_INFINITY]) sys.setrecursionlimit(max_rec) world_constants = WorldConstants() save_genealogy = False world = World(constants=world_constants, save_genealogy=save_genealogy) app = QApplication(sys.argv) mySW = MainWindow(world) mySW.show() sys.exit(app.exec_())