Last active
March 27, 2017 15:24
-
-
Save takahub1/2653d3a938a4a1af6360f828109abcfa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from PyQt5.QtWidgets import (QApplication, QWidget, | |
QGridLayout, QVBoxLayout, QHBoxLayout, | |
QLabel, QLineEdit, QPushButton) | |
import socket | |
import datetime #for datetime | |
import os #for directory | |
import time #for sleep | |
import shutil #for fail copy | |
class MainWindow(QWidget): | |
def __init__(self, parent=None): | |
super(MainWindow, self).__init__(parent) | |
self.ipLine = QLineEdit() | |
self.portLine = QLineEdit() | |
self.sharedLine = QLineEdit() | |
# self.outputLine.setReadOnly(True) | |
self.calcButton = QPushButton("&Connect") | |
self.calcButton.clicked.connect(self.calc) | |
lineLayout = QGridLayout() | |
lineLayout.addWidget(QLabel("server ip address"), 0, 0) | |
lineLayout.addWidget(self.ipLine, 0, 1) | |
lineLayout.addWidget(QLabel("server port"), 1, 0) | |
lineLayout.addWidget(self.portLine, 1, 1) | |
lineLayout.addWidget(QLabel("shared directory"), 2, 0) | |
lineLayout.addWidget(self.sharedLine, 2, 1) | |
buttonLayout = QVBoxLayout() | |
buttonLayout.addWidget(self.calcButton) | |
mainLayout = QHBoxLayout() | |
mainLayout.addLayout(lineLayout) | |
mainLayout.addLayout(buttonLayout) | |
self.setLayout(mainLayout) | |
self.setWindowTitle("handRoboLogger") | |
# if push button | |
def calc(self): | |
print (self.ipLine.text()) | |
print (self.portLine.text()) | |
print (self.sharedLine.text()) | |
print ("program start") | |
soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
while True: | |
try: | |
soc.connect((self.ipLine.text(), int(self.portLine.text()))) | |
# soc.connect(("192.168.0.30", 10003)) | |
print ("soccet connected") | |
break | |
except: | |
print ("soc connect failed") | |
time.sleep(1) | |
loopCount=0 | |
while(1): | |
data_recv = soc.recv(1024) | |
dataFirst = data_recv[:1] #data_recv extract first character | |
print ("Server>",dataFirst) # サーバー側の書き込みを表示 | |
if dataFirst == "1": #if updated image | |
try: | |
f.close() | |
except: | |
pass #do nothing | |
finally: | |
print ("make directory") | |
today = datetime.datetime.today() | |
shutil.copytree(self.sharedLine.text(),"log/"+today.strftime("%y-%m-%d_%H:%M:%S")) | |
f = open("log/"+today.strftime("%y-%m-%d_%H:%M:%S")+"/data.txt",'w') | |
loopCount += 1 | |
print ("loopCount:%d" % loopCount) | |
try: | |
f.write(dataFirst+"\n") | |
except: | |
pass #do nothing | |
if __name__ == '__main__': | |
import sys | |
app = QApplication(sys.argv) | |
main_window = MainWindow() | |
main_window.show() | |
sys.exit(app.exec_()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment