def GetFile(message=None): """ Select file dialog. Returns path if one is selected. Otherwise it returns None. Availability: FontLab, Macintosh, PC """ path = None if MAC: if haveMacfs: fss, ok = macfs.PromptGetFile(message) if ok: path = fss.as_pathname() else: from robofab.interface.mac.getFileOrFolder import GetFile path = GetFile(message) elif PC: if inFontLab: if not message: message = '' path = fl.GetFileName(1, message, '', '') else: openFlags = win32con.OFN_FILEMUSTEXIST | win32con.OFN_EXPLORER mode_open = 1 myDialog = win32ui.CreateFileDialog(mode_open, None, None, openFlags) myDialog.SetOFNTitle(message) is_OK = myDialog.DoModal() if is_OK == 1: path = myDialog.GetPathName() else: _raisePlatformError('GetFile') return path
def openfile2(): openfile = win32ui.CreateFileDialog(0) openfile.SetOFNInitialDir('D:') openfile.DoModal() filename = openfile.GetPathName() name_entered2.insert(0, filename) baocunlujinglist.append(filename)
def select_path(currentPath): ''' 通过使用对话窗口选择文件确定目录 :return: 选择的路径名 ''' #设置起始路径,如果目标路径不存在,则选择当前路径 if os.path.isdir(currentPath): os.chdir(currentPath) else: print('目录不存在:', currentPath) currentPath = os.getcwd() print("当前目录:%s" % (currentPath)) dlg = win32ui.CreateFileDialog(1) # 1表示打开文件对话框 dlg.SetOFNInitialDir(currentPath) # 设置打开文件对话框中的初始显示目录 flag = dlg.DoModal() if flag == 2: print("未选择文件,程序退出") exit(1) filename = dlg.GetPathName() # 获取选择的文件名称 dlg.GetPathName() strSelectPath = os.path.dirname(filename) os.chdir(strSelectPath) currentPath = os.getcwd() print("工作目录:{}".format(currentPath)) return currentPath
def get_text(f='C:/Users'): import win32ui dlg = win32ui.CreateFileDialog(1) # 1表示打开文件对话框 dlg.SetOFNInitialDir('C:/Users') # 设置打开文件对话框中的初始显示目录 dlg.DoModal() f = dlg.GetPathName() # 获取选择的文件名称 return f
def LocatePythonFile( fileName, bBrowseIfDir = 1 ): " Given a file name, return a fully qualified file name, or None " # first look for the exact file as specified if not os.path.isfile(fileName): # Go looking! baseName = fileName for path in sys.path: fileName = os.path.join(path, baseName) if os.path.isdir(fileName): if bBrowseIfDir: d=win32ui.CreateFileDialog(1, "*.py", None, 0, "Python Files (*.py)|*.py|All files|*.*") d.SetOFNInitialDir(fileName) rc=d.DoModal() if rc==win32con.IDOK: fileName = d.GetPathName() break else: return None else: fileName = fileName + ".py" if os.path.isfile(fileName): break # Found it! else: # for not broken out of return None return win32ui.FullPath(fileName)
def Get_Filename(): import win32ui dlg= win32ui.CreateFileDialog(1)# 1表示打开文件对话框 dlg.SetOFNInitialDir('E:/')# 设置打开文件对话框中的初始显示目录 dlg.DoModal() filename= dlg.GetPathName() return filename try: print("已选择文件:",end='') #print(Get_Filename()) server=tcp_server() file=open("1.vsdx",'rb') while True: client_s,client_Info = server.accept() server.send("1.vsdx".encode("utf-8")) recvData = client_s.recv(buffsize) if((recvData.decode("utf-8"))=="start"): for temp_content in file.read(1024): content = file.read(1024) print("send: "+str(content)) server.send(str(content).encode("utf-8")) if((recvData.decode("utf-8"))=="bye"): client.close() server.close() print("INFO---> %s -- %s"%(client_Info,recvData.decode("utf-8"))) exit() except Exception as e: logging.error(e) print(e)
def render(self): w, h = self.imageFocus.get_size() x, y = self.position if self.isPressed(): screen.blit(self.imageFocus,(x-w/2,y-h/2)) elif self.isOver(): screen.blit(self.imageHover,(x-w/2,y-h/2)) else: screen.blit(self.imageNormal,(x-w/2,y-h/2)) if self.isPressed(): dlg= win32ui.CreateFileDialog(1)# 1表示打开文件对话框 dlg.SetOFNInitialDir('C:/')# 设置打开文件对话框中的初始显示目录 dlg.DoModal() filename= dlg.GetPathName()# 获取选择的文件名称 global midiFileName#存储midi文件名称 print(filename) midiFileName=filename if midiFileName: #midiFile=wave.open(filename,"rb")#获取midi文件 #打开的midi文件 print("midifilename") print(filename)
def file_path(info_path=None): # info_path = None common.deadline() # 创建文件获取路径 common.mkdir("_tmp") common.del_dir(r"_tmp\tmp_text.txt") print("读取配置信息...") # 1表示打开文件对话框 with open(r'_tmp\filepath.txt', 'w') as f: # print("写入") f.write('Hello, world!') # 1表示打开文件对话框 file = path.abspath(r'_tmp\filepath.txt') # print(file) files = file.replace(r'filepath.txt', "") files_s = file.replace(r'_tmp\filepath.txt', "") # 注册码校准 common.check_info() # print(files) # print(files_s) print("导入文件...请选择需要导入的文件") if info_path is None: dlg = win32ui.CreateFileDialog(1) dlg.SetOFNInitialDir(files_s) # 设置打开文件对话框中的初始显示目录 dlg.DoModal() filename = dlg.GetPathName() # 获取选择的文件路径 else: filename = files_s + info_path # print(filename) # 读取创建一个新的,并写入保存,关闭 with open(r'_tmp\filepath.txt', 'w') as f: # print('正在写入') f.write(filename) print([filename, files_s, files]) return [filename, files_s, files]
def open_character(self): #name = self.nameInput.get() or 'world' #messagebox.showinfo('Message', 'Hello, %s' % name) #messagebox.showinfo('Message','Hello,world') dlg = win32ui.CreateFileDialog(1) # 1表示打开文件对话框 #dlg.SetOFNInitialDir('D:\Project\python\ssss') # 设置打开文件对话框中的初始显示目录 dlg.DoModal() self.character_path = dlg.GetPathName() # 获取选择的文件名称 #print(character_path) #print(character_path[-3:]) # 判定最后三个字符是不是txt if self.character_path[-3:] == "txt": #print(self.character_path) ytm = tkinter.Tk() # 创建Tk对象 ytm.title("提示") # 设置窗口标题 # 布局窗口大小 width = 300 height = 200 screenwidth = ytm.winfo_screenwidth() screenheight = ytm.winfo_screenheight() alignstr = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2) ytm.geometry(alignstr) text = Text(ytm, width=300, height=50) text.pack() text.insert(INSERT, self.character_path + "打开成功") # l1 = tkinter.Label(ytm, text=self.character_path+"打开成功") # 标签 # l1.pack() # 指定包管理器放置组件 ytm.mainloop() # 进入主循环 else: self.open_character()
def _select_file(self, title, directory, filename, patterns, extension, save, multi): import win32ui import win32con flags = win32con.OFN_HIDEREADONLY if save: flags |= win32con.OFN_OVERWRITEPROMPT mode = 0 else: mode = 1 if multi: flags |= win32con.OFN_ALLOWMULTISELECT # This hack with finding non-specified windows is used so that # we get some parent window for CreateFileDialog. # Without this parent windows the method DoModal doesn't show # the dialog window on top... parent = win32ui.FindWindow(None, None) dialog = win32ui.CreateFileDialog(mode, extension, "%s" % filename or '*.*', flags, '|'.join(["%s|%s" % (self._pattern_label(label, pat), ';'.join(pat)) for label, pat in patterns]) + '||', parent) if directory: dialog.SetOFNInitialDir(directory) result = dialog.DoModal() if result != 1: return None if multi: return dialog.GetPathNames() else: return dialog.GetPathName()
def chooseImg(self): """打开文件对话框选择图片""" dlg = win32ui.CreateFileDialog(1) # 1表示打开文件对话框 dlg.SetOFNInitialDir("C:/") # 设置打开文件对话框中的初始显示目录 dlg.DoModal() filename = dlg.GetPathName() # 获取选择的文件名称 return filename
def main(): parser = argparse.ArgumentParser() parser.add_argument("viz_config") parser.add_argument("meta_path") args = parser.parse_args() print(args.viz_config) print(args.meta_path) dialog = win32ui.CreateFileDialog( 0, ".csv", None, win32con.OFN_HIDEREADONLY | win32con.OFN_OVERWRITEPROMPT, "CSV Files (*.csv)|*.csv|All Files (*.*)|*.*||") dialog.SetOFNInitialDir(os.getcwd()) result = dialog.DoModal() print(result) if result == win32con.IDOK: print("OK clicked") print("Filename:", dialog.GetFileName()) print("File path:", dialog.GetPathName()) config_file_path = args.viz_config destination_path = dialog.GetPathName() with open(config_file_path, "r") as viz_config_file: viz_config = json.load(viz_config_file) dataset_basedir = os.path.dirname(config_file_path) raw_data_csv_path = os.path.join(dataset_basedir, viz_config["raw_data"]) shutil.copyfile(raw_data_csv_path, destination_path)
def add(): # 录取人脸特征 cap = cv2.VideoCapture(0) # 创建内置摄像头变量 while cap.isOpened(): # 如果摄像头打开 try: ret, img = cap.read() if ret == True: cv2.imshow("Image", img) k = cv2.waitKey(100) # 每0.1秒读一次键盘 if k == ord("z") or k == ord("Z"): # 如果输入z imgSave = img dlog = win32ui.CreateFileDialog(0) dlog.DoModal() filename = dlog.GetPathName().split("\\")[-1] if '.' not in filename: filename = filename + '.jpg' cv2.imwrite('photos/' + filename, imgSave) cap.release() imgpath = 'photos/' + filename image = cv2.imread(imgpath) f = fr.face_encodings(image, known_face_locations=None) with open('xuehao.txt', 'r') as fp: lines = len(fp.readlines()) fp.close() ft = open("图片库/特征库/" + str(lines + 1) + ".txt", "w") ft.write(str(list(f[0]))) ft.close() fc = open("xuehao.txt", "a+") mz = input("请输入你的名字\n") fc.write(str(lines + 1) + " " + mz + "\n") fc.close() except: print("错误") continue
def PutFile(message=None, fileName=None): """ Save file dialog. Returns path if one is entered. Otherwise it returns None. Availability: FontLab, Macintosh, PC """ path = None if MAC: if haveMacfs: fss, ok = macfs.StandardPutFile(message, fileName) if ok: path = fss.as_pathname() else: import EasyDialogs path = EasyDialogs.AskFileForSave(message, savedFileName=fileName) elif PC: if inFontLab: if not message: message = '' if not fileName: fileName = '' path = fl.GetFileName(0, message, fileName, '') else: openFlags = win32con.OFN_OVERWRITEPROMPT | win32con.OFN_EXPLORER mode_save = 0 myDialog = win32ui.CreateFileDialog(mode_save, None, fileName, openFlags) myDialog.SetOFNTitle(message) is_OK = myDialog.DoModal() if is_OK == 1: path = myDialog.GetPathName() else: _raisePlatformError('GetFile') return path
def save(self): dlg = win32ui.CreateFileDialog(0) dlg.SetOFNInitialDir("C:") flag = dlg.DoModal() if 1 == flag: file_path = dlg.GetPathName() + '.txt' with open(file_path, 'a') as f: f.write(self.display.get(1.0, END))
def watch(): dlg = win32ui.CreateFileDialog(1) dlg.SetOFNInitialDir('Desktop') dlg.DoModal() filename = dlg.GetPathName() fp = open(filename, 'r') content = fp.read() text.insert(1.0, content)
def OpenDialog(fileType="", extension=""): #print("For testing, this will only display PDF Files!") o = win32ui.CreateFileDialog( 1, fileType, None, 0, fileType + " Files (*" + extension + ")|*" + extension + "|All Files (*.*)|*.*|") o.DoModal() #print (self.o.GetPathName()) return o.GetPathName()
def chooseout(self): dlg = win32ui.CreateFileDialog(1) # 1表示打开文件对话框 dlg.SetOFNInitialDir('C:') # 设置打开文件对话框中的初始显示目录 dlg.DoModal() filename = dlg.GetPathName() # 获取选择的文件名称 self.fo = filename self.lineEdit_2.setText( filename) # 将获取的文件名称写入名为“lineEdit_InputId_AI”可编辑文本框中
def Win_Save_File(): # 保存文件时,文件后缀需要另处理 print("Save File\n") dlg = win32ui.CreateFileDialog(0, None, None, API_flag, file_type) # 指定为保存文件窗口 dlg.SetOFNInitialDir('C:') # 默认打开的位置 dlg.DoModal() path = dlg.GetPathName() # 获取打开的路径 return path
def file_open(self,mode): dlg = win32ui.CreateFileDialog(1) if(mode == "test"): dlg.SetOFNInitialDir(self.test_path) else: dlg.SetOFNInitialDir(self.logs_path) dlg.DoModal() self.logfile = dlg.GetPathName()
def OnCmdSave(self, cmd, code): flags = win32con.OFN_OVERWRITEPROMPT dlg = win32ui.CreateFileDialog(0, None, None, flags, "Text Files (*.txt)|*.txt||", self) dlg.SetOFNTitle("Save Results As") if dlg.DoModal() == win32con.IDOK: pn = dlg.GetPathName() self._obj_.SaveFile(pn) return 0
def browse_local_file(self): dlg = win32ui.CreateFileDialog(0, None, None, 0, "Html File(*.html)|*.*||") dlg.DoModal() cata_raw = dlg.GetPathName() cata = unicode(cata_raw, 'gbk', 'ignore') self.LocalFileAddressEdit.setText(cata)
def taskupdate_button(self): # 更新任务总表 dlg = win32ui.CreateFileDialog(1) # 1表示打开文件对话框 dlg.SetOFNInitialDir(r'E:\01_MProject\MTGM') # 设置打开文件对话框中的初始显示目录 dlg.DoModal() path = dlg.GetPathName() # 和数据库建立连接 if path != "": # conn = pymysql.connect('localhost', 'root', 'mysql', 'MT_TASK', charset='utf8') conn = self.database() # 创建游标链接 cur = conn.cursor() cur.execute("DROP TABLE IF EXISTS VW331") sql = """CREATE TABLE IF NOT EXISTS VW331( part_name VARCHAR(100), part_num_1 CHAR(50), sent_time_1 CHAR(50), get_time_1 CHAR(50) , part_num_2 CHAR(50), sent_time_2 CHAR(50), get_time_2 CHAR(50), part_num_3 CHAR(50), sent_time_3 CHAR(50), get_time_3 CHAR(50), part_num_4 CHAR(50), sent_time_4 CHAR(50), get_time_4 CHAR(50), part_num_5 CHAR(50), sent_time_5 CHAR(50), get_time_5 CHAR(50), part_num_6 CHAR(50), sent_time_6 CHAR(50), get_time_6 CHAR(50), part_num_7 CHAR(50), sent_time_7 CHAR(50), get_time_7 CHAR(50) )ENGINE=InnoDB DEFAULT CHARSET=utf8 """ # try: # 执行sql语句 cur.execute(sql) # 提交到数据库执行 conn.commit() except: # Rollback in case there is any error conn.rollback() # # # 关闭数据库连接 conn.close() importExcelToMysql(path) # 将任务按照星期进行分布 todaytask = Showtadaytask() todaytask.create_today_db_table() todaytask.data_into_taday_task() else: return
def exposed_open_selected_file(self, template=None, encrypt=None): """Return a read-only 'file' like object of a user selected file. The file is selected by the user using a GUI dialog. If the user cancels the dialog, 'None' is returned. Arguments: template -- a string defining the required file name pattern, or 'None' encrypt -- list of encryption keys to use to encrypt the file; if the list is empty then let the user select the keys; if 'None' then don't encrypt the file """ assert template is None or isinstance(template, basestring), template if self._pytis_on_windows(): import win32ui import win32con extension = None if template: file_filter = (u"Soubory požadovaného typu (%s)|%s|Všechny soubory (*.*)|*.*||" % (template, template,)) filename = template if template.find('.') != -1: extension = template.split('.')[-1] else: file_filter = u"Všechny soubory (*.*)|*.*||" filename = "*.*" parent = win32ui.FindWindow(None, None) flags = win32con.OFN_HIDEREADONLY | win32con.OFN_OVERWRITEPROMPT dialog = win32ui.CreateFileDialog(1, extension, "%s" % filename, flags, file_filter, parent) result = dialog.DoModal() if result != 1: return None filename = unicode(dialog.GetPathName(), sys.getfilesystemencoding()) else: filename = self._pytis_file_dialog(template=template) if filename is None: return None if encrypt is not None: gpg = self._gpg() keys = self._select_encryption_keys(gpg, encrypt) class Wrapper(object): def __init__(self, filename): f = open(filename, 'rb') if encrypt is not None: s = gpg.encrypt_file(f, keys) f = cStringIO.StringIO(str(s)) self._f = f self._filename = filename def exposed_read(self): return self._f.read() def exposed_close(self): self._f.close() def exposed_name(self): return self._filename return Wrapper(filename)
def exposed_make_selected_file(self, directory=None, filename=None, template=None, encoding=None, mode='wb', decrypt=False): """Return a write-only 'file' like object of a user selected file. The file is selected by the user using a GUI dialog. If the user cancels the dialog, 'None' is returned. Arguments: directory -- initial directory for the dialog filename -- default filename or None template -- a string defining the required file name pattern, or 'None' encoding -- output encoding, string or None mode -- default mode for opening the file decrypt -- if true then decrypt the file contents """ assert template is None or isinstance(template, basestring), template if self._pytis_on_windows(): import win32ui import win32con file_filter = u"Všechny soubory (*.*)|*.*||" extension = None if filename: name, ext = os.path.splitext(filename) if ext: template = "*" + ext file_filter = (u"Soubory požadovaného typu (%s)|%s|%s" % (template, template, file_filter)) extension = ext[1:] else: filename = "*.*" if template: file_filter = (u"Soubory požadovaného typu (%s)|%s|%s" % (template, template, file_filter)) # This hack with finding non-specified windows is used so that # we get some parent window for CreateFileDialog. # Without this parent windows the method DoModal doesn't show # the dialog window on top... parent = win32ui.FindWindow(None, None) flags = win32con.OFN_HIDEREADONLY | win32con.OFN_OVERWRITEPROMPT dialog = win32ui.CreateFileDialog(0, extension, "%s" % filename, flags, file_filter, parent) if directory: dialog.SetOFNInitialDir(directory) result = dialog.DoModal() if result != 1: return None filename = dialog.GetPathName() if filename is None: return None filename = unicode(filename, sys.getfilesystemencoding()) else: filename = self._pytis_file_dialog(directory=directory, filename=filename, template=template, save=True) if filename is None: return None return self._open_file(filename, encoding, mode, decrypt=decrypt)
def fileaddress(): #open chosen windows try: dlg = win32ui.CreateFileDialog(1, '', 'test.xlsx') dlg.DoModal() filename = dlg.GetPathName() except Exception as e: print(str(e)) filename = fileaddress() return filename
def openfile_cargolist(self): dlg=win32ui.CreateFileDialog(1) dlg.SetOFNInitialDir(os.getcwd()) dlg.DoModal() filename=dlg.GetPathName() try: self.cargo_list=pd.read_excel(filename) except: print("无法打开文件cargo_list")
def image_load(): dlg = win32ui.CreateFileDialog(1) dlg.SetOFNInitialDir(os.path.abspath(os.curdir)) dlg.DoModal() image_path = dlg.GetPathName() f = open(image_path, 'rb') image = base64.b64encode(f.read()) f.close return image
def OnBrowse(self, id, cmd): openFlags = win32con.OFN_OVERWRITEPROMPT|win32con.OFN_FILEMUSTEXIST dlg = win32ui.CreateFileDialog(1,None,None,openFlags, "Python Scripts (*.py)|*.py||", self) dlg.SetOFNTitle("Run Script") if dlg.DoModal()!=win32con.IDOK: return 0 self['script'] = dlg.GetPathName() self.UpdateData(0) return 0
def read_excel(): global filename wrong = 0 print("请打开要检验的噩梦版Excel文件") dlg = win32ui.CreateFileDialog(1, None, None, 0, "Excel files|*.xls*") # 表示打开文件对话框 dlg.SetOFNInitialDir('D:/') # 设置打开文件对话框中的初始显示目录 dlg.DoModal() filename = dlg.GetPathName() # 获取选择的文件名称