예제 #1
0
 def clearCacheReports(self):
     dirci = QDir(self.mDir + QDir.separator() + "tempReports")
     if dirci.exists():
         listFiles = []
         listFiles = dirci.entryList(QDir.Files)
         for sdfile in listFiles:
             QDir().remove(dirci.path() + QDir.separator() + sdfile)
예제 #2
0
 def clearCacheScaleImage(self):
     dirci = QDir(self.mDir + QDir.separator() + "imagecache")
     if dirci.exists():
         listFiles = []
         listFiles = dirci.entryList(QDir.Files)
         for sdfile in listFiles:
             QDir().remove(dirci.path() + QDir.separator() + sdfile)
예제 #3
0
    def scaleImage(self, pixels, path):
        dircache = QDir(self.mDir + QDir.separator() + "imagecache")
        if dircache.exists() == False:
            s = QDir(self.mDir)
            s.mkdir("imagecache")

        ima = QImage(path)
        wids = ima.width()
        heis = ima.height()
        if (wids > pixels or heis > pixels):
            imarescale = ima.scaledToWidth(
                pixels, Qt.SmoothTransformation) if (
                    wids > heis) else ima.scaledToHeight(
                        pixels, Qt.SmoothTransformation)

            newImagePath = dircache.path() + QDir.separator(
            ) + "_temp_scaled_" + QFileInfo(path).fileName()
            imawriter = QImageWriter()
            imawriter.setFileName(newImagePath)
            #    imawriter.setFormat("png");
            if (imawriter.write(imarescale)):
                #qDebug()<<"si path"<<newImagePath
                return newImagePath
            else:
                #qDebug()<<"no path"<<newImagePath;
                return path

        return path
예제 #4
0
 def selectSystemTranslation(self, language, typemodule):
     dirsystem = "systemnet" if typemodule == True else "system"
     dirsyslan = QDir(self.mDir + QDir.separator() + dirsystem)
     if dirsyslan.exists():
         if QFileInfo(dirsyslan.path() + QDir.separator() + language +
                      ".qm").exists():
             translator = QTranslator(self)
             translator.load(dirsyslan.path() + QDir.separator() + language)
             self.mApp.installTranslator(translator)
         else:
             language = language.split('_')[0]
             if len(language) == 2:
                 if QFileInfo(dirsyslan.path() + QDir.separator() +
                              language + ".qm").exists():
                     translator = QTranslator(self)
                     translator.load(dirsyslan.path() + QDir.separator() +
                                     language)
                     self.mApp.installTranslator(translator)
예제 #5
0
 def selectCoreTranslation(self, language, settings):
     settings.setValue("translate", "en")
     dircorelan = QDir(self.mDir + QDir.separator() + "corelocale")
     if dircorelan.exists():
         if QFileInfo(dircorelan.path() + QDir.separator() + language +
                      ".qm").exists():
             settings.setValue("translate", language)
             translator = QTranslator(self)
             translator.load(dircorelan.path() + QDir.separator() +
                             language)
             self.mApp.installTranslator(translator)
         else:
             language = language.split('_')[0]
             if len(language) == 2:
                 if QFileInfo(dircorelan.path() + QDir.separator() +
                              language + ".qm").exists():
                     settings.setValue("translate", language)
                     translator = QTranslator(self)
                     translator.load(dircorelan.path() + QDir.separator() +
                                     language)
                     self.mApp.installTranslator(translator)
예제 #6
0
파일: systemnet.py 프로젝트: numaelis/thesa
 def actionCacheOnCompleted(self):  #version 1.1 up thesamodule
     boolAction = False
     if self.actionCache_ == "deleteOnCompleted":
         sysdir = QDir(self.mDir + QDir.separator() + _dirSystem)
         DIR_QML_SYS = sysdir.path()
         for the_file in os.listdir(DIR_QML_SYS):
             file_path = os.path.join(DIR_QML_SYS, the_file)
             try:
                 if os.path.isfile(file_path):
                     if ".qml" in file_path:
                         os.unlink(file_path)
                 elif os.path.isdir(file_path):
                     shutil.rmtree(file_path)
                 boolAction = True
             except Exception as e:
                 boolAction = False
                 print(e)
     else:
         boolAction = True
     return boolAction
예제 #7
0
파일: systemnet.py 프로젝트: numaelis/thesa
    def rechargeNet(self, preferences, username):
        #version 1.1 up thesamodule
        data = self.m_qjsonnetwork.callDirect(
            "version internal", "model.thesamodule.config.search_read",
            [[], 0, 1, [], ["internal_version"], preferences])
        if not data["data"] == "error":
            self.internal_version = data["data"]["result"][0][
                "internal_version"]
            if float(self.internal_version) > 1.0:
                data = self.m_qjsonnetwork.callDirect(
                    "cachedel", "model.thesamodule.config.search_read",
                    [[], 0, 1, [], ["deletecache"], preferences])
                if not data["data"] == "error":
                    if data["data"]["result"][0]["deletecache"] == True:
                        self.actionCache_ = "deleteOnCompleted"
                    else:
                        self.actionCache_ = "notDelete"
        sysdir = QDir(self.mDir + QDir.separator() + _dirSystem)
        DIR_QML_SYS = sysdir.path()
        DIR_QML_SYS_LOST = DIR_QML_SYS + QDir.separator() + "lost"
        sysdirlost = QDir(DIR_QML_SYS_LOST)
        #revisar folder systemnet
        if sysdir.exists() == False:
            s = QDir(self.mDir)
            s.mkdir(_dirSystem)
        #revisar folder systemnet lost
        if sysdirlost.exists() == False:
            sl = QDir(DIR_QML_SYS)
            sl.mkdir("lost")
        #find all files en folder net
        listSysFiles = os.listdir(DIR_QML_SYS)
        if "lost" in listSysFiles:
            listSysFiles.remove("lost")
        #
        data = {}
        data["data"] = "error"
        if float(self.internal_version) > 1.1:
            data = self.m_qjsonnetwork.callDirect(
                "findforuser", "model.thesamodule.usersfolder.search_read", [[
                    "AND", ["users.user.name", "=", username],
                    ["activefolder", "=", True]
                ], 0, 1, [], ["qmlfiles"], preferences])
            if not data["data"] == "error":
                result = data["data"]["result"]
                if len(result) > 0:
                    idfiles = result[0]["qmlfiles"]
                    data = self.m_qjsonnetwork.callDirect(
                        "rechargeNetStep1",
                        "model.thesamodule.thesamodule.read",
                        [idfiles, [
                            "checksum",
                            "filename",
                        ], preferences])
                    if len(idfiles) == 0:
                        self.m_qjsonnetwork.signalResponse.emit(
                            "systemnet", 15, {"noqmlfiles": ""})
                else:  #buscar default
                    data = self.m_qjsonnetwork.callDirect(
                        "findforuser",
                        "model.thesamodule.usersfolder.search_read", [[
                            "AND", ["type", "=", "default"],
                            ["activefolder", "=", True]
                        ], 0, 1, [], ["qmlfiles"], preferences])
                    if not data["data"] == "error":
                        result = data["data"]["result"]
                        if len(result) > 0:
                            idfiles = result[0]["qmlfiles"]
                            data = self.m_qjsonnetwork.callDirect(
                                "rechargeNetStep1",
                                "model.thesamodule.thesamodule.read", [
                                    idfiles, [
                                        "checksum",
                                        "filename",
                                    ], preferences
                                ])
                            if len(idfiles) == 0:
                                self.m_qjsonnetwork.signalResponse.emit(
                                    "systemnet", 15, {"noqmlfiles": ""})
                        else:
                            self.m_qjsonnetwork.signalResponse.emit(
                                "systemnet", 12, {"noqmlfiles": ""})
                    else:
                        self.m_qjsonnetwork.signalResponse.emit(
                            "systemnet", 13, {"error": ""})
            else:
                self.m_qjsonnetwork.signalResponse.emit(
                    "systemnet", 13, {"error": ""})

        else:
            data = self.m_qjsonnetwork.callDirect(
                "rechargeNetStep1",
                "model.thesamodule.thesamodule.search_read",
                [[], 0, 1000, [], ["checksum", "filename"], preferences])
        if not data["data"] == "error":
            resultnet = data["data"]["result"]
            mapnet = {}
            mapids = {}
            listNetFiles = []
            for file in resultnet:
                mapnet[file["filename"]] = file["checksum"]
                mapids[file["filename"]] = file["id"]
                listNetFiles.append(file["filename"])
            #buscar faltantes en system y los updates
            #buscar los que ya no deben estar
            mapsysnet = {}
            listToUpdate = set()  #new or update
            listToErase = []
            for file in listSysFiles:
                try:
                    with open(DIR_QML_SYS + QDir.separator() + file,
                              "rb") as binary_file:
                        data = binary_file.read()
                        chek = hashlib.md5(data).hexdigest()
                        mapsysnet[file] = chek
                except:
                    listToUpdate.add(file)

            for file in listNetFiles:
                if file in listSysFiles:
                    if mapnet[file] != mapsysnet[file]:
                        listToUpdate.add(file)  # update
                else:
                    listToUpdate.add(file)  # new
            for file in listSysFiles:
                if not file in listNetFiles:
                    listToErase.append(file)  # erase

            listToUpdate = list(listToUpdate)
            ids = []
            for file in listToUpdate:
                ids.append(mapids[file])

            data = self.m_qjsonnetwork.callDirect(
                "rechargeNetStep2", "model.thesamodule.thesamodule.read",
                [ids, [
                    "filebinary",
                    "filename",
                ], preferences])
            errors = []
            if not data["data"] == "error":
                resultnet = data["data"]["result"]
                for file in resultnet:
                    filename = DIR_QML_SYS + QDir.separator(
                    ) + file["filename"]
                    qfile = QFile(filename)
                    if qfile.open(QIODevice.WriteOnly) == False:
                        errors.append(filename)
                        print("error", filename, qfile.errorString())
                    else:
                        print("update", file["filename"])
                        bafile = QByteArray.fromBase64(
                            file["filebinary"]["base64"].encode())
                        qfile.write(bafile)
                        qfile.close()
            if len(errors) > 0:
                self.m_qjsonnetwork.signalResponse.emit(
                    "systemnet", 33, {"error": errors})
                return False

            #erase
            for file in listToErase:
                print("moviendo", file)
                shutil.move(DIR_QML_SYS + QDir.separator() + file,
                            DIR_QML_SYS_LOST + QDir.separator() + file)
            return True
        else:
            #erase all files, no conexion con thesa module
            for file in listSysFiles:
                print("moviendo", file)
                shutil.move(DIR_QML_SYS + QDir.separator() + file,
                            DIR_QML_SYS_LOST + QDir.separator() + file)
            self.m_qjsonnetwork.signalResponse.emit("systemnet", 34,
                                                    {"error": ""})
            return False
예제 #8
0
class Loader(QWidget):
    def __init__(self, parent=None):
        super(Loader, self).__init__(parent=parent)
        self.ui = Ui_Loader()
        self.ui.setupUi(self)
        self.dir = QDir(QDir.currentPath() + '/programs/')
        self.dir.setFilter(QDir.Files or QDir.NoDotAndDotDot)
        self.fs_watcher = QFileSystemWatcher(self.dir.path())
        self.fs_watcher.addPath(self.dir.path())
        self.fs_watcher.directoryChanged.connect(self.update_program_list)
        self.send_status = QProgressDialog
        self.sender = Sender
        self.serialpropertiesvalues = \
            {
                'baudrate': Serial.BAUDRATES,
                'parity': Serial.PARITIES,
                'databits': Serial.BYTESIZES,
                'stopbits': Serial.STOPBITS,
                'flowcontrol': ['NoControl', 'SoftwareControl', 'HardwareControl']
            }

        self.update_program_list()
        self.update_serial_port_list()
        # self.set_serial_port_options()

        self.ui.updateProgramListButton.clicked.connect(self.refresh)
        self.ui.programListWidget.itemSelectionChanged.connect(
            self.selection_changed)
        self.ui.sendButton.clicked.connect(self.send_program)
        self.ui.serialPortChooser.currentTextChanged.connect(
            self.selection_changed)
        self.ui.serialPortChooser.currentTextChanged.connect(save_port)
        # self.ui.baudRateInput.textChanged.connect(save_baud)
        # self.ui.parityChooser.currentTextChanged.connect(save_parity)
        # self.ui.dataBitsChooser.currentTextChanged.connect(save_databits)
        # self.ui.stopBitsChooser.currentTextChanged.connect(save_stopbits)
        # self.ui.flowControlChooser.currentTextChanged.connect(save_flowcontrol)
        self.thread_pool = QThreadPool()

    def set_serial_port_options(self):
        for key in parities.keys():
            self.ui.parityChooser.addItem(key)
        for key in bytesize.keys():
            self.ui.dataBitsChooser.addItem(key)
        for key in stopbits.keys():
            self.ui.stopBitsChooser.addItem(key)
        self.ui.flowControlChooser.addItems(flowcontrol)
        if globalSettings.contains('serialport/port'):
            self.selectpreviousvalues()
        else:
            self.saveconfig()

    def selectpreviousvalues(self):
        self.ui.serialPortChooser.setCurrentText(
            globalSettings.value('serialport/port'))
        self.ui.baudRateInput.setText(
            globalSettings.value('serialport/baudrate'))
        self.ui.parityChooser.setCurrentText(
            globalSettings.value('serialport/parity'))
        self.ui.dataBitsChooser.setCurrentText(
            globalSettings.value('serialport/databits'))
        self.ui.stopBitsChooser.setCurrentText(
            globalSettings.value('serialport/stopbits'))
        self.ui.flowControlChooser.setCurrentText(
            globalSettings.value('serialport/flowcontrol'))

    def saveconfig(self):
        save_port(self.ui.serialPortChooser.currentText())
        save_baud(self.ui.baudRateInput.text())
        save_parity(self.ui.parityChooser.currentText())
        save_databits(self.ui.dataBitsChooser.currentText())
        save_stopbits(self.ui.stopBitsChooser.currentText())
        save_flowcontrol(self.ui.flowControlChooser.currentText())

    def update_serial_port_list(self):
        self.ui.serialPortChooser.clear()
        for port in list_ports.comports():
            self.ui.serialPortChooser.addItem(port.device)

    def update_program_list(self):
        self.ui.programListWidget.clear()
        self.dir.refresh()
        self.ui.programListWidget.addItems(self.dir.entryList())
        self.ui.programListWidget.clearSelection()

    def selection_changed(self):
        if self.ui.serialPortChooser.currentText() is not None \
                and self.ui.programListWidget.currentItem() is not None:
            self.ui.sendButton.setEnabled(True)
        else:
            self.ui.sendButton.setDisabled(True)

    def refresh(self):
        self.update_program_list()
        self.update_serial_port_list()

    def send_program(self):
        selections = self.ui.programListWidget.selectedItems()
        for selection in selections:
            filename = selection.text()
            filepath = self.dir.path() + '/' + filename
            port_chosen = self.ui.serialPortChooser.currentText()
            confirm = ConfirmSend(self)
            confirm.ui.dialogLabel.setText(f'Send program \'{filename}\'?')
            confirm.exec()
            if confirm.result() == QDialog.Accepted:
                self.send_status = QProgressDialog(self)
                self.sender = Sender(
                    port_chosen, filepath,
                    globalSettings.value('serialport/baudrate'),
                    globalSettings.value('serialport/databits'),
                    globalSettings.value('serialport/parity'),
                    globalSettings.value('serialport/stopbits'),
                    globalSettings.value('serialport/flowcontrol'), self)
                self.send_status.setMaximum(self.sender.file.size())
                self.send_status.canceled.connect(self.sender.cancel)
                self.sender.signals.update_status.connect(
                    self.send_status.setValue)
                self.thread_pool.start(self.sender)
                self.send_status.exec_()
                self.send_status.deleteLater()