Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Pyqt5_ site Administration _ stcd_windows

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

From PyQt5.QtWidgets import (QWidget,QTableWidget,QHBoxLayout,QVBoxLayout,QGridLayout,QGroupBox,QLineEdit,QLabel,QPushButton, QHeaderView,QTableWidgetItem,QMessageBox) import os,re# defines the site information window class stcd_window (QWidget): def _ _ init__ (self): super (). _ init__ () self.stcd_tablewidget = QTableWidget (0 3) self.stcd_stcd = QLineEdit () self.stcd_rtu = QLineEdit () self.stcd_name = QLineEdit () self.list_stcd = [] self.stcd_pik_path ='. / / DATA//STCDinfo.pik' self.stcd_txt_path ='. / / DATA// site information. Txt 'self.table_clicked_old =-1 # Line number self.initUI () def initUI (self): # initialize window component self.stcd_tablewidget.setHorizontalHeaderLabels (['site code') 'RTU coding' 'site name']) self.stcd_tablewidget.setEditTriggers (QTableWidget.NoEditTriggers) table_group = QGroupBox ('site') table_vbox = QVBoxLayout () table_vbox.addWidget (self.stcd_tablewidget) table_group.setLayout (table_vbox) stcd_group = QGroupBox ('site Information configuration') stcd_grid = QGridLayout () stcd_label = QLabel ('site code:') rtu_label = QLabel ('RTU code:') name_label = QLabel ('site name:') delete_button = QPushButton ('delete') input_button = QPushButton ('save') delete_button.clicked.connect (self.delete_stcd_info) input_button.clicked.connect (self.save_stcd_info) self.stcd_ tablewidget. CellClicked [int Int] .connect (self.cell_clicked) stcd_grid.addWidget (stcd_label, 0,0) stcd_grid.addWidget (self.stcd_stcd, 0,1) stcd_grid.addWidget (rtu_label, 1,0) stcd_grid.addWidget (self.stcd_rtu, 1,1) stcd_grid.addWidget (name_label, 2,0) stcd_grid.addWidget (self.stcd_name, 2 1) button_grid = QGridLayout () button_grid.addWidget (delete_button, 0,0) button_grid.addWidget (input_button, 0) 1) stcd_vbox = QVBoxLayout () stcd_vbox.addLayout (stcd_grid) stcd_vbox.addLayout (button_grid) stcd_group.setLayout (stcd_vbox) hbox = QHBoxLayout () hbox.addWidget (table_group) hbox.addWidget (stcd_group) self.setLayout (hbox) self.get_list_stcd () self.initTable () # initialize site information form def get_list_stcd (self): try: if not os.path.exists (self.stcd_txt_path): with open (self.stcd_txt_path) 'w') as stcd_txt_file: stcd_txt_file.write ('site code RTU site Site name\ n') return with open (self.stcd_txt_path 'r') as stcd_txt_file: stcd_txt_file.readline () self.list_stcd.clear () txt_line = stcd_txt_file.readline () while txt_line: txt_line = txt_line.strip ('\ n') txt_line = txt_line.replace (' X = re.findall (txt_line) if len (x) > 1: txt_line = txt_line.replace ('-','-') line = txt_line.strip () .split (' ', 2) if not line [0] .strip () ='': self.list_stcd.append ([line [0] .strip (), line [1] .strip () Line [2] .strip () txt_line = stcd_txt_file.readline () try: os.remove (self.stcd_txt_path) except Exception as error1: return with open (self.stcd_txt_path,'a') as stcd_txt_file: stcd_txt_file.write ('site Code RTU site; site name\ n') for line in self.list_stcd: stcd_txt_file.write (line [0] +';'+ line [1] +') '+ line [2] +'\ n') except Exception as error: return # initialization list def initTable (self): X = 0 for line in self.list_stcd: self.stcd_tablewidget.insertRow (x) self.stcd_tablewidget.setItem (x, 0, QTableWidgetItem (line [0])) self.stcd_tablewidget.setItem (x, 1 QTableWidgetItem (line [1]) self.stcd_tablewidget.setItem (x, 2, QTableWidgetItem (line [2])) x = x + 1 # form is selected def cell_clicked (self, x, y): if self.table_clicked_old = = x: return self.table_clicked_old = x self.stcd_stcd.setText (self.stcd_tablewidget.item (x) 0) .text () self.stcd_rtu.setText (self.stcd_tablewidget.item (x, 1) .text () self.stcd_name.setText (self.stcd_tablewidget.item (x) 2) .text () # Save button def save_stcd_info (self): if self.stcd_stcd.text (). Strip () =''or self.stcd_rtu.text (). Strip () =''or self.stcd_name.text (). Strip () ='': QMessageBox.warning (self,' Note', 'site Encoding, RTU Encoding, site name\ ncannot be empty.') Return x = 0 while x

< len(self.list_stcd): if self.stcd_stcd.text().strip() == self.list_stcd[x][0]: flag = 0 if self.stcd_rtu.text().strip() != self.list_stcd[x][1]: del self.list_stcd[x][1] self.list_stcd[x].insert(1,self.stcd_rtu.text().strip()) self.stcd_tablewidget.setItem(x,1,QTableWidgetItem(self.stcd_rtu.text().strip())) flag = 1 if self.stcd_name.text().strip() != self.list_stcd[x][2]: del self.list_stcd[x][2] self.list_stcd[x].insert(2, self.stcd_name.text().strip()) self.stcd_tablewidget.setItem(x, 2, QTableWidgetItem(self.stcd_name.text().strip())) flag = 2 if flag >

0: os.remove (self.stcd_txt_path) with open (self.stcd_txt_path,'a') as r_file: r_file.write ('site code; RTU site Site name: for line in self.list_stcd: r_file.write (line [0] +';'+ line [1] +') '+ line [2] +'\ n') r_file.flush () return x = x + 1 self.stcd_tablewidget.insertRow (len (self.list_stcd)) self.stcd_tablewidget.setItem (len (self.list_stcd), 0, QTableWidgetItem (self.stcd_stcd.text (). Strip ()) self.stcd_tablewidget.setItem (len (self.list_stcd)) 1, QTableWidgetItem (self.stcd_rtu.text (). Strip ()) self.stcd_tablewidget.setItem (len (self.list_stcd), 2, QTableWidgetItem (self.stcd_name.text (). Strip ()) self.list_stcd.append ([self.stcd_stcd.text (). Strip (), self.stcd_rtu.text (). Strip (), self.stcd_name.text (). Strip ()]) with open (self.stcd_txt_path 'a') as file: file.write (self.stcd_stcd.text (). Strip () +' '+ self.stcd_rtu.text () .strip () +';'+ self.stcd_name.text () .strip () +'\ n') self.table_clicked_old =-1 # delete button def delete_stcd_info (self): if self.table_clicked_old = =-1: QMessageBox.warning (self,' prompt', 'Please select the site to delete before deleting.') Return self.stcd_tablewidget.removeRow (self.table_clicked_old) del self.list_ STCD [self.table _ clicked_old] os.remove (self.stcd_txt_path) with open (self.stcd_txt_path,'a') as de_file: de_file.write ('site code; RTU site Site name: for line in self.list_stcd: de_file.write (line [0] +';'+ line [1] +') '+ line [2] +'\ n') de_file.flush () self.stcd_stcd.setText ('') self.stcd_rtu.setText ('') self.stcd_name.setText ('') self.table_clicked_old =-1

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 288

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report