def get_system_folder(folder_id): #folder = shell.SHGetFolderPath(0, folder_id, 0, 0) # Following does not return unicode string folder = shell.SHGetPathFromIDList(shell.SHGetFolderLocation(0, folder_id)) if not isinstance(folder, unicode): folder = folder.decode(sys.getfilesystemencoding()) return folder
def choose_folder(title=strings.choose_folder): desktop_pidl = shell.SHGetFolderLocation(0, shellcon.CSIDL_DESKTOP, 0, 0) pidl, display_name, image_list = shell.SHBrowseForFolder( win32gui.GetDesktopWindow(), desktop_pidl, title, 0, None, None) if pidl: path = shell.SHGetPathFromIDListW(pidl) set_last_cwd(path) return path
def askOpenFolderWin32(title, initialDir): try: desktop_pidl = shell.SHGetFolderLocation(0, shellcon.CSIDL_DESKTOP, 0, 0) pidl, display_name, image_list = shell.SHBrowseForFolder( win32gui.GetDesktopWindow(), desktop_pidl, "Choose a folder", 0, None, None) return shell.SHGetPathFromIDList(pidl) except pywintypes.com_error as e: if e.args[0] == -2147467259: print "Invalid folder selected"
def _setup_file_handler(): global _file_handler # import traceback; traceback.print_stack() if not _file_handler: # Lookup path the user's personal folder in which # to log Dragonfly messages. mydocs_pidl = shell.SHGetFolderLocation(0, shellcon.CSIDL_PERSONAL, 0, 0) mydocs_path = shell.SHGetPathFromIDList(mydocs_pidl) log_file_path = os.path.join(mydocs_path, "dragonfly.txt") _file_handler = logging.FileHandler(log_file_path) formatter = logging.Formatter("%(asctime)s %(name)s (%(levelname)s):" " %(message)s" + repr(_file_handler)) _file_handler.setFormatter(formatter) return _file_handler
def create_file_dialog(self, dialog_type, directory, allow_multiple, save_filename): if not directory: directory = os.environ['temp'] try: if dialog_type == FOLDER_DIALOG: desktop_pidl = shell.SHGetFolderLocation( 0, shellcon.CSIDL_DESKTOP, 0, 0) pidl, display_name, image_list =\ shell.SHBrowseForFolder(self.hwnd, desktop_pidl, None, 0, None, None) file_path = (shell.SHGetPathFromIDList(pidl).decode("utf-8"), ) elif dialog_type == OPEN_DIALOG: file_filter = localization[ "windows.fileFilter.allFiles"] + u"\0*.*\0" custom_filter = localization[ "windows.fileFilter.otherFiles"] + u"\0*.*\0" flags = win32con.OFN_EXPLORER if allow_multiple: flags = flags | win32con.OFN_ALLOWMULTISELECT file_path, customfilter, flags = \ win32gui.GetOpenFileNameW(self.hwnd, InitialDir=directory, Flags=flags, File=None, DefExt="", Title="", Filter=file_filter, CustomFilter=custom_filter, FilterIndex=0) parts = file_path.split('\x00') if len(parts) > 1: file_path = tuple([ os.path.join(parts[0], file_name) for file_name in parts[1:] ]) else: file_path = (file_path, ) elif dialog_type == SAVE_DIALOG: file_filter = localization[ "windows.fileFilter.allFiles"] + u"\0*.*\0" custom_filter = localization[ "windows.fileFilter.otherFiles"] + u"\0*.*\0" file_path, customfilter, flags = \ win32gui.GetSaveFileNameW(self.hwnd, InitialDir=directory, File=save_filename, DefExt="", Title="", Filter=file_filter, CustomFilter=custom_filter, FilterIndex=0) except Exception as e: logger.debug("File dialog crash", exc_info=True) file_path = None return file_path
def create_file_dialog(self, dialog_type, directory, allow_multiple, save_filename): if not directory: directory = os.environ['temp'] try: if dialog_type == FOLDER_DIALOG: desktop_pidl = shell.SHGetFolderLocation( 0, shellcon.CSIDL_DESKTOP, 0, 0) pidl, display_name, image_list =\ shell.SHBrowseForFolder(self.hwnd, desktop_pidl, None, 0, None, None) file_path = (shell.SHGetPathFromIDList(pidl), ) elif dialog_type == OPEN_DIALOG: file_filter = 'All Files\0*.*\0' custom_filter = 'Other file types\0*.*\0' flags = win32con.OFN_EXPLORER if allow_multiple: flags = flags | win32con.OFN_ALLOWMULTISELECT file_path, customfilter, flags = \ win32gui.GetOpenFileNameW(InitialDir=directory, Flags=flags, File=None, DefExt='', Title='', Filter=file_filter, CustomFilter=custom_filter, FilterIndex=0) parts = file_path.split('\x00') if len(parts) > 1: file_path = tuple([ os.path.join(parts[0], file_name) for file_name in parts[1:] ]) else: file_path = (file_path, ) elif dialog_type == SAVE_DIALOG: file_filter = 'All Files\0*.*\0' custom_filter = 'Other file types\0*.*\0' file_path, customfilter, flags = \ win32gui.GetSaveFileNameW(InitialDir=directory, File=save_filename, DefExt='', Title='', Filter=file_filter, CustomFilter=custom_filter, FilterIndex=0) parts = file_path.split('\x00') return file_path except: return None
def shell_entry(shell_entry=core.UNSET): if shell_entry is None: return None elif shell_entry is core.UNSET: return ShellFolder([], desktop) elif isinstance(ShellEntry, shell_entry): return shell_entry elif isinstance(shell_entry, basestring): pidl, flags = shell.SHILCreateFromPath(os.path.abspath(shell_folder), SHCONTF.FOLDERS) if pidl is None: return ShellFolder( shell.SHGetFolderLocation(None, CSIDL.constant(shell_entry), None, 0), desktop) pidl = None return ShellFolder( desktop.BindToObject(pidl, None, shell.IID_IShellFolder))
def exposed_select_directory(self): if self._pytis_on_windows(): import win32gui from win32com.shell import shell, shellcon # Get PIDL of the topmost folder for the dialog desktop_pidl = shell.SHGetFolderLocation(0, shellcon.CSIDL_DESKTOP, 0, 0) pidl, display_name, image_list = shell.SHBrowseForFolder( win32gui.GetDesktopWindow(), desktop_pidl, u"Výběr adresáře", 0, None, None) # Transform PIDL back to a directory name and return it return shell.SHGetPathFromIDList(pidl) else: import PyZenity as zenity directory_list = zenity.GetDirectory() if directory_list and len(directory_list) > 0: return directory_list[0] else: return None
def get_save_path(): # 获取保存的文件夹 import win32gui from win32com.shell import shell, shellcon desktop_pidl = shell.SHGetFolderLocation(0, shellcon.CSIDL_DESKTOP, 0, 0) pidl, display_name, image_list = shell.SHBrowseForFolder( win32gui.GetDesktopWindow(), desktop_pidl, "Choose a folder", 0, None, None) # 获取 print(shell.SHGetPathFromIDList(pidl)) l = shell.SHGetPathFromIDList(pidl) print(l) return l # 获得输入的文件名 # return filename pass
def _select_directory(self, title, directory): import win32gui from win32com.shell import shell, shellcon def callback(hwnd, msg, lp, data): if msg == shellcon.BFFM_INITIALIZED: win32gui.SendMessage(hwnd, shellcon.BFFM_SETSELECTION, 1, directory) pidl, dname, imglist = shell.SHBrowseForFolder( win32gui.GetDesktopWindow(), # Get PIDL of the topmost folder for the dialog shell.SHGetFolderLocation(0, shellcon.CSIDL_DESKTOP, 0, 0), title, 0, callback, None, ) # Transform PIDL back to a directory name and return it return shell.SHGetPathFromIDList(pidl)
def selecdirectori(): mydocs_pidl = shell.SHGetFolderLocation (0, shellcon.CSIDL_DESKTOP, 0, 0) pidl, display_name, image_list = shell.SHBrowseForFolder ( win32gui.GetDesktopWindow (), mydocs_pidl, "Select a file or folder", shellcon.BIF_BROWSEINCLUDEFILES, None, None ) if (pidl, display_name, image_list) == (None, None, None): print "Nothing selected" else: path = shell.SHGetPathFromIDList (pidl) #print "Opening", #path a=(path) return a
def path_update(): desktop_pidl = shell.SHGetFolderLocation (0, shellcon.CSIDL_DESKTOP, 0, 0) pidl, display_name, image_list = shell.SHBrowseForFolder ( win32gui.GetDesktopWindow (), desktop_pidl, "Select Steam root folder", 0, None, None ) with open(dir+'\\s_path.sah', 'w') as p: decoded = shell.SHGetPathFromIDList (pidl).decode('utf-8') full_path = decoded + '\\Steam.exe' try: p.write(full_path) except Exception as error: print("An error occured while updating the path: %s" %error) finally: p.close() menu()
def shell_folder(shell_folder=core.UNSET, parent=core.UNSET): if shell_folder is None: return None elif shell_folder is core.UNSET: return ShellFolder([], desktop) elif isinstance(shell_folder, PyIShellFolder): return ShellFolder(shell_folder) elif isinstance(shell_folder, basestring): pidl, flags = shell.SHILCreateFromPath(os.path.abspath(shell_folder), 0) if pidl is None: pidl = shell.SHGetFolderLocation(None, CSIDL.constant(shell_folder), None, 0) return ShellFolder( desktop.BindToObject(pidl, None, shell.IID_IShellFolder)) elif isinstance(shell_folder, list): if parent is core.UNSET: raise x_shell(errctx="shell_folder", errmsg="Cannot bind to PIDL without parent") return ShellFolder( parent.BindToObject(shell_folder, None, shell.IID_IShellFolder)) else: raise x_shell(errctx="shell_folder")
def main(): #delete any leftover previously created delivery notes folders leftover_del_notes_folders = glob.glob('\Delivery Notes*') for folder in leftover_del_notes_folders: shutil.rmtree(folder) #open browser window to enable user to choose file to create delivery #notes from desktop_pidl = shell.SHGetFolderLocation(0, shellcon.CSIDL_DESKTOP, 0, 0) pidl, display_name, image_list = shell.SHBrowseForFolder( win32gui.GetDesktopWindow(), desktop_pidl, "Please select the file you would \ like to create your delivery notes from.", shellcon.BIF_BROWSEINCLUDEFILES, None, None) if (pidl, display_name, image_list) == (None, None, None): print vis_demarc_line + "\n\n\tNothing selected" else: fin = shell.SHGetPathFromIDList(pidl) #open Excel workbook workbook_in = xlrd.open_workbook(fin) #Iterate through worksheets print vis_demarc_line + "\n\n\t" for sheet in workbook_in.sheets(): store = sheet.name worksheet = workbook_in.sheet_by_name(store) #Grab data from input workbook store_name = worksheet.cell(0, 1) store_address_cell = sheet.cell(1, 1) store_code = worksheet.cell(3, 1) store_address = re.split("[,.]", store_address_cell.value) #Create dictionary to store address address_dict = {} #Load address into dictionary i = 1 for address_line in store_address: address_dict[i] = address_line i += 1 #Define devices in each worksheet, where all_devices is a #list of devices switch_col = worksheet.col_values(4, 6, 15) ap_col = worksheet.col_values(1, 17, 36) list_of_switches = list(set(switch_col)) list_of_switches.remove('') list_of_aps = list(set(ap_col)) all_devices = list_of_switches + list_of_aps #Save sheet as temporary csv file for easier data collection with open(store + '-temp.csv', 'w') as csv_in: csv_temp = csv.writer(csv_in) for row in range(worksheet.nrows): csv_temp.writerow(worksheet.row_values(row)) #Parse csv file for device and serial data device1 = all_devices[0] device2 = all_devices[1] device3 = None if len(all_devices) > 3: device3 = all_devices[2] device4 = all_devices[-1] #Create empty device lists, where the name of each list is a #different device model device1_list = [] device2_list = [] device3_list = [] device4_list = [] #Build device lists with device serial numbers with open(store + '-temp.csv', 'r') as csv_out: lines = csv_out.readlines() for line in lines: if device1 in line and \ (line.split(',')[-2] != ''): device1_list.append(line.split(',')[-2]) elif device2 in line and \ (line.split(',')[-2] != ''): device2_list.append(line.split(',')[-2]) elif (len(all_devices) > 3) and \ device3 in line and \ (line.split(',')[-2] != ''): device3_list.append(line.split(',')[-2]) elif device4 in line and \ (line.split(',')[2] != ''): device4_list.append(line.split(',')[2]) #Show progress to user print '\n\tCreating %s (%s) delivery note...\n' % (store_name.value, store_code.value) #Create delivery note workbook workbook_out = Workbook() del_note = workbook_out.add_sheet('Delivery Note', cell_overwrite_ok=True) #Format delivery note workbook format_delivery_note(del_note) #Write store name and address to delivery note store_code_statement = 'Store code: %s' % store_code.value del_note.write_merge(10, 10, 0, 3, store_name.value, left_and_right_border_left_align) del_note.write_merge(11, 11, 0, 3, address_dict.get(1), left_and_right_border_left_align) del_note.write_merge(12, 12, 0, 3, address_dict.get(2), left_and_right_border_left_align) del_note.write_merge(13, 13, 0, 3, address_dict.get(3), left_and_right_border_left_align) del_note.write_merge(14, 14, 0, 3, address_dict.get(4), left_and_right_border_left_align) del_note.write_merge(15, 15, 0, 3, address_dict.get(5), left_and_right_border_left_align) del_note.write_merge(16, 16, 0, 3, address_dict.get(6), left_and_right_border_left_align) del_note.write_merge(17, 17, 0, 3, store_code_statement, all_borders_centre_align) #Specify device quantities i = 20 j = i + len(device1_list) k = j + len(device2_list) l = k + len(device3_list) total_no_of_devices = (len(device1_list) + len(device2_list) + len(device3_list) + len(device4_list)) #write device model names to delivery note del_note.write_merge(i, i, 2, 5, device1, all_borders_centre_align) del_note.write_merge(j, j, 2, 5, device2, all_borders_centre_align) del_note.write_merge(k, k, 2, 5, device3, all_borders_centre_align) del_note.write_merge(l, l, 2, 5, device4, all_borders_centre_align) #Write device quantities to delivery note del_note.write_merge(i, i, 0, 1, len(device1_list), all_borders_centre_align) del_note.write_merge(j, j, 0, 1, len(device2_list), all_borders_centre_align) del_note.write_merge(k, k, 0, 1, len(device3_list), all_borders_centre_align) del_note.write_merge(l, l, 0, 1, len(device4_list), all_borders_centre_align) #Write device lists to excel file for item in device1_list: del_note.write_merge(i, i, 6, 9, item, all_borders_centre_align) i += 1 for item in device2_list: del_note.write_merge(j, j, 6, 9, item, all_borders_centre_align) j += 1 for item in device3_list: del_note.write_merge(k, k, 6, 9, item, all_borders_centre_align) k += 1 for item in device4_list: del_note.write_merge(l, l, 6, 9, item, all_borders_centre_align) l += 1 #Write number of boxes to delivery note total_boxes = '%d BOXES IN TOTAL' % total_no_of_devices row1 = total_no_of_devices + 20 row2 = row1 + 1 del_note.write_merge(row1, row2, 0, 9, total_boxes, all_borders_centre_align) #Delete temp csv files os.remove(store + '-temp.csv') #create 'Delivery Notes' folder within the same directory as the #Excel spreadsheet if it doesn't already exist folder_timestr = time.strftime("%d%m%Y") del_notes_dir = desktop_path + '\Delivery Notes-' + folder_timestr + '\\' if not os.path.exists(del_notes_dir): os.makedirs(del_notes_dir) #Save excel file workbook_out.save(del_notes_dir + store_code.value + '-' + total_boxes + '.xls') print( vis_demarc_line + "\n\n\tYour delivery notes have been created here:\n\n\t%s" % del_notes_dir + vis_demarc_line + '\n\n')
def get_special_folder_path(folder_id): return unicode(shell.SHGetFolderPath(0, folder_id, 0, 0)) return unicode( shell.SHGetPathFromIDList(shell.SHGetFolderLocation( 0, folder_id)) # .decode("iso-8859-2") )
"grammar.eval": (logging.WARNING, logging.WARNING), "grammar.process": (logging.WARNING, logging.WARNING), "compound.parse": (logging.WARNING, logging.INFO), "dictation.formatter": (logging.WARNING, logging.WARNING), "action": (logging.WARNING, logging.WARNING), "action.init": (logging.WARNING, logging.WARNING), "action.exec": (logging.WARNING, logging.WARNING), "context": (logging.WARNING, logging.INFO), "context.match": (logging.WARNING, logging.INFO), "rule": (logging.WARNING, logging.INFO), "config": (logging.WARNING, logging.INFO), "monitor.init": (logging.WARNING, logging.INFO), } # Lookup path the user's personal folder in which to log Dragonfly messages. mydocs_pidl = shell.SHGetFolderLocation(0, shellcon.CSIDL_PERSONAL, 0, 0) mydocs_path = shell.SHGetPathFromIDList(mydocs_pidl) log_file_path = os.path.join(mydocs_path, "dragonfly.txt") log_file_size = 128 * 1024 log_file_count = 9 #--------------------------------------------------------------------------- # Main factory function for users of the log facilities. _log_cache = {} def get_log(name): global _log_cache if name in _log_cache: return _log_cache[name]
from win32com.shell import shell, shellcon try: import winxpgui as win32gui except ImportError: import win32gui import struct import array import commctrl IDC_SEARCHTEXT = 1024 IDC_BUTTON_CANCEL = 1025 IDC_BUTTON_OK = 1026 desktop_pidl = shell.SHGetFolderLocation(0, shellcon.CSIDL_DESKTOP, 0, 0) WM_SEARCH_RESULT = win32con.WM_USER + 512 WM_SEARCH_FINISHED = win32con.WM_USER + 513 class _WIN32MASKEDSTRUCT: def __init__(self, **kw): full_fmt = "" for name, fmt, default, mask in self._struct_items_: self.__dict__[name] = None if fmt == "z": full_fmt += "pi" else: full_fmt += fmt for name, val in kw.iteritems():