/
NeiroN
/
PySCP
Обзор
Документация
Войти
/
NeiroN
/
PySCP
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
TkDND_wrapper.py
102 строки
4 KB
NeiroN
Add files
23 апр 2021, 16:21
23 апр 2021, 16:21
4b31692
Код
Авторство
О чём код?
# # This wrapper was copied from https://mail.python.org/pipermail/tkinter-discuss/2005-July/000476.html # parse_uri_list(self, uri_list) method was added by the author # import os import tkinter class TkDND(object): def __init__(self, tkroot): self._tkroot = tkroot # make self an attribute of the parent window for easy access in child classes tkroot.dnd = self def bindsource(self, widget, type=None, command=None, arguments=None, priority=None): '''Register widget as drag source; for details on type, command and arguments, see bindtarget(). priority can be a value between 1 and 100, where 100 is the highest available priority (default: 50). If command is omitted, return the current binding for type; if both type and command are omitted, return a list of registered types for widget.''' command = self._generate_callback(command, arguments) tkcmd = self._generate_tkcommand('bindsource', widget, type, command, priority) res = self._tkroot.tk.eval(tkcmd) if type == None: res = res.split() return res def bindtarget(self, widget, type=None, sequence=None, command=None, arguments=None, priority=None): '''Register widget as drop target; type may be one of text/plain, text/uri-list, text/plain;charset=UTF-8 (see the man page tkDND for details on other (platform specific) types); sequence may be one of '<Drag>', '<DragEnter>', '<DragLeave>', '<Drop>' or '<Ask>' ; command is the callback associated with the specified event, argument is an optional tuple of arguments that will be passed to the callback; possible arguments include: %A %a %b %C %c %D %d %L %m %T %t %W %X %x %Y %y (see the tkDND man page for details); priority may be a value in the range 1 to 100 ; if there are bindings for different types, the one with the priority value will be proceeded first (default: 50). If command is omitted, return the current binding for type, where sequence defaults to '<Drop>'. If both type and command are omitted, return a list of registered types for widget.''' command = self._generate_callback(command, arguments) tkcmd = self._generate_tkcommand('bindtarget', widget, type, sequence, command, priority) res = self._tkroot.tk.eval(tkcmd) if type == None: res = res.split() return res def clearsource(self, widget): '''Unregister widget as drag source.''' self._tkroot.tk.call('dnd', 'clearsource', widget) def cleartarget(self, widget): '''Unregister widget as drop target.''' self._tkroot.tk.call('dnd', 'cleartarget', widget) def drag(self, widget, actions=None, descriptions=None, cursorwindow=None, command=None, arguments=None): '''Initiate a drag operation with source widget.''' command = self._generate_callback(command, arguments) if actions: if actions[1:]: actions = '-actions {%s}' % ' '.join(actions) else: actions = '-actions %s' % actions[0] if descriptions: descriptions = ['{%s}'%i for i in descriptions] descriptions = '{%s}' % ' '.join(descriptions) if cursorwindow: cursorwindow = '-cursorwindow %s' % cursorwindow tkcmd = self._generate_tkcommand('drag', widget, actions, descriptions, cursorwindow, command) self._tkroot.tk.eval(tkcmd) def _generate_callback(self, command, arguments): '''Register command as tk callback with an optional list of arguments.''' cmd = None if command: cmd = self._tkroot._register(command) if arguments: cmd = '{%s %s}' % (cmd, ' '.join(arguments)) return cmd def _generate_tkcommand(self, base, widget, *opts): '''Create the command string that will be passed to tk.''' tkcmd = 'dnd %s %s' % (base, widget) for i in opts: if i is not None: tkcmd += ' %s' % i return tkcmd def parse_uri_list(self, uri_list): space_in_path = False unprocessed_file_list = uri_list.split(' ') file_list = [] processed_path = '' for item in unprocessed_file_list: if('{' in item): space_in_path = True processed_path = item.replace('{', '') elif('}' in item): space_in_path = False processed_path += ' ' + item.replace('}', '') file_list.append(processed_path) elif(space_in_path): processed_path+= ' ' + item else: file_list.append(item) return file_list