def main(): # create the Application app = QtWidgets.QApplication(sys.argv) # create the event loop event_loop = QEventLoop(app) asyncio.set_event_loop(event_loop) # Create the Gui main_window = MainWindow() # plugins to include different websites (and listeners?) plugin_manager = PluginManager() plugin_manager.register_main_window(main_window) # User Settings settings_manager = SettingsManager() settings_manager.register_main_window(main_window) settings_manager.register_plugin_manager(plugin_manager) main_window.show() try: event_loop.run_forever() except KeyboardInterrupt: pass app.deleteLater() plugin_manager.terminate_plugins() event_loop.close() sys.exit()
def main(): app = QtGui.QApplication(sys.argv) app_window = MainWindow(display_width,display_height) app_window.show() app.exec_()
def main(): """ Main function for the program """ parser = argparse.ArgumentParser( description="Loop a video between 2 points in time based on rules in " "a text file." ) parser.add_argument('timestamp_filename', metavar='F', nargs='?', help='the location of the timestamp file') parser.add_argument('--video_filename', metavar='V', help='the location of the video file') args = parser.parse_args() app = QApplication(sys.argv) with open("gui/application.qss", "r") as theme_file: app.setStyleSheet(theme_file.read()) main_window = MainWindow() if args.timestamp_filename: timestamp_filename = os.path.abspath(args.timestamp_filename) main_window.set_timestamp_filename(timestamp_filename) if args.video_filename: video_filename = os.path.abspath(args.video_filename) main_window.set_video_filename(video_filename) sys.exit(app.exec_())
def main(): with concurrent.futures.ThreadPoolExecutor(max_workers=1) as threadworker: # this threadpool is used to fetch weather data # it's used so that the tkinter's mainloop does not get blocked by a http request # it's being passed to the app so that a method inside it can use it app = MainWindow(threadworker) app.mainloop()
def main(argv): check_pyopenssl_version() options = None app = QApplication(sys.argv) ui = MainWindow(options) ui.setWindowTitle('MitmUI v0.1') ui.show() sys.exit(app.exec_())
def main(): app = QApplication(sys.argv) args = app.arguments() args = map(str, args) if platform.system() == 'Windows' and 'python' in args[0]: args = args[1:] config = parse_args(args[1:]) if config['verbose'] > 0: logging.basicConfig(level=logging.DEBUG) win = MainWindow(config) win.setFixedSize(600, 400) win.setWindowTitle('BrytonOffline') win.setWindowIcon(QIcon(resource_path('img/bryton_logo.jpg'))) win.show() return app.exec_()
def __init__(self, queue): MainWindow.__init__(self, None) self.workQueue = queue # set up address events self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.enableAddrButtons, self.addrList) self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.disableAddrButtons, self.addrList) # set up timer to check connection # and update balance self.timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.update, self.timer) self.timer.Start(0)
def main(): """ Start the program """ # Initialize the backend hardware = Hardware("config/hardware.json") # Initialize the GUI app = QtGui.QApplication(sys.argv) window = MainWindow(hardware) # Start window.show() sys.exit(app.exec_())
def loop(HOST, PORT, CERT): server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server.connect((HOST, PORT)) buffer = [] disconnected = False # The following code explains how to use the GUI. w = MainWindow() # update() returns false when the user quits or presses escape. while w.update(): if disconnected: continue try: rready, wready, xready = select.select([server], [server], [server]) # ready to receive if server in rready: data = server.recv(1024) if not data: server.close() w.writeln("<server disconnected>") disconnected = True continue # print message w.writeln(data.rstrip()) # ready to send if server in wready: if len(buffer) > 0: server.sendall(buffer.pop()) # error if server in xready: server.close() sys.exit(1) # if the user entered a line getline() returns a string. line = w.getline() if line: buffer.append(line) w.writeln("> " + line) # close server on SIGINT except (KeyboardInterrupt, SystemExit): print "\nDisconnecting..." server.close() print "Cheers!" sys.exit(0)
def main(path=None, page=None): """Run the normal interface.""" app = QtGui.QApplication(sys.argv) if path is not None: config.settings.Main.Package = path window = MainWindow() if page is not None: window.set_page(page) center_window(window) window.show() warn.set_warnings_qt() exit_code = app.exec_() prepare_quit(window) return exit_code
def main(mcast_addr, sensor_pos, sensor_range, sensor_val, grid_size, ping_period): """ mcast_addr: udp multicast (ip, port) tuple. sensor_pos: (x,y) sensor position tuple. sensor_range: range of the sensor ping (radius). sensor_val: sensor value. grid_size: length of the of the grid (which is always square). ping_period: time in seconds between multicast pings. """ # -- make the gui -- window = MainWindow() # -- make the node -- node = Node(mcast_addr, sensor_pos,sensor_range, sensor_val, window) start_time = time.time() # -- This is the event loop. -- while window.update(): node.updateSelect() # Auto ping if (time.time() - start_time) > ping_period: node.sendPing() start_time = time.time() # Check for new messages for c in node.readable: # Receive message from server and write to the window data = c.recvfrom(1024) parseData(data, node) # Check if something was entered in the GUI, parse the input and execute the corresponding command line = window.getline() if line: parseInput(line, node) # # Prevent busy looping time.sleep(0.1)
def main(mcast_addr, sensor_pos, sensor_range, sensor_val, grid_size, ping_period): """ mcast_addr: udp multicast (ip, port) tuple. sensor_pos: (x,y) sensor position tuple. sensor_range: range of the sensor ping (radius). sensor_val: sensor value. grid_size: length of the of the grid (which is always square). ping_period: time in seconds between multicast pings. """ node = nodeContainer() # -- make sockets node.init(mcast_addr) # -- set node values node.position = sensor_pos node.range = sensor_range node.value = sensor_val node.pingTime = ping_period # -- create gui window = MainWindow() node.setWindow(window) # -- Command/message parser parser = msgParser(node) # -- Both peer and Mcast connections conns = node.getConnections() # -- This is the event loop while window.update(): inputReady, outputReady, errorReady = \ select.select(conns, [], [], 0.025) # Is it ping time already node.autoPing() # Network message for s in inputReady: parser.parseSensorMessage(s) # Gui message line = window.getline() if line: parser.parseLine(line);
def main(): win = MainWindow() win.setup() win.set_size_request(600,500) win.show_all() gtk.gdk.threads_init() gtk.main()
def main(): # create the GUI app = QtWidgets.QApplication(sys.argv) # create the event loop event_loop = QEventLoop(app) asyncio.set_event_loop(event_loop) main_window = MainWindow() # need chat_slot to be able to add to add the chat signal chat_slot = main_window.central_widget.message_area.chat_slot settings = get_settings_helper() # this methods also handles passing in values to websites plugin_manager = instantiate_plugin_manager(settings) main_window.set_settings(settings) chat_list = plugin_manager.get_instances() # connect the sockets signals to the GUI for chat in chat_list: chat.chat_signal.connect(chat_slot) chat.connected_signal.connect(main_window.status_bar.set_widget_status) listener_interface = pluginmanager.PluginInterface() listener_interface.collect_plugins(plugins) listener_list = listener_interface.get_instances() # flake8: noqa # main_window.central_widget.message_area.listeners = listener_list main_window.show() try: event_loop.run_forever() except KeyboardInterrupt: pass for chat in chat_list: if chat.process: chat.process.terminate() event_loop.close() sys.exit()
def main(): # create the Application app = QtWidgets.QApplication(sys.argv) # create the event loop event_loop = QEventLoop(app) asyncio.set_event_loop(event_loop) # Create the Gui main_window = MainWindow() # plugins to include different websites (and listeners?) plugin_manager = PluginManager() plugin_manager.register_main_window(main_window) # User Settings settings_manager = SettingsManager() settings_manager.register_main_window(main_window) settings_manager.register_plugin_manager(plugin_manager) # listeners handeled separatly for now listener_interface = pluginmanager.PluginInterface() listener_interface.collect_plugins(plugins) listener_list = listener_interface.get_instances() # flake8: noqa # main_window.central_widget.message_area.listeners = listener_list main_window.show() try: event_loop.run_forever() except KeyboardInterrupt: pass app.deleteLater() plugin_manager.terminate_plugins() event_loop.close() sys.exit()
def main(mcast_addr, sensor_pos, sensor_range, sensor_val, grid_size, ping_period): """ mcast_addr: udp multicast (ip, port) tuple. sensor_pos: (x,y) sensor position tuple. sensor_range: range of the sensor ping (radius). sensor_val: sensor value. grid_size: length of the of the grid (which is always square). ping_period: time in seconds between multicast pings. """ # -- Create the multicast listener socket. -- mcast = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP) # Sets the socket address as reusable so you can run multiple instances # of the program on the same machine at the same time. mcast.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) # Subscribe the socket to multicast messages from the given address. mreq = struct.pack('4sl', inet_aton(mcast_addr[0]), INADDR_ANY) mcast.setsockopt(IPPROTO_IP, IP_ADD_MEMBERSHIP, mreq) if sys.platform == 'win32': # windows special case mcast.bind( ('localhost', mcast_addr[1]) ) else: # should work for everything else mcast.bind(mcast_addr) # -- Create the peer-to-peer socket. -- peer = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP) # Set the socket multicast TTL so it can send multicast messages. peer.setsockopt(IPPROTO_IP, IP_MULTICAST_TTL, 5) # Bind the socket to a random port. if sys.platform == 'win32': # windows special case peer.bind( ('localhost', INADDR_ANY) ) else: # should work for everything else peer.bind( ('', INADDR_ANY) ) # -- make the gui -- window = MainWindow() window.writeln( 'my address is %s:%s' % peer.getsockname() ) window.writeln( 'my position is (%s, %s)' % sensor_pos ) window.writeln( 'my sensor value is %s' % sensor_val ) # -- This is the event loop. -- while window.update(): pass
def __init__(self): MainWindow.MainWindowDelegate.__init__(self) glClearColor(0.0, 0.0, 0.25, 0.0) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) self._result = None self._gmVer = Sprite.TextDisplayer() self._gmVer.setText("GalaxyMage %s" % Main.__version__) self._gmVer.setFont(Resources.font(size=14, bold=False)) self._label = Sprite.TextDisplayer() self._label.setFont(Resources.font(size=20, bold=True)) self._menu = ScenarioChooserMenu() self._menu.setEnabled(True) self.addressEntry = Sprite.TextEntry() self.resize(MainWindow.get().size()) self.fsm = ScenarioChooserFSM(self) self.scenario = None self.multiplayer = None self.serverAddress = None self.hostGame = None self.readyToStart = False
def setUp(self): self.app = QApplication(sys.argv) self._principale = MainWindow.mainwindow("0.0.0") self._about = aboutDialog.aboutDial(self._principale) self._loginwidget = loginDialog.Login(self._principale)
__VERSION__ = "0.0.9" if __name__ == '__main__': argparser = argparse.ArgumentParser(prog="Thinkzone",version = __VERSION__) grupporeg = argparser.add_argument_group("Opzioni registrazione") gruppoescl = argparser.add_mutually_exclusive_group(required = True) gruppoescl.add_argument("-g","--gui",action="store_true",help="Fa partire l'interfaccia grafica.") gruppoescl.add_argument("-r",nargs=2,metavar=("username","password"),help="Registra un utente.") grupporeg.add_argument("-a","--address",metavar="hostname",help="Hostname del server per la registraizone.") grupporeg.add_argument("-p","--port",metavar="porta",type=int,default=4242,help="La porta del server a cui connettersi.") arogmi = argparser.parse_args(sys.argv[1:]) if(arogmi.gui): print('Starting gui...') app = QtGui.QApplication(sys.argv) finestra = MainWindow.mainwindow(__VERSION__) finestra.show() app.exec() print('exit') else: username = arogmi.r[0] password = arogmi.r[1] porta = arogmi.port hostname = arogmi.address connettore = Comunicazione.comunicatore() connettore.registrati(hostname, porta, username, password) if(connettore._registered): print('Registrazione completata correttamente') else: print('Registrazione non effettuata. Consulta il file di log per ulteriori informazioni.')
NUMBER_OF_ROWS = 10 ** 2 NUMBER_OF_COLS = 10 ROW_OFFSET = 2 COL_OFFSET = 2 VALUES_BUTTON_MAX_WIDTH = 50 VARIABLE_LIST_COLS_WIDTH = 50 VARIABLE_LIST_COL_N_WIDTH = 20 VARIABLE_LIST_COLS_COUNT = 6 N_ROLE = 0 NAME_ROLE = 1 TYPE_ROLE = 2 WIDTH_ROLE = 3 DECIMAL_ROLE = 4 LABEL_ROLE = 5 if __name__ == '__main__': sys.excepthook = handle_exception setup_logger("FS") app = QApplication(sys.argv) app.setStyle("Fusion") app.blockSignals(True) fill_random() app.blockSignals(False) window = MainWindow() window.show() exit_code = app.exec_() sys.exit(exit_code)
#!/usr/bin/python # -*- coding: utf-8 -*- from PyQt5 import QtWidgets from gui import MainWindow, GuiManger from app import StatusClientThread from gui.uiconfig import windowsoptions from gui.dialogs import weblogin if __name__ == '__main__': import sys app = QtWidgets.QApplication(sys.argv) loginsettings = windowsoptions['weblogin_window'] login_flag, address = weblogin(loginsettings) if login_flag: mainwindow = MainWindow() guimanger = GuiManger(address) statusThread = StatusClientThread(address) statusThread.daemon = True statusThread.start() mainwindow.show() sys.exit(app.exec_())
logging.info("Starting tweetStream %s" % __version__) if len(sys.argv) < 2: logging.fatal("No username given! Stopping...") print "Usage: %s [username] [-c]" % sys.argv[0] sys.exit(1) uname = sys.argv[1] logging.info("Given username %s" % uname) client = TwitterClient(uname) if len(sys.argv) == 3 and sys.argv[2] == '-c': client.start() shown = [] while True: try: time.sleep(3) c = client.storage.get_all_sorted() for t in c: if t.guid not in shown: print t shown.append(t.guid) except KeyboardInterrupt: client.stop() sys.exit(0) else: win = MainWindow(client) win.main()
def main(argv = sys.argv): app = QApplication(argv) win = MainWindow() win.show() return app.exec_()
def main(mcast_addr, sensor_pos, sensor_range, sensor_val, grid_size, ping_period): """ mcast_addr: udp multicast (ip, port) tuple. sensor_pos: (x,y) sensor position tuple. sensor_range: range of the sensor ping (radius). sensor_val: sensor value. grid_size: length of the of the grid (which is always square). ping_period: time in seconds between multicast pings. """ # -- Create the multicast listener socket. -- mcast = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP) # Sets the socket address as reusable so you can run multiple instances # of the program on the same machine at the same time. mcast.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) # Subscribe the socket to multicast messages from the given address. mreq = struct.pack('4sl', inet_aton(mcast_addr[0]), INADDR_ANY) mcast.setsockopt(IPPROTO_IP, IP_ADD_MEMBERSHIP, mreq) mcast.bind(mcast_addr) # -- Create the peer-to-peer socket. -- peer = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP) # Set the socket multicast TTL so it can send multicast messages. peer.setsockopt(IPPROTO_IP, IP_MULTICAST_TTL, 5) # Bind the socket to a random port. if sys.platform == 'win32': # windows special case peer.bind( ('localhost', INADDR_ANY) ) else: # should work for everything else peer.bind( ('', INADDR_ANY) ) # -- make the gui -- window = MainWindow() window.writeln("My address is %s:%s" % peer.getsockname()) window.writeln("My position is (%s, %s)" % sensor_pos) window.writeln("My sensor value is %s" % sensor_val) # Periodic pinging. A value of -1 causes an immediate ping event. # When entering the group, a first ping is sent. lastpingtime = -1 # The set of neighbours; (position, address). neighbours = set() # The echo sequence number. echoseq = -1; # The dictionary of fathers of currently active echo's; (position, address). father = {} # The dictionary of sets of pending neighbours of currently active echo's. echo = {} # The dictionary of operations of currently active echo's. echoop = {} # The dictionary of lists of loads of currently active echo's. echoload = {} # -- This is the event loop. -- while window.update(): line = window.getline() # Our event loop will consist of 5 steps. # 1: Interpret the command line input (if any). # 2: If a ping event should occur, ping. # 3: If an echo event should occur, echo. # 4: If one or more messages are received, handle them. # 5: If echo's have finished, show or forward their results. # The operation of a new echo. If the value is nonnegative, an echo occurs. newechoop = -1 if (line): #debug: window.writeln("> " + line) #switch line if (line == "ping"): # Cause a ping event immediately. lastpingtime = -1 elif (line == "list"): window.writeln("Neighbours:") for (npos, naddr) in neighbours: window.writeln("\t- neighbour at " + str(npos) + " from " + str(addr)) #end for neighbours window.writeln("\t(end of list)") elif (line == "move"): sensor_pos = random_position(grid_size) window.writeln("My new position is (%s, %s)" % sensor_pos) elif (line == "value"): sensor_val = randint(0, 100) window.writeln("My sensor value is %s" % sensor_val) elif (line == "echo"): newechoop = OP_NOOP elif (line == "size"): newechoop = OP_SIZE elif (line == "sum"): newechoop = OP_SUM elif (line == "max"): newechoop = OP_MAX elif (line == "min"): newechoop = OP_MIN else: window.writeln("{ command not recognised }") #end switch line #end if line # If lastpingtime has a negative value, a ping occurs. # Otherwise, a ping occurs if periodic pinging is on and ping_period # seconds have past since the last ping. # Any ping sets the timer back to ping_period seconds. if ((lastpingtime < 0) or (ping_period > 0 and \ (time.time() >= lastpingtime + ping_period))): neighbours.clear() msg = message_encode(MSG_PING, 0, sensor_pos, sensor_pos) peer.sendto(msg, mcast_addr) lastpingtime = time.time() #end if ping # If newechoop has a nonnegative value, a new echo wave is sent. # echo[eid] is the set of all neighbours that haven't responded yet. if (newechoop >= 0): echoseq += 1; eid = (sensor_pos, echoseq) echo[eid] = neighbours.copy() father[eid] = (sensor_pos, None) echoop[eid] = newechoop echoload[eid] = [] msg = message_encode(MSG_ECHO, echoseq, sensor_pos, sensor_pos, newechoop) for (npos, naddr) in neighbours: peer.sendto(msg, naddr) #end for neighbours #end if echoop # Read from available sockets. rrdy, wrdy, err = select.select([mcast, peer], [], [], 0) for r in rrdy: (msg, addr) = r.recvfrom(message_length) if (len(msg) > 0): content = message_decode(msg) tp, seq, initiator, sender, op, payload = content # Take actions depending on the message type (tp). if (tp == MSG_PING): # Respond to pings with a pong with your position. # Don't respond to your own pings. if (sender != sensor_pos): resp = message_encode(MSG_PONG, 0, initiator, sensor_pos) peer.sendto(resp, addr) #end if notself elif (tp == MSG_PONG): if (sender == sensor_pos): # In the rare case of a collision, move. sensor_pos = random_position(grid_size) window.writeln("{ collision detected }") window.writeln("My new position is (%s, %s)" % sensor_pos) elif (is_in_range(sensor_pos, sensor_range, sender)): # If the other node is in range, add it as a neighbour. neighbours.add((sender, addr)) #end if inrange elif (tp == MSG_ECHO): eid = (initiator, seq) if (eid not in echo): # If this echo is new, make a new (sub)echo. # echo[eid] is the set of neighbours that haven't responded yet. echo[eid] = neighbours.copy() echoop[eid] = op echoload[eid] = [] father[eid] = (None, None) frw = message_encode(MSG_ECHO, seq, initiator, sensor_pos, op) for (npos, naddr) in echo[eid]: if (npos == sender): # If the sender is a neighbour*, make it the father. # (* This is usually true, but the neighbour list may be old.) father[eid] = (npos, naddr) else: peer.sendto(frw, naddr) #end if sender #end for echo neighbours # We're not waiting for the father to respond, so discard it. echo[eid].discard(father[eid]) else: # If you already received this echo, respond with empty payload # and set operation to OP_NOOP, to prevent the payload from being # registered as value 0. frw = message_encode(MSG_ECHO_REPLY, seq, initiator, sensor_pos, \ OP_NOOP) for (npos, naddr) in neighbours: if (npos == sender): peer.sendto(frw, naddr) #end if sender #end for neighbours #end if new echo elif (tp == MSG_ECHO_REPLY): eid = (initiator, seq) if (eid in echo): for (npos, naddr) in echo[eid]: if (npos == sender): gotfrom = (npos, naddr) #end if sender #end for echo neighbours # Add the payload to the echoload list. If the echo operation is a # real operation, discard any payloads that arrive with operation # OP_NOOP; these are just acknowledgements. if (op == echoop[eid]): echoload[eid].append(payload) #end if op match # gotfrom has responded; remove it from the echo's pending set. echo[eid].discard(gotfrom) #end if echo exists else: window.writeln("{ unknown message type " + str(tp) + " received }") #end switch tp #debug: window.writeln("< " + str(addr) + ": " + str(content)) #end if len #end for r # We shall check if any (sub)echo's are finished, i.e. all neighbours that # should have responded, have responded. If so, echo[eid] will be empty. finished = set() for (eid, pending) in echo.iteritems(): if (len(pending) == 0): finished.add(eid) # If the operation is a simple count, add a 1 to the list. # If the operation manages sensor values, add your own sensor value. op = echoop[eid] if (op == OP_NOOP or op == OP_SIZE): echoload[eid].append(1) elif (op == OP_SUM or op == OP_MIN or op == OP_MAX): echoload[eid].append(sensor_val) #end switch op # If the operation is a function on payloads, calculate the result. # If the operation is a basic echo, ignore the payloads; the fact that # the echo completes is enough information. if (op == OP_SIZE or op == OP_SUM): result = sum(echoload[eid]) elif (op == OP_MIN): result = min(echoload[eid]) elif (op == OP_MAX): result = max(echoload[eid]) else: result = 1 #end switch op (fpos, faddr) = father[eid] # If I am the initiator, faddr will be set to None. # In the case that I have moved during an echo, discard the results. # In the rare case that 'neighbours' was outdated when a father was set, # the father might be (None, None) instead; discard the results. # Otherwise, faddr will be the address of the father. if (fpos == sensor_pos and faddr is None): # If I am the initiator, display the results. if (op == OP_SIZE): window.writeln("Cluster size: " + str(result)) elif (op == OP_SUM): window.writeln("Sum of sensor values in cluster: " \ + str(result)) elif (op == OP_MIN): window.writeln("Minimum of sensor values in cluster: " \ + str(result)) elif (op == OP_MAX): window.writeln("Maximum of sensor values in cluster: " \ + str(result)) else: window.writeln("Echo complete.") #end switch op elif (fpos is not None and faddr is not None): # If I am not the father, forward the subresult to the father. (initiator, seq) = eid msg = message_encode(MSG_ECHO_REPLY, seq, initiator, sensor_pos, \ op, result) peer.sendto(msg, faddr) #end if self father #end if echo empty #end for echos # Remove finished echo's. for eid in finished: del echo[eid] del father[eid] del echoop[eid] del echoload[eid] #end for finished #end while update return
def main(): app = QApplication(sys.argv) window = MainWindow() window.show() app.exec_()
def test_gui_main_window(self): from gi.repository import Gtk try: from .config import Config from .map import Map from .gui import MainWindow from .client import ClientThread except SystemError: from config import Config from map import Map from gui import MainWindow from client import ClientThread def dummy(server_id): return test_widget = TestWidget() test_config = Config(None).default_config test_map = Map(test_config["map"]) test_networks = networks() test_client_threads = {0: ClientThread()} main_window = MainWindow(test_config, dummy, dummy, test_map, test_networks, {0: None, 1: None}, test_client_threads) main_window.network_list.crypt_cache = {} main_window.log_list.add("Kismon", "test") main_window.network_list.add_network('11:22:33:44:55:66') main_window.network_list.network_selected = '11:22:33:44:55:66' main_window.network_list.add_network('00:12:2A:03:B9:12') main_window.network_list.add_network('00:12:2A:03:B9:12') main_window.network_list.column_selected = 2 main_window.network_list.on_copy_field(None) main_window.network_list.on_copy_network(None) main_window.network_list.on_comment_editing_done(test_widget) main_window.network_list.remove_network('00:12:2A:03:B9:12') main_window.server_tabs[0].update_info_table({"networks":100, "packets":200} ) main_window.server_tabs[0].update_gps_table({"fix": 3, "lat": 52.0, "lon": 13.0}) sources = {"1": {"uuid": "1", "username": "******", "type": "bla", "channel": 11, "packets": 100}} main_window.server_tabs[0].update_sources_table(sources) main_window.on_configure_event(None, None) main_window.on_config_window(None) main_window.on_config_window(None) main_window.on_signal_graph(None) main_window.on_signal_graph_destroy(None, "11:22:33:44:55:66") main_window.fullscreen() main_window.fullscreen() main_window.on_map_window(None, True) main_window.on_map_window(None, False) main_window.on_map_widget(None, True) main_window.on_map_widget(None, False) #main_window.on_server_disconnect(None, 0) test_event = TestEvent() main_window.on_window_state(None, test_event) config_window = main_window.config_window main_window.on_file_import(None) test_widget.text = "Infrastructure" main_window.on_network_filter_type(test_widget) main_window.on_network_filter_networks(test_widget, "map", "all")
'/usr/lib/%s-linux-gnu/qt5/plugins/' % 'i386') else: QApplication.addLibraryPath( '/usr/lib/%s-linux-gnu/qt5/plugins/' % platform.machine()) applicationName = 'PFramer' app = QSingleApplication(applicationName, sys.argv) app.setApplicationVersion("1.0") app.setOrganizationName("dragondjf.github.io") app.setApplicationName(applicationName) if app.isRunning(): sys.exit(0) if windowsoptions['splashflag']: splash = FSplashScreen(1, windowsoptions['splashimg']) mainwindow = MainWindow() mainwindow.show() splash.finish(mainwindow) else: mainwindow = MainWindow() mainwindow.show() app.setActivationWindow(mainwindow) mainwindow.guimanger.globals = globals() mainwindow.guimanger.locals = locals() print(app.desktop().availableGeometry()) mainwindow.setGeometry(app.desktop().screen().geometry()) exitCode = app.exec_()
filename = default_filename print('Change your default settings!') with open(filename) as setting_file: settings = json.load(setting_file) # alias out the individual settings for each of the sockets chrome_server_settings = settings['chrome_tcp_server'] wpc_settings = settings['watchpeoplecode'] twitch_settings = settings['twitch'] # instantiate the sockets wpc_socket = socket_protocols.ReadOnlyWebSocket(wpc_settings['channel']) irc_client = socket_protocols.ReadOnlyIRCBot(twitch_settings['channel'], twitch_settings['nick'], twitch_settings['oauth_token']) youtube_scrapper = YoutubeScrapper('https://www.youtube.com/watch?v=W2DS6wT6_48') # create the GUI app = QtWidgets.QApplication(sys.argv) main_window = MainWindow() main_window.show() # connect the sockets signals to the GUI youtube_scrapper.chat_signal.connect(main_window.chat_string_slot) wpc_socket.chat_signal.connect(main_window.chat_string_slot) irc_client.chat_signal.connect(main_window.chat_string_slot) # loop... forever sys.exit(app.exec_())
GUI loop. port: port to connect to. cert: public certificate (bonus task) """ sock = None try: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((host, port)) except socket.error, e: print 'Could not connect to server @%d' % port sys.exit(1) # The following code explains how to use the GUI. w = MainWindow() # update() returns false when the user quits or presses escape. while w.update(): line = w.getline() if line: while True: sock.send(line) inputready, outputready, exceptrdy = select.select([sock], [],[], 0.3) for i in inputready: if i == sock: data = sock.recv(1024) if not data: print 'Shutting down.' w.quit() else:
def main(argv): """ Program entry point. """ # size_wave is True in case a wave is ongoing that calculates size global size_wave size_wave = False global sum_wave sum_wave = False global min_wave min_wave = False global max_wave max_wave = False #last received echo message global echoMsg echoMsg = (0, 0) global neighbor_replies neighbor_replies = [] #IP and port of father global father father = (-1, -1) global waveSeqNr waveSeqNr = 0 # Set some of the global variables global neighbors neighbors = [] global peerlist peerlist = [] global x x = random.randint(0, 99) global y y = random.randint(0, 99) #x = int(argv[1]) #y = int(argv[2]) global value value = random.randint(0, 10) global size size = 0 global minimum minimum = value global maximum maximum = value s = socket(AF_INET, SOCK_DGRAM) s.connect(('google.com', 0)) ip = s.getsockname()[0] s.close() ## Create the multicast listener socket and suscribe to multicast. mcast = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP) socket_subscribe_mcast(mcast, MCAST_GRP) # Bind it to the multicast address. # NOTE: You may have to bind to localhost or '' instead of MCAST_GRP # depending on your operating system. # ALSO: In the lab room change the port to MCAST_PORT + group number # so that messages rom different groups do not interfere. # When you hand in your code in it must listen on (MCAST_GRP, MCAST_PORT). # Make resuable mcast.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) mcast.bind((MCAST_GRP, MCAST_PORT)) ## Create the peer-to-peer socket. peer = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP) # Set the socket multicast TTL so it can send multicast messages. peer.setsockopt(IPPROTO_IP, IP_MULTICAST_TTL, 2) # Bind the socket to a random port. peer.bind(('', INADDR_ANY)) # Find ip and port number #TODO find ip address #peer.connect(('google.com', 0)) _, port = peer.getsockname() global window ## This is the event loop. window = MainWindow() # Show information of newly connected node TODO: Display Local IP ip_port = "IP:Port = " + str(ip) + ":" + str(port) window.writeln(ip_port) window.writeln("position = (" + str(x) + ", " + str(y) + ")") window.writeln("sensor value = " + str(value)) # Send ping to all other users and start clock send_ping(peer) start = time.time() # Input for select input = [mcast, peer] peer.setblocking(0) mcast.setblocking(0) while window.update(): # In case 5 seconds have passed resend ping message if ((time.time() - start) > PING_PERIOD): neighbors = [] send_ping(peer) start = time.time() # Read input from mcast and peer try: message, address = mcast.recvfrom(1024) handle_message(peer, mcast, message, address) except error: pass try: message, address = peer.recvfrom(1024) handle_message(peer, mcast, message, address) except error: pass #See if there was GUI input command = window.getline() # Send a ping to the rest if(command == "ping"): neighbors = [] window.writeln("Sending ping over multicast...") send_ping(peer) # Show the list of neighbors elif(command == "list"): window.writeln("List of neighbors <(x,y), ip:port>:") if neighbors == []: window.writeln("No neighbors found") for i in neighbors: window.writeln(str(i[0]) + ", " + str(i[1][0]) + ":" + str(i[1][1])) # Move to a new random position elif(command == "move"): x = random.randint(0, 99) y = random.randint(0, 99) window.writeln("New position = " + str((x,y))) # Get a random new sensor value elif(command == "value"): value = random.randint(0, 10) window.writeln("New sensor value = " + str((x,y))) # Initiate wave elif(command == "wave"): size_wave = False sum_wave = False waveSeqNr += 1 window.writeln("Starting wave...") msg = MSG_ECHO, waveSeqNr, (x,y), (-1, -1), OP_NOOP, 0 # Send wave message to all numbers 1) send_echo(peer, msg, OP_NOOP) # Initiatie wave with size op elif(command == "size" ): size_wave = True # Make sure start with size = 0 size = 0 waveSeqNr += 1 window.writeln("Starting wave to get size...") msg = MSG_ECHO, waveSeqNr, (x,y), (-1, -1), OP_NOOP, 0 # Send wave message to all numbers 1) send_echo(peer, msg, OP_SIZE) # Initiatie wave with size op elif(command == "sum" ): sum_wave = True # Make sure start with size = 0 size = 0 waveSeqNr += 1 window.writeln("Starting wave to get sum...") msg = MSG_ECHO, waveSeqNr, (x,y), (-1, -1), OP_NOOP, 0 # Send wave message to all numbers 1) send_echo(peer, msg, OP_SUM) # Initiatie wave with min op elif(command == "min" ): min_wave = True # Make sure start with minimum = value minimum = value waveSeqNr += 1 window.writeln("Starting wave to get min...") msg = MSG_ECHO, waveSeqNr, (x,y), (-1, -1), OP_NOOP, 0 # Send wave message to all numbers 1) send_echo(peer, msg, OP_MIN) # Initiatie wave with max op elif(command == "max" ): max_wave = True # Make sure start with maximum = value maximum = value waveSeqNr += 1 window.writeln("Starting wave to get max...") msg = MSG_ECHO, waveSeqNr, (x,y), (-1, -1), OP_NOOP, 0 # Send wave message to all numbers 1) send_echo(peer, msg, OP_MAX) # If now input than pass elif(command == ""): pass else: window.writeln("\"" + command + "\" is not a valid command")
def main(argv): """ Program entry point. """ #last received echo message global echoMsg echoMsg = (0, 0) global neighbor_replies neighbor_replies = [] #IP and port of father global father father = (-1, -1) global waveSeqNr waveSeqNr = 0 # Set some of the global variables global neighbors neighbors = [] # TODO: Make global and no duplicate values between nodes global x x = random.randint(0, 10) global y y = random.randint(0, 10) global value value = random.randint(0, 259898) ## Create the multicast listener socket and suscribe to multicast. mcast = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP) socket_subscribe_mcast(mcast, MCAST_GRP) # Bind it to the multicast address. # NOTE: You may have to bind to localhost or '' instead of MCAST_GRP # depending on your operating system. # ALSO: In the lab room change the port to MCAST_PORT + group number # so that messages rom different groups do not interfere. # When you hand in your code in it must listen on (MCAST_GRP, MCAST_PORT). # Make resuable mcast.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) mcast.bind((MCAST_GRP, MCAST_PORT)) ## Create the peer-to-peer socket. peer = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP) # Set the socket multicast TTL so it can send multicast messages. peer.setsockopt(IPPROTO_IP, IP_MULTICAST_TTL, 2) # Bind the socket to a random port. peer.bind(('', INADDR_ANY)) ## This is the event loop. window = MainWindow() print (x,y) # Show information of newly connected node TODO: Display Local IP ip_port = "IP:Port = " + str(MCAST_GRP) + ":" + str(INADDR_ANY) window.writeln(ip_port) window.writeln("position = (" + str(x) + ", " + str(y) + ")") window.writeln("sensor value = " + str(value)) # Send ping to all other users and start clock send_ping(peer) start = time.time() # Input for select input = [mcast, peer] peer.setblocking(0) mcast.setblocking(0) while window.update(): # In case 5 seconds have passed resend ping message if ((time.time() - start) > PING_PERIOD): neighbors = [] send_ping(peer) start = time.time() # Read input from mcast and peer try: message, address = mcast.recvfrom(1024) handle_message(peer, mcast, message, address) except error: pass try: message, address = peer.recvfrom(1024) print message_decode(message) handle_message(peer, mcast, message, address) except error: pass #See if there was GUI input command = window.getline() # Send a ping to the rest if(command == "ping"): neighbors = [] window.writeln("Sending ping over multicast...") send_ping(peer) # Show the list of neighbors elif(command == "list"): window.writeln("List of neighbors <(x,y), ip:port>:") if neighbors == []: window.writeln("No neighbors found") for i in neighbors: window.writeln(str(i[0]) + ", " + str(i[1][0]) + ":" + str(i[1][1])) # Move to a new random position elif(command == "move"): x = random.randint(0, 99) y = random.randint(0, 99) window.writeln("New position = " + str((x,y))) # Initiate wave elif(command == "wave"): waveSeqNr += 1 window.writeln("Starting wave...") encripted_message = message_encode(MSG_ECHO, waveSeqNr, (x,y), (-1, -1), OP_NOOP, 0) # Send wave message to all numbers 1) for i in neighbors: peer.sendto(encripted_message, i[1]) #peer.sendto("ECHO_MSG", i[1]) # If now input than pass elif(command == ""): pass else: window.writeln("\"" + command + "\" is not a valid command")