def SlotDealWithQuerryData(self,where,data):
     """处理来自数据库查询的数据"""
     if where.startswith('cs'):#处理数据发出的用于绘图的数据
         try:
             if data!=():
                 data = np.array(data)[:, 0]
                 self.ZaiRuWindow.addLines((0,),(tuple(data),),('r',))
             else:
                 self.SlotMessageBox('错误!','此表无数据!')
         except:
             pass
         print '来自数据库的数据'
     elif where.startswith('ex*'):#处理数据发出的用于导出的数据
         where=where.lstrip('ex*')#去除信息前缀
         oldfilepath,newfiledir=where.split('*')#来自哪个数据表,数据应该存储的位置
         infor = FiveFileParser.readTable(oldfilepath)
         infor=infor[infor.keys()[0]]['cellContent']#获取文件中的表
         temppath=os.path.split(oldfilepath)[1]#获取文件名
         temppath=temppath.replace('.d','.txt')#替换文件后缀名
         with open(os.path.join(newfiledir,temppath),'w') as f:#创建数据文件
             pass
         #首先存储参数表
         FiveFileParser.insertTable(infor,'所使用参数',os.path.join(newfiledir,temppath),-1)
         #创建线程来存数数据
         fd=threading.Thread(target=saveData2File,args=(os.path.join(newfiledir,temppath),data))
         fd.start()
         self.SlotMessageBox('提示','数据导出成功!')
 def SlotPushbutton_Save_CGCS(self):
     """保存按钮信号槽,用于保存修改的数据"""
     if self.currentfilepath is not None and self.currentfilepath['type']==0:
         FiveFileParser.updataTable(dict(self.tableinfor_2Save),'MUBAN',
                                    self.currentfilepath['path'])
         QtWidgets.QMessageBox.information(self, '提示', '更改成功:'
                                     '{}'.format(os.path.split(self.currentfilepath['path'])[1]),
                                     QtWidgets.QMessageBox.Yes)
 def SlotPushbutton_Save_TJCS(self):
     """保存参数处保存按钮"""
     file=self.tableinfor[self.tableinfor.keys()[0]]#文件名
     path=os.path.join(self.ParasDir,file)
     while os.path.exists("".join([path,'.txt'])):
         path="".join([path,'_backup'])
     temp = copy.deepcopy(self.tableinfor)
     temp.popitem(False)#
     temp=dict(temp)
     FiveFileParser.createTable("".join([path,'.txt']))
     FiveFileParser.insertTable(temp,'MUBAN',"".join([path,'.txt']),0)
     QtWidgets.QMessageBox.information(self,'提示','保存为:\n'
             '{}'.format("".join([path,'.txt'])),QtWidgets.QMessageBox.Yes)
 def SlotPushbutton_UseThisPara(self):
     """设置使用该参数列表"""
     if self.tableinfor_2Save!=self.tableinfor_2:#保存修改后的参数
         if self.currentfilepath is not None and self.currentfilepath['type'] == 0:
             FiveFileParser.updataTable(dict(self.tableinfor_2Save), 'MUBAN',
                                        self.currentfilepath['path'])
     self.Signal_UpdataParas.emit(dict(self.tableinfor_2Save))
     #创建数据表(包含参数,用一个data来存数据在数据库中的位置)
     #当前参数表对应的名字,不要后缀
     name="D"+os.path.split(self.currentfilepath['path'])[1].rstrip('.txt')+"时间"+time.strftime('%Y%m%d%M',time.localtime())
     #检测当前名字是否合适
     while os.path.exists("".join([os.path.join(self.AnotherSavingDir,name),'.d'])):
         name+='cp'
     #数据表路径
     path=os.path.join(self.AnotherSavingDir,''.join([name,'.d']))#数据表后缀变为‘.d’
     FiveFileParser.createTable(path)
     FiveFileParser.insertTable(dict(self.tableinfor_2Save), '参数',path,0)
     FiveFileParser.writeComments(path,'\nDataBaseDir*{}\nDataTable*{}'.format(self.AnotherSavingDir,name))
     QtWidgets.QMessageBox.information(self, '提示', '参数选择成功:'
                                       '数据表为:{}\n立即搜集数据'.format(name),
                                       QtWidgets.QMessageBox.Yes)
     self.Signal_SaveDirChanged_ForDB.emit(self.AnotherSavingDir,name)
     self.Signal_UseThisParaTable.emit(name)
     self.Siganl_ManagerWidget.emit('ShuJuBiao',''.join(name))
     self.log.info('Create DataTable:  {}.d'.format(name))
 def CreatTable_CGCS(self,tablepath,type=0):
     """修改参数界面的表格绘制函数"""
     self.tableinfor_2 = FiveFileParser.readTable(tablepath)
     self.UI.tableWidget.clear()
     if self.tableinfor_2  is not None:
         self.tableinfor_2=Dict(self.tableinfor_2[self.tableinfor_2.keys()[0]]['cellContent'])
         self.tableinfor_2Save = copy.deepcopy(self.tableinfor_2)#获取存储数据
         row,col=CalculateRowCol(self.tableinfor_2.keys())
         self.currentfilepath.setdefault('row',row)
         self.currentfilepath.setdefault('col',col)
         self.SetTableRowCol_CGCS(row,col)#更新表格的个数
         for i,data in enumerate(self.tableinfor_2.iteritems()):
             itemkey = QtWidgets.QTableWidgetItem()
             itemvalue=QtWidgets.QTableWidgetItem()
             if type==0:
                 itemkey.setBackground(QtGui.QBrush(QtGui.QColor(200, 184, 7)))
             else:
                 itemkey.setBackground(QtGui.QBrush(QtGui.QColor(188, 229, 255)))
             itemkey.setText(data[0])
             itemvalue.setText(data[1])
             itemkey.setFlags(QtCore.Qt.ItemIsEnabled)
             self.UI.tableWidget.setItem(i % self.currentfilepath['row'],
                             (i // self.currentfilepath['row']) * 2, itemkey)
             self.UI.tableWidget.setItem(i%self.currentfilepath['row'],(i // self.currentfilepath['row']) * 2+1,itemvalue)
     else:
         self.tableinfor_2=None
Exemple #6
0
 def slotNewPushOk(self):
     path = self.logintablePath
     if self.line_edit.text() != "":
         temp = self.regions[self.co_region.currentIndex()][1]
         temp = "".join([temp, ".", self.line_edit.text()])
         self.regions[self.co_region.currentIndex()][1] = temp
     # print self.regions[self.co_region.currentIndex()][1]
     self.activeComboxRegin()
     self.ui.LOGIN_region.setCurrentIndex(self.co_region.currentIndex())
     self.ui.LOGIN_gen.setCurrentIndex(
         len(self.regions[self.co_region.currentIndex()][1].strip().split(
             '.')) - 1)
     table = dict()
     for i in self.regions:
         table.setdefault(i[0], i[1])
     FiveFileParser.updataTable(table, "regions", path)
     del table
     self.New.accept()
 def SlotPushbutton_WatchData_CGCS(self):
     """查看数据"""
     if self.currentfilepath is  not None and self.currentfilepath['type']==1:
         self.UI.tabWidget.setCurrentIndex(3)
         infor=FiveFileParser.getcomments(self.currentfilepath['path'],('DataTable','DataBaseDir'))
         name=infor['DataTable'][0].rstrip('\n')
         path=infor['DataBaseDir'][0].rstrip('\n')
         self.Signal_QuerrySQL.emit('cs',
                                    path,' select PRESSURE  from {}  '.format(name))
         self.log.info('querry data :{},{}'.format(path,name))
Exemple #8
0
 def getRegions(self):
     path = self.logintablePath
     regioninfor = FiveFileParser.readTable(path)
     if regioninfor != None:
         for _, item in regioninfor.iteritems():
             regions = item['cellContent']
             for keys, values in regions.iteritems():
                 self.regions.append([keys, values])
             break
         self.ui.LOGIN_region.currentIndexChanged.connect(
             self.activeComboxGen)
         self.activeComboxRegin()
 def SlotPushbutton_DeleteTable_CGCS(self):
     """用与删除当前self.currentfilepath变量对应的表"""
     if self.currentfilepath is not None:
         if self.currentfilepath['type'] == 1:#如果是数据表就删除,而且数据库中对应的也删除
             infor = FiveFileParser.getcomments(self.currentfilepath['path'], ('DataTable', 'DataBaseDir'))
             name = infor['DataTable'][0].rstrip('\n')
             path = infor['DataBaseDir'][0].rstrip('\n')
             self.Signal_DelSQL.emit( path, ' DROP TABLE {} '.format(name))
         os.remove(self.currentfilepath['path'])
         QtWidgets.QMessageBox.information(self, '提示', '删除成功:'
                                            '{}'.format(os.path.split(self.currentfilepath['path'])[1]),
                                           QtWidgets.QMessageBox.Yes)
         self.log.info('delete file:  {}'.format(self.currentfilepath['path']))
         self.ClearTable_CGCS()
Exemple #10
0
    def SlotPushbutton_ExportData_CGCS(self):
        """导出数据"""
        if self.currentfilepath is  not None and self.currentfilepath['type']==1:
            # self.UI.tabWidget.setCurrentIndex(3)
            #创建文件夹
            basepath, exname = os.path.split(self.currentfilepath['path'])
            filename, suffix = os.path.splitext(exname)
            if not os.path.exists(os.path.join(self.AnotherSavingDir, filename)):#创建文件夹
                os.mkdir(os.path.join(self.AnotherSavingDir, filename))

            infor=FiveFileParser.getcomments(self.currentfilepath['path'],('DataTable','DataBaseDir'))
            name=infor['DataTable'][0].rstrip('\n')
            path=infor['DataBaseDir'][0].rstrip('\n')
            self.Signal_QuerrySQL.emit('ex*{}*{}'.format(self.currentfilepath['path'],os.path.join(self.AnotherSavingDir, filename)),
                                       path,' select PRESSURE , DISTANCE from {}  '.format(name))
            self.log.info('export data :{},{}'.format(path,name))

        pass
Exemple #11
0
 def CheckUsb(self):
     """检查USB"""
     path = self.FilesLists[0]
     usb = FiveFileParser.getcomments(path, ('usb', ))['usb']
     if usb != []:  #如果存在usb残留则删除记录
         FiveFileParser.removeComments(path, ['usb'])
     FiveFileParser.writeComments(path, ['usb*'])
     tempusb = 'None'  #暂存usb的路径
     usbPATH = '/media/pi'  #"/media/pi"#树莓派的Usb路径更改处
     if os.path.exists(usbPATH):
         if len(os.listdir(usbPATH)) != 0:
             for i in os.listdir(usbPATH):
                 if os.path.exists(os.path.join(usbPATH, i)):
                     tempusb = os.path.join(usbPATH, i)
                     self.usb = tempusb
                     break
     tempusb = self.Savepath if tempusb == 'None' else tempusb
     FiveFileParser.updateComments(path, {'usb': r'{}'.format(tempusb)})
Exemple #12
0
 def CreateTable_TJCS(self,table):
     """创建参数表"""
     temp= FiveFileParser.readTable(table)
     self.UI.table_tianjiacanshu.clear()
     if temp  is not None:
         temp=Dict(temp[temp.keys()[0]]['cellContent'])
         self.tableinfor = Dict()
         row, col = CalculateRowCol(temp.keys())
         self.parefile['row'], self.parefile['col']=row,col
         self.SetTableRowCol_TJCS(row,col)
         self.tableinfor.setdefault('存储为','MUBAN')
         for data in temp.iteritems():
             self.tableinfor.setdefault(data[0],data[1])
         for i,data in enumerate(self.tableinfor.iteritems()):
             item = QtWidgets.QTableWidgetItem()
             item.setText(data[0])
             item.setFlags(QtCore.Qt.ItemIsEnabled)
             self.UI.table_tianjiacanshu.setItem(i % self.parefile['row'], (i // self.parefile['row']) * 2, item)
     else:
         self.tableinfor=Dict()
         self.tableinfor.setdefault('存储为', 'MUBAN')
Exemple #13
0
 def CheckFiles(self):
     """检查文件是否存在"""
     try:
         for index, files in enumerate(self.FilesLists):
             files = os.path.normpath(files)
             if not os.path.exists(files):
                 with open(files, "w") as f:
                     self.log.info("create file:{}".format(files))
                     if index == 0:  #"setting.txt"
                         FiveFileParser.writeComments(
                             files, [r'saving*{}'.format(files)])
                     if index == 1:
                         table = {
                             "省份名": "工厂名",
                         }
                         FiveFileParser.insertTable(table, 'regions', files,
                                                    0)
                     if index == 2:
                         table = {
                             "参数表名": "0",
                             "电厂": "0",
                             '阀门型号': "0",
                             '整定压力': "0",
                             '弹簧刚度': "0",
                             '密封面内径': "0",
                             '密封面外径': "0",
                             '整调螺母方数': "0",
                         }
                         FiveFileParser.insertTable(table, 'MUBAN0', files,
                                                    0)
             else:
                 if index == 0:  #"setting.txt"
                     FiveFileParser.updateComments(
                         files, {'usb': r'{}'.format(self.Savepath)})
         return True
     except Exception as e:
         return False