Пример #1
0
Файл: gui.py Проект: Okmr27/V2X
    def __init__(self, parent=None):
        super().__init__(parent)
        # initialize gui from QT Designer
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        self.host_list = []
        self.report_active = True
        self.message = {}
        self.report = ''
        # command to start receiving reports
        self.cmd = 'start_report'
        # gui events
        self.ui.startButton.clicked.connect(self.on_start_button_click)
        self.ui.stopButton.clicked.connect(self.on_stop_button_click)
        self.ui.send_cmd_btn.clicked.connect(self.send_cmd)

        self.ui.connect_report_btn.clicked.connect(self.connect_report)
        self.ui.start_report_btn.clicked.connect(self.start_report)
        self.ui.stop_report_btn.clicked.connect(self.stop_report)
        self.ui.plot_btn.clicked.connect(self.plot_report)

        self.ui.stop_report_btn.setEnabled(False)
        self.ui.start_report_btn.setEnabled(False)
        # plot window
        self.plot = PlotWindow(self)

        self.x_curr = 0
        self.y_curr = 0

        self.pos_dict = {}
        self.old_pos = (0, 0)
Пример #2
0
class MainWindow(QtWidgets.QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

    def closeEvent(self, event):
        print("closeEvent")
Пример #3
0
 def __init__(self, parent=None):
     self.app = QtWidgets.QApplication(sys.argv)  # the main application
     super().__init__(parent)
     self.ui = Ui_MainWindow()  # the main window
     self.ui.setupUi(self)  # set up the GUI
     # connecect the menu actions with their functions
     self.ui.get.clicked.connect(self.get_weather)
     self.ui.name.triggered.connect(self.name)
     self.ui.phone.triggered.connect(self.phone)
     self.ui.help.triggered.connect(self.help)
Пример #4
0
    def __init__(self):
        super().__init__()
        log.debug("MainWindow construct")
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.slm = QStringListModel()

        # only for client ipv4 saved
        self.client_ipv4_List = []

        # class of c_led_client
        self.client_list = []
        self.slm.setStringList(self.client_ipv4_List)
        self.ui.listView_client.setModel(self.slm)
        self.ipv4_addr = multicast_utils.get_eth0_ip('enp8s0')
        log.info("self.ipv4_addr = %s" % self.ipv4_addr)
        log.debug("type(self.ipv4_addr) : %s" % type(self.ipv4_addr))
        '''I can not recv any thing with multicast_sock_init'''
        #self.multicast_socket = multicast_utils.multicast_sock_init()
        '''But I can recv with this one. Strange!'''
        self.multicast_socket = multicast_utils.joinMcast_with_if(MULTICAST_IP)
        self.multicast_socket.settimeout(1)
        self.cmd_parser = cmd_parser(local_ipv4=self.ipv4_addr)

        self.send_data_total_len = 0
        self.send_data_total_len_per_sec = 0
        self.send_data_count = 0
        self.recv_count = 0
        self.thread_send = Worker(method=self.send_multicast)
        #self.thread_send.start()

        self.thread_recv = Worker(method=self.recv_multicast)
        #self.thread_recv.start()

        self._timer_send_data = QTimer(self)
        self._timer_send_data.timeout.connect(self.send_data)

        self._timer_recv_data = QTimer(self)
        self._timer_recv_data.timeout.connect(self.recv_multicast)

        self._timer_network_profile = QTimer(self)
        self._timer_network_profile.timeout.connect(self.cal_network_profile)
        self.btn_init()
        #self._timer_send_data.start(0.01)
        self._timer_network_profile.start(1)

        self._ui_update_timer = QTimer(self)
        self._ui_update_timer.timeout.connect(self.ui_update_timer)
        self._ui_update_timer.start(1000 * 1)
Пример #5
0
 def __init__(self):
     QtWidgets.QMainWindow.__init__(self)
     MainWindow.__init__(self)
     self.setupUi(self)
Пример #6
0
    def __init__(self, parent=None):
        super().__init__(parent)

        myappid = 'eft_quest_wiki.joshua_merold.v_0.3'
        ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)

        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        pixmamp = QPixmap("icons/Quest_Wiki_Logo.png")
        icon = QIcon(pixmamp)
        self.setWindowIcon(icon)

        pixmamp = QPixmap("icons/house.jpg")
        icon = QIcon(pixmamp)
        self.ui.pushButton_1.setIcon(icon)

        pixmamp = QPixmap("icons/list.jpg")
        icon = QIcon(pixmamp)
        self.ui.pushButton_2.setIcon(icon)

        pixmamp = QPixmap("icons/fav_blue.jpg")
        icon = QIcon(pixmamp)
        self.ui.pushButton_3.setIcon(icon)

        pixmamp = QPixmap("icons/settings.jpg")
        icon = QIcon(pixmamp)
        self.ui.pushButton_4.setIcon(icon)

        pixmamp = QPixmap("icons/clear.jpg")
        icon = QIcon(pixmamp)
        self.ui.btnClear.setIcon(icon)

        self.ui.table.insertColumn(0)
        self.ui.table.setColumnWidth(0, 50)
        self.ui.table.setHorizontalHeaderItem(
            0, QtWidgets.QTableWidgetItem("Fav"))
        self.ui.table.insertColumn(1)
        self.ui.table.setColumnWidth(1, 220)
        self.ui.table.setHorizontalHeaderItem(
            1, QtWidgets.QTableWidgetItem("Name"))
        self.ui.table.insertColumn(2)
        self.ui.table.setColumnWidth(2, 100)
        self.ui.table.setHorizontalHeaderItem(
            2, QtWidgets.QTableWidgetItem("Vendor"))
        self.ui.table.insertColumn(3)
        self.ui.table.setColumnWidth(3, 130)
        self.ui.table.setHorizontalHeaderItem(
            3, QtWidgets.QTableWidgetItem("Map"))
        self.ui.table.insertColumn(4)
        self.ui.table.setColumnWidth(4, 90)
        self.ui.table.setHorizontalHeaderItem(
            4, QtWidgets.QTableWidgetItem("EXP"))
        self.ui.table.insertColumn(5)
        self.ui.table.setColumnWidth(5, 79)
        self.ui.table.setHorizontalHeaderItem(
            5, QtWidgets.QTableWidgetItem("Roubles"))
        self.ui.table.insertColumn(6)
        self.ui.table.setColumnWidth(6, 117)
        self.ui.table.setHorizontalHeaderItem(
            6, QtWidgets.QTableWidgetItem("Rep"))
        self.ui.table.insertColumn(7)
        #self.ui.table.setColumnWidth(7, 143)
        self.ui.table.setHorizontalHeaderItem(
            7, QtWidgets.QTableWidgetItem("HiddenFavValue"))
        self.ui.table.hideColumn(7)

        self.ui.pages.setCurrentIndex(0)

        self.ui.btnUpdate.clicked.connect(self.update)

        ld = loadData.loadData()
        self.data = ld.load()
        self.showData(self.data)

        self.ui.searchInput.textChanged.connect(self.search)
        self.ui.btnSearch.clicked.connect(self.search)

        self.ui.pushButton_1.clicked.connect(self.goHome)
        self.ui.pushButton_2.clicked.connect(self.goList)
        self.ui.pushButton_3.clicked.connect(self.goFavorites)
        self.ui.pushButton_4.clicked.connect(self.goSettings)

        self.ui.statusbar.addPermanentWidget(self.ui.statusText)
        self.ui.statusText.setText("v0.3 | by Joshua Merold")

        self.ui.table.cellDoubleClicked.connect(self.tableClicked)

        slot = functools.partial(self.changeCol, 1)
        self.ui.missionNameCheckbox.clicked.connect(slot)
        slot = functools.partial(self.changeCol, 2)
        self.ui.vendorCheckbox.clicked.connect(slot)
        slot = functools.partial(self.changeCol, 3)
        self.ui.mapCheckbox.clicked.connect(slot)
        slot = functools.partial(self.changeCol, 4)
        self.ui.expCheckbox.clicked.connect(slot)
        slot = functools.partial(self.changeCol, 5)
        self.ui.roublesCheckbox.clicked.connect(slot)
        slot = functools.partial(self.changeCol, 6)
        self.ui.repCheckbox.clicked.connect(slot)

        self.clicked = False
        self.ui.table.horizontalHeader().sortIndicatorChanged.connect(
            self.sortFav)

        self.buttonClicked = "background-color: rgb(242, 242, 242); border: 2px solid rgb(242, 242, 242); border-radius: 35px; color: white;"
        self.buttonIdle = "background-color: rgb(255,255,255); border: 2px solid rgb(255,255,255); border-radius: 35px; color: white;"
        self.ui.pushButton_1.setStyleSheet(self.buttonClicked)
Пример #7
0
class mainWindow(QtWidgets.QMainWindow):
    def __init__(self, parent=None):
        super().__init__(parent)

        myappid = 'eft_quest_wiki.joshua_merold.v_0.3'
        ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)

        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        pixmamp = QPixmap("icons/Quest_Wiki_Logo.png")
        icon = QIcon(pixmamp)
        self.setWindowIcon(icon)

        pixmamp = QPixmap("icons/house.jpg")
        icon = QIcon(pixmamp)
        self.ui.pushButton_1.setIcon(icon)

        pixmamp = QPixmap("icons/list.jpg")
        icon = QIcon(pixmamp)
        self.ui.pushButton_2.setIcon(icon)

        pixmamp = QPixmap("icons/fav_blue.jpg")
        icon = QIcon(pixmamp)
        self.ui.pushButton_3.setIcon(icon)

        pixmamp = QPixmap("icons/settings.jpg")
        icon = QIcon(pixmamp)
        self.ui.pushButton_4.setIcon(icon)

        pixmamp = QPixmap("icons/clear.jpg")
        icon = QIcon(pixmamp)
        self.ui.btnClear.setIcon(icon)

        self.ui.table.insertColumn(0)
        self.ui.table.setColumnWidth(0, 50)
        self.ui.table.setHorizontalHeaderItem(
            0, QtWidgets.QTableWidgetItem("Fav"))
        self.ui.table.insertColumn(1)
        self.ui.table.setColumnWidth(1, 220)
        self.ui.table.setHorizontalHeaderItem(
            1, QtWidgets.QTableWidgetItem("Name"))
        self.ui.table.insertColumn(2)
        self.ui.table.setColumnWidth(2, 100)
        self.ui.table.setHorizontalHeaderItem(
            2, QtWidgets.QTableWidgetItem("Vendor"))
        self.ui.table.insertColumn(3)
        self.ui.table.setColumnWidth(3, 130)
        self.ui.table.setHorizontalHeaderItem(
            3, QtWidgets.QTableWidgetItem("Map"))
        self.ui.table.insertColumn(4)
        self.ui.table.setColumnWidth(4, 90)
        self.ui.table.setHorizontalHeaderItem(
            4, QtWidgets.QTableWidgetItem("EXP"))
        self.ui.table.insertColumn(5)
        self.ui.table.setColumnWidth(5, 79)
        self.ui.table.setHorizontalHeaderItem(
            5, QtWidgets.QTableWidgetItem("Roubles"))
        self.ui.table.insertColumn(6)
        self.ui.table.setColumnWidth(6, 117)
        self.ui.table.setHorizontalHeaderItem(
            6, QtWidgets.QTableWidgetItem("Rep"))
        self.ui.table.insertColumn(7)
        #self.ui.table.setColumnWidth(7, 143)
        self.ui.table.setHorizontalHeaderItem(
            7, QtWidgets.QTableWidgetItem("HiddenFavValue"))
        self.ui.table.hideColumn(7)

        self.ui.pages.setCurrentIndex(0)

        self.ui.btnUpdate.clicked.connect(self.update)

        ld = loadData.loadData()
        self.data = ld.load()
        self.showData(self.data)

        self.ui.searchInput.textChanged.connect(self.search)
        self.ui.btnSearch.clicked.connect(self.search)

        self.ui.pushButton_1.clicked.connect(self.goHome)
        self.ui.pushButton_2.clicked.connect(self.goList)
        self.ui.pushButton_3.clicked.connect(self.goFavorites)
        self.ui.pushButton_4.clicked.connect(self.goSettings)

        self.ui.statusbar.addPermanentWidget(self.ui.statusText)
        self.ui.statusText.setText("v0.3 | by Joshua Merold")

        self.ui.table.cellDoubleClicked.connect(self.tableClicked)

        slot = functools.partial(self.changeCol, 1)
        self.ui.missionNameCheckbox.clicked.connect(slot)
        slot = functools.partial(self.changeCol, 2)
        self.ui.vendorCheckbox.clicked.connect(slot)
        slot = functools.partial(self.changeCol, 3)
        self.ui.mapCheckbox.clicked.connect(slot)
        slot = functools.partial(self.changeCol, 4)
        self.ui.expCheckbox.clicked.connect(slot)
        slot = functools.partial(self.changeCol, 5)
        self.ui.roublesCheckbox.clicked.connect(slot)
        slot = functools.partial(self.changeCol, 6)
        self.ui.repCheckbox.clicked.connect(slot)

        self.clicked = False
        self.ui.table.horizontalHeader().sortIndicatorChanged.connect(
            self.sortFav)

        self.buttonClicked = "background-color: rgb(242, 242, 242); border: 2px solid rgb(242, 242, 242); border-radius: 35px; color: white;"
        self.buttonIdle = "background-color: rgb(255,255,255); border: 2px solid rgb(255,255,255); border-radius: 35px; color: white;"
        self.ui.pushButton_1.setStyleSheet(self.buttonClicked)

    def goHome(self):
        self.ui.pages.setCurrentIndex(0)
        self.changeButtonStyle(0)

    def goList(self):
        self.ui.pages.setCurrentIndex(1)
        self.changeButtonStyle(1)

    def goFavorites(self):
        self.ui.pages.setCurrentIndex(2)
        self.changeButtonStyle(2)
        self.getFav()

    def goSettings(self):
        self.ui.pages.setCurrentIndex(3)
        self.changeButtonStyle(3)

    def changeButtonStyle(self, clickedButton):
        self.ui.pushButton_1.setStyleSheet(self.buttonIdle)
        self.ui.pushButton_2.setStyleSheet(self.buttonIdle)
        self.ui.pushButton_3.setStyleSheet(self.buttonIdle)
        self.ui.pushButton_4.setStyleSheet(self.buttonIdle)

        if clickedButton == 0:
            self.ui.pushButton_1.setStyleSheet(self.buttonClicked)
        elif clickedButton == 1:
            self.ui.pushButton_2.setStyleSheet(self.buttonClicked)
        elif clickedButton == 2:
            self.ui.pushButton_3.setStyleSheet(self.buttonClicked)
        elif clickedButton == 3:
            self.ui.pushButton_4.setStyleSheet(self.buttonClicked)

    def update(self):
        rd = requestData.Data()
        print(rd.getCompleteSite())
        temp = rd.transformMissions()
        self.data = temp

        print("Saving...")
        sd = saveData.saveData()
        sd.save(self.data)

        self.showData(self.data)

    def showData(self, data):
        self.ui.table.setRowCount(0)

        count = 0
        for missionName, mission in data.items():
            if missionName == "timestamp" or missionName == "favorite" or missionName == "completeSite":
                continue

            vendor = "-"
            vendors = [
                "Prapor", "Therapist", "Fence", "Skier", "Peacekeeper",
                "Mechanic", "Ragman", "Jaeger", "Warden", "Bashkir", "Khokhol"
            ]
            map = "Any"
            maps = [
                "Factory", "Customs", "Woods", "Shoreline", "Interchange",
                "The Lab", "Reserve", "Hideout", "Streets of Tarkov",
                "Suburbs", "Town", "Lighthouse", "Terminal", "Arena",
                "Private Sector"
            ]
            if "infobox" in mission:
                for info in mission["infobox"]:
                    #print(info)
                    if info in vendors:
                        vendor = info

                    multipleMaps = re.findall(r"(?=(" + '|'.join(maps) + r"))",
                                              info)
                    if len(multipleMaps) > 0:
                        map = ", ".join(multipleMaps)

                    if info in maps:
                        map = info

            self.data[missionName].update({"Vendor": vendor})
            self.data[missionName].update({"Map": map})

            self.ui.table.insertRow(count)

            missionXP = "-"
            missionRoubles = "-"
            missionRep = "-"

            if "Rewards" in mission:
                missionRewards = mission["Rewards"][0].split("\n")

                for reward in missionRewards:
                    if "EXP" in reward:
                        missionXP = reward.strip("+EXP")

                    elif "Roubles" in reward:
                        missionRoubles = reward.strip("Roubles")

                    elif "Rep" in reward:
                        missionRep = reward.replace("Rep ", "")

            if mission["favorite"] == 0:
                favPic = QPixmap("icons/noFav.jpg")
                favIcon = QIcon(favPic)
                item = QtWidgets.QTableWidgetItem(favIcon, "")
                self.ui.table.setItem(count, 7,
                                      QtWidgets.QTableWidgetItem("0"))
            elif mission["favorite"] == 1:
                favPic = QPixmap("icons/fav.jpg")
                favIcon = QIcon(favPic)
                item = QtWidgets.QTableWidgetItem(favIcon, "")
                self.ui.table.setItem(count, 7,
                                      QtWidgets.QTableWidgetItem("1"))

            self.ui.table.setItem(count, 0, item)
            self.ui.table.setItem(count, 1,
                                  QtWidgets.QTableWidgetItem(missionName))
            self.ui.table.setItem(count, 2, QtWidgets.QTableWidgetItem(vendor))
            self.ui.table.setItem(count, 3, QtWidgets.QTableWidgetItem(map))
            self.ui.table.setItem(count, 4,
                                  QtWidgets.QTableWidgetItem(missionXP))
            self.ui.table.setItem(count, 5,
                                  QtWidgets.QTableWidgetItem(missionRoubles))
            self.ui.table.setItem(count, 6,
                                  QtWidgets.QTableWidgetItem(missionRep))

            count += 1

    def search(self):
        #print(self.data)
        self.ui.pages.setCurrentIndex(1)
        self.input = self.ui.searchInput.text().lower()
        if "ä" in self.input:
            self.input = self.input.replace("ä", "ae")

        foundItems = []
        for name, mission in self.data.items():
            if name == "timestamp" or name == "favorite" or name == "completeSite":
                continue

            if self.input in name.lower():
                foundItems.append(name)
                #print("name")

            for info in mission["infobox"]:
                info = info.lower()

                if self.input in info:
                    foundItems.append(name)
                    #print("infobox" + info)

        for i in range(0, self.ui.table.rowCount()):
            selection = self.ui.table.item(i, 1).text()
            if selection in foundItems:
                self.ui.table.showRow(i)

            else:
                self.ui.table.hideRow(i)

    def tableClicked(self, row, col):
        if col == 0:
            print(row)
            fav = favs.favs(self.data)
            fav.addFav(row)
            self.showData(self.data)

        else:
            self.ui.pages.setCurrentIndex(4)

            md = missionDetails.missionDetails(self.data)
            details = md.getDetails(row)

            self.ui.textBrowser_5.setHtml(details)
            #self.ui.textBrowser_5.setHtml("<img src='icons/settings.jpg' />")

        #print(row, col)

    def getFav(self):
        fav = favs.favs(self.data)
        favorites = fav.loadFavs()

        count = 0
        for name, obj in favorites.items():
            headline = name
            text = "".join(obj)

            if count == 0:
                self.ui.textBrowser_1.setText(
                    "<span style='font-weight:600; font-size:10pt'>" +
                    headline + "</span><ul>" + text + "</ul>")
            elif count == 1:
                self.ui.textBrowser_2.setText(
                    "<span style='font-weight:600; font-size:10pt'>" +
                    headline + "</span><ul>" + text + "</ul>")
            elif count == 2:
                self.ui.textBrowser_3.setText(
                    "<span style='font-weight:600; font-size:10pt'>" +
                    headline + "</span><ul>" + text + "</ul>")
            elif count == 3:
                self.ui.textBrowser_4.setText(
                    "<span style='font-weight:600; font-size:10pt'>" +
                    headline + "</span><ul>" + text + "</ul>")
            else:
                break
            count += 1

    def changeCol(self, col):
        print(col)
        if self.ui.table.isColumnHidden(col):
            self.ui.table.showColumn(col)
        else:
            self.ui.table.hideColumn(col)

    def sortFav(self, col):
        if col == 0:
            if self.clicked == False:
                self.ui.table.sortByColumn(7, QtCore.Qt.AscendingOrder)
                self.clicked = True
            else:
                self.ui.table.sortByColumn(7, QtCore.Qt.DescendingOrder)
                self.clicked = False
Пример #8
0
 def __init__(self):
     QMainWindow.__init__(self)
     self.main_ui = Ui_MainWindow()
     self.main_ui.setupUi(self)
Пример #9
0
class parentWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        self.main_ui = Ui_MainWindow()
        self.main_ui.setupUi(self)
Пример #10
0
class MainWindow(QtWidgets.QMainWindow):
    def __init__(self):
        super().__init__()
        log.debug("MainWindow construct")
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.slm = QStringListModel()

        # only for client ipv4 saved
        self.client_ipv4_List = []

        # class of c_led_client
        self.client_list = []
        self.slm.setStringList(self.client_ipv4_List)
        self.ui.listView_client.setModel(self.slm)
        self.ipv4_addr = multicast_utils.get_eth0_ip('enp8s0')
        log.info("self.ipv4_addr = %s" % self.ipv4_addr)
        log.debug("type(self.ipv4_addr) : %s" % type(self.ipv4_addr))
        '''I can not recv any thing with multicast_sock_init'''
        #self.multicast_socket = multicast_utils.multicast_sock_init()
        '''But I can recv with this one. Strange!'''
        self.multicast_socket = multicast_utils.joinMcast_with_if(MULTICAST_IP)
        self.multicast_socket.settimeout(1)
        self.cmd_parser = cmd_parser(local_ipv4=self.ipv4_addr)

        self.send_data_total_len = 0
        self.send_data_total_len_per_sec = 0
        self.send_data_count = 0
        self.recv_count = 0
        self.thread_send = Worker(method=self.send_multicast)
        #self.thread_send.start()

        self.thread_recv = Worker(method=self.recv_multicast)
        #self.thread_recv.start()

        self._timer_send_data = QTimer(self)
        self._timer_send_data.timeout.connect(self.send_data)

        self._timer_recv_data = QTimer(self)
        self._timer_recv_data.timeout.connect(self.recv_multicast)

        self._timer_network_profile = QTimer(self)
        self._timer_network_profile.timeout.connect(self.cal_network_profile)
        self.btn_init()
        #self._timer_send_data.start(0.01)
        self._timer_network_profile.start(1)

        self._ui_update_timer = QTimer(self)
        self._ui_update_timer.timeout.connect(self.ui_update_timer)
        self._ui_update_timer.start(1000 * 1)

    def btn_init(self):
        self.ui.btn_start_test.clicked.connect(self.start_test)
        self.ui.btn_stop_test.clicked.connect(self.stop_test)

    def start_test(self):
        log.debug("start_test")
        self._timer_send_data.start(1)
        self._timer_recv_data.start(0.1)
        #self._timer_network_profile.start(1)

    def stop_test(self):
        if self._timer_send_data is not None:
            self._timer_send_data.stop()
        time.sleep(20)
        #if self._timer_recv_data is not None:
        #    self._timer_recv_data.stop()
        log.debug("stop_test")

    def send_data(self):

        sent_data_len = self.multicast_socket.sendto(data_tmp * 500,
                                                     MULTICAST_GROUP)

        self.send_data_total_len_per_sec += sent_data_len
        self.send_data_total_len += sent_data_len
        self.send_data_count += 1
        log.debug("self.send_data_total_len : %d %d" %
                  (self.send_data_total_len, self.send_data_count))
        #log.debug("send_data_count : %d " % self.send_data_count)
        #self.recv_multicast()
        #self.stop_test()

    def cal_network_profile(self):
        speed_val = self.send_data_total_len_per_sec
        self.send_data_total_len_per_sec = 0
        label_str = "Speed: " + str(speed_val) + "Bytes/sec"
        self.ui.label_profile_per_sec.setText(label_str)

        total_val = self.send_data_total_len
        label_str = "Total: " + str(total_val) + "Bytes"
        self.ui.label_profile_total.setText(label_str)

    def send_multicast(self):
        if (self.multicast_socket is None):
            print("No multicast socket")
            return
        #print("send_multicast")
        self.send_data()

    def recv_multicast(self):
        if (self.multicast_socket is None):
            log.error("No multicast socket")
            return
        try:
            data, from_ip = self.multicast_socket.recvfrom(1500)
        except socket.timeout:
            log.debug('timed out, no more responses')
        else:
            if from_ip[0] == self.ipv4_addr:
                #log.debug('received "%s" from %s' % (data, from_ip))
                pass
            else:
                #log.debug("from_ip : %s" % from_ip[0])
                ret, type, response = self.cmd_parser.parse_packet(
                    data, from_ip)
                self.recv_count += 1
                #log.debug("self.recv_count : %d" % self.recv_count)
                if type == "report_data_length":
                    #log.debug("type : %s, response :%s" % (type, response))
                    add_client_to_list = True
                    index = 0
                    for n in self.client_ipv4_List:
                        if n.split("   ")[0] == from_ip[0]:
                            add_client_to_list = False
                            break
                        index += 1
                    if add_client_to_list is True:
                        self.client_ipv4_List.append(from_ip[0] + "   " +
                                                     response)
                        #self.slm.setStringList(self.client_ipv4_List)
                        client = led_client(from_ip[0])
                        client.set_client_recv_total_len(response)
                        self.client_list.append(client)

                    else:
                        for n in self.client_list:
                            if n.get_ipv4_addr() == from_ip[0]:
                                n.set_client_recv_total_len(
                                    int(n.get_client_recv_total_len()) +
                                    int(response))
                                self.client_ipv4_List[index] = (
                                    from_ip[0] + "   " +
                                    str(n.get_client_recv_total_len()))
                                #self.slm.setStringList(self.client_ipv4_List)

    def ui_update_timer(self):
        self.slm.setStringList(self.client_ipv4_List)

    def closeEvent(self, event):
        log.debug("closeEvent")
Пример #11
0
        RECORD_WORDBOOK.addWord(new_word)
        MainUI.record_text_word.setText('')
        MainUI.record_text_meaning.setPlainText('')
        MainUI.record_text_example.setPlainText('')
        MainUI.record_label_status.setText(
            f'当前状态:已添加单词\"{new_word["spelling"]}\"')
        MainUI.record_text_word.setFocus()
    else:
        QtWidgets.QMessageBox.warning(None, '错误', '未选择单词本!')


if __name__ == '__main__':
    QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
    app = QtWidgets.QApplication(sys.argv)

    MainWindow = QtWidgets.QMainWindow()

    MainUI = Ui_MainWindow()
    MainUI.setupUi(MainWindow)

    # icon = QtGui.QIcon()
    # iconfile = GetPath(os.path.join("assets", "icon_128x128.ico"))

    # icon.addPixmap(QtGui.QPixmap(iconfile), QtGui.QIcon.Normal, QtGui.QIcon.Off)
    # MainWindow.setWindowIcon(icon)

    MainUI.record_button_manage.clicked.connect(RECORD_MANAGE_WORDBOOKS)
    MainUI.record_button_record.clicked.connect(RECORD_ADD_WORD)

    MainWindow.show()
    sys.exit(app.exec())
Пример #12
0
class MainWindow(QtWidgets.QMainWindow):
    def __init__(self, parent=None):
        self.app = QtWidgets.QApplication(sys.argv)  # the main application
        super().__init__(parent)
        self.ui = Ui_MainWindow()  # the main window
        self.ui.setupUi(self)  # set up the GUI
        # connecect the menu actions with their functions
        self.ui.get.clicked.connect(self.get_weather)
        self.ui.name.triggered.connect(self.name)
        self.ui.phone.triggered.connect(self.phone)
        self.ui.help.triggered.connect(self.help)

    def show(self):
        super().show(
        )  # freeze the code untill the user closes the application main window
        sys.exit(self.app.exec_())

    def get_weather(self):
        city = self.ui.city.text()  # city name
        country = self.ui.country.text()  # country name
        try:
            data = get(city, country)  # get the weather data
            description = f'{data[0][0]} -- {data[0][1]}'
            self.ui.description.setText(description)
            self.ui.maintemp.setText(data[1])
            self.ui.feelslike.setText(data[2])
            self.ui.min_temp.setText(data[3])
            self.ui.max_temp.setText(data[4])
            self.ui.pressure.setText(data[5])
            self.ui.humidity.setText(data[6])
            self.ui.speed.setText(data[7])
            self.ui.angle.setText(data[8])

        except:  # incase of any error erase the data and show invalid input message
            self.ui.description.setText('Invalid Location !!')
            self.ui.maintemp.setText('')
            self.ui.feelslike.setText('')
            self.ui.min_temp.setText('')
            self.ui.max_temp.setText('')
            self.ui.pressure.setText('')
            self.ui.humidity.setText('')
            self.ui.speed.setText('')
            self.ui.angle.setText('')

    def name(self):  # show name message box
        msg = QtWidgets.QMessageBox()
        msg.setWindowTitle('My name')
        msg.setIcon(QtWidgets.QMessageBox.Information)
        msg.setText('Mohamed mostafa al-ghaly')
        show = msg.exec_()

    def phone(self):  # show phone message box
        msg = QtWidgets.QMessageBox()
        msg.setWindowTitle('Phone')
        msg.setIcon(QtWidgets.QMessageBox.Information)
        msg.setText('01002929690')
        show = msg.exec_()

    def help(self):  # show help message box
        msg = QtWidgets.QMessageBox()
        msg.setWindowTitle('Help')
        msg.setText('weather data from : openweathermap')
        msg.setIcon(QtWidgets.QMessageBox.Information)
        about = 'name : mohamed al-ghaly.\nphone : 01002929690\npython developer\n' \
                'twitter : https://twitter.com/mohamed32093140\n ' \
                'linkedin : https://www.linkedin.com/in/mohamed-alghaly-33ab201a3/'
        msg.setDetailedText(about)
        shoe = msg.exec_()
Пример #13
0
 def __init__(self):
     super(MainWindow, self).__init__()
     self.ui = Ui_MainWindow()
     self.ui.setupUi(self)
Пример #14
0
Файл: gui.py Проект: Okmr27/V2X
class MainWindow(QtWidgets.QMainWindow):
    def __init__(self, parent=None):
        super().__init__(parent)
        # initialize gui from QT Designer
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        self.host_list = []
        self.report_active = True
        self.message = {}
        self.report = ''
        # command to start receiving reports
        self.cmd = 'start_report'
        # gui events
        self.ui.startButton.clicked.connect(self.on_start_button_click)
        self.ui.stopButton.clicked.connect(self.on_stop_button_click)
        self.ui.send_cmd_btn.clicked.connect(self.send_cmd)

        self.ui.connect_report_btn.clicked.connect(self.connect_report)
        self.ui.start_report_btn.clicked.connect(self.start_report)
        self.ui.stop_report_btn.clicked.connect(self.stop_report)
        self.ui.plot_btn.clicked.connect(self.plot_report)

        self.ui.stop_report_btn.setEnabled(False)
        self.ui.start_report_btn.setEnabled(False)
        # plot window
        self.plot = PlotWindow(self)

        self.x_curr = 0
        self.y_curr = 0

        self.pos_dict = {}
        self.old_pos = (0, 0)

    # ------ Client Tab ---------

    def on_start_button_click(self):
        self.s = RunServerThread()
        print("clicked")
        self.s.client_changed.connect(self.print_clients)
        self.ui.startButton.setEnabled(False)
        self.ui.stopButton.setEnabled(True)
        self.s.finished.connect(self.thread_complete)
        self.s._actice = True
        self.ui.connect_report_btn.setEnabled(False)
        # starts the server thread
        self.s.start()

    def on_stop_button_click(self):
        self.s.interrupt()

        self.ui.startButton.setEnabled(True)
        self.ui.stopButton.setEnabled(False)
        self.ui.connect_report_btn.setEnabled(True)

    def print_clients(self, client_list):
        # if client is connected -> add to list
        new_host = list(set(client_list) - set(self.host_list))
        # if client connection lost -> delete from list
        to_remove = list(set(self.host_list) - set(client_list))

        if new_host:
            # tuple of host and id
            client_id, client_host = new_host[0]
            # add to gui list
            self.ui.ipList.addItem(f"{client_id}: {client_host}")
        if to_remove:
            client_id, _ = to_remove[0]
            # delete from gui list
            self.ui.ipList.takeItem(
                self.ui.ipList.row(
                    self.ui.ipList.findItems(str(client_id),
                                             Qt.MatchContains)[0]))

        self.host_list = client_list[:]

    # ---------------------------

    # ------ Command Tab ---------

    def send_cmd(self):
        # get selected host from list
        selected_item = self.ui.ipList.currentItem()

        cmd = self.ui.cmd_line.text()
        if selected_item and cmd:
            # prepare command to send
            selected_item_tuple = tuple(selected_item.text().replace(
                " ", "").split(':'))
            server.send_cmd_to_client(selected_item_tuple, cmd)
            self.ui.cmd_line.setText('')  # clear textbox

    # ---------------------------

    # ------ Report Tab ---------

    def print_report(self, m):
        if not m == self.message:
            self.message = m
            # prepare msg
            self.report = f"{self.message['addr']}> {self.message['data']}"
            # add to gui list and scroll down
            self.ui.reportList.addItem(self.report)
            self.ui.reportList.scrollToBottom()
            # get host name from report
            _, host_curr = self.message['addr']
            # extract position from report
            x_curr, y_curr = server.extract_pos()
            # create dict for hostname and pos
            self.pos_dict[host_curr] = (x_curr, y_curr)
            # check pos has changed
            if not (self.old_pos == (x_curr, y_curr)):
                # update plot
                print(host_curr, (x_curr, y_curr))
                self.plot.update_plot(self.pos_dict)
                self.old_pos = (x_curr, y_curr)
                # delete last hostname from dict to speed up the plot
                del self.pos_dict[host_curr]

            # check area to forward or discard data
            if stat.check_area(x_curr, y_curr):
                # broadcast to other clients
                server.broadcast(self.report, host=self.message['addr'])

            else:
                print('blocked!', (x_curr, y_curr))

    def connect_report(self):
        # create instance of Report thread
        self.r = RunReportThread()

        self.ui.connect_report_btn.setEnabled(False)

        self.ui.start_report_btn.setEnabled(True)
        self.ui.reportList.addItem('Connected to clients..')
        self.ui.reportList.addItem('Report created!')

    def start_report(self):
        # set while statement true to loop
        self.r._actice = True
        # gui events
        self.r.report_recv.connect(self.print_report)
        self.r.finished.connect(self.thread_complete)
        self.ui.start_report_btn.setEnabled(False)
        self.ui.stop_report_btn.setEnabled(True)
        # start report thread
        self.r.start()

    def stop_report(self):
        self.r.interrupt()
        self.ui.start_report_btn.setEnabled(True)
        self.ui.stop_report_btn.setEnabled(False)
        # create statistic
        forward, discard = stat.get_statistic()
        self.ui.reportList.addItem(f"forward:{forward}, discard:{discard}")

    def plot_report(self):
        # show plot window and initialize
        self.plot.show()
        self.plot.plot_clients()

    # ---------------------------

    def thread_complete(self):
        print('Thread closed!')