示例#1
0
    def valid(self, command):
        if not command:
            return True

        if super().valid(command):
            if command != cmCancel and command != cmFileClear:
                fName = self.getFilename()

                if isWild(fName):
                    path, name = splitPath(fName)
                    if self.checkDirectory(path):
                        self.directory = path
                        self.wildCard = name
                        if command != cmFileInit:
                            self.fileList.select()
                        self.fileList.readDirectory(self.directory, self.wildCard)
                elif os.path.isdir(fName):
                    if self.checkDirectory(fName):
                        self.directory = fName
                        if command != cmFileInit:
                            self.fileList.select()
                        self.fileList.readDirectory(self.directory, self.wildCard)
                elif validFileName(fName):
                    return True
                else:
                    messageBox(self.invalidFileText, mfError, [mfOKButton])
                    return False
            else:
                return True
        return False
示例#2
0
    def checkDirectory(self, pth):
        if pathValid(pth):
            return True

        messageBox(self.invalidDriveText, mfError, [mfOKButton])
        self.filename.select()
        return False
示例#3
0
 def handleEvent(self, event):
     super().handleEvent(event)
     if event.what == evCommand:
         emc = event.message.command
         if emc == cmAbout:
             self.aboutDialog()
         elif emc == cmPopup:
             self.popup()
         elif emc == cmOne:
             messageBox('Item 1 selected', mfInformation, (mfOKButton, ))
         elif emc == cmTwo:
             messageBox('Item 2 selected', mfInformation, (mfOKButton, ))
         self.clearEvent(event)
示例#4
0
    def valid(self, command):
        if command == cmReleasedFocus:
            return True

        if command in {cmQuit, cmClose, cmOK}:
            if self.regex:
                try:
                    m = re.match(self.regex, self.getDataString())
                    if m and m.string != self.getDataString():
                        self.select()
                        return False
                except Exception as e:
                    messageBox(str(e), mfError, (mfOKButton, ))
                    return False
        return super().valid(command)
示例#5
0
    def doEditorDialog(self, dialog, *args):
        if dialog == edOutOfMemory:
            return messageBox('Not enough memory for this operation', mfError,
                              (mfOKButton, ))
        if dialog == edReadError:
            return messageBox('Error reading file {}'.format(args[0]), mfError,
                              (mfOKButton, ))
        if dialog == edWriteError:
            return messageBox('Error writing file {}'.format(args[0]), mfError,
                              (mfOKButton, ))
        if dialog == edCreateError:
            return messageBox('Error creating file {}'.format(args[0]),
                              mfError, (mfOKButton, ))
        if dialog == edSaveModify:
            return messageBox('%s has been modified. Save?'.format(args[0]),
                              mfInformation,
                              (mfYesButton, mfNoButton, mfCancelButton))
        if dialog == edSaveUntitled:
            return messageBox('Save untitled file?', mfInformation,
                              (mfYesButton, mfNoButton, mfCancelButton))
        if dialog == edSaveUntitled:
            return execDialog(
                FileDialog('*.*', 'Save file as', '~N~ame', fdOKButton, 101),
                args[0])

        if dialog == edSearchFailed:
            return messageBox('Search string not found', mfError,
                              (mfOKButton, ))

        if dialog == edReplace:
            return execDialog(createReplaceDialog(), args[0])

        if dialog == edReplacePrompt:
            return self.doReplacePrompt(args[0])
示例#6
0
    def valid(self, command):
        if command != cmOK:
            return True
        rec = DataRecord()
        self.dirInput.getData()
        path = rec.value
        if not path:
            event = Event(evCommand)
            event.message.command = cmChangeDir
            self.putEvent(event)
            return False

        path = fexpand(path)
        if path and path[-1] == os.sep:
            path = path[:-1]

        if self.changeDir(path):
            messageBox(self.invalidText, mfError, (mfOKButton, ))
            return False
        return True
示例#7
0
    def readFile(self, fName):
        self._limit.x = 0
        self.fileName = fName
        self.fileLines = Collection()

        try:
            fileToView = open(fName, 'rt', encoding='utf-8')
        except OSError:
            messageBox(_('Invalid drive or directory'), 1, mfError | mfOKButton)
            self.isValid = False
            return

        lines = fileToView.readlines()
        if self.wrap:
            wrapped = (textwrap.wrap(l + '\n', self.size.x - 1, expand_tabs=True, tabsize=4) for l in lines)
            lines = itertools.chain(*wrapped)

        self.fileLines.extend(lines)
        self._limit.y = len(self.fileLines)
        if self.fileLines:
            self._limit.x = max(len(l) for l in self.fileLines)
示例#8
0
 def newDialog(self):
     pd = Dialog(Rect(20, 6, 60, 19), 'Demo Dialog')
     sb = ScrollBar(Rect(25, 2, 26, 11))
     pd.insert(sb)
     lb = ListBox(Rect(2, 2, 24, 11), 2, sb)
     pd.insert(lb)
     names = random.sample(animals, 20)
     tsc = StringCollection(names)
     pd.insert(Button(Rect(28, 6, 38, 8), '~O~K', cmOK, bfDefault))
     pd.insert(Button(Rect(28, 10, 38, 12), '~C~ancel', cmCancel, bfNormal))
     data = ListBoxRec()
     data.items = tsc
     data.selection = 2
     items = [data]
     pd.setData(items)
     control = self.desktop.execView(pd)
     if control != cmCancel:
         data = pd.getData()
         data = data[0]
     if control == cmOK:
         messageBox('\x03Your selection is {}'.format(tsc[data.selection]), mfInformation, (mfOKButton,))
     self.destroy(pd)
示例#9
0
 def doWork(self):
     messageBox('\003Welcome to the cheese ordering system', mfInformation,
                (mfOKButton, ))
     checkBoxData = 1
     radioButtonData = 2
     inputLineData = 'By box'
     demoDialogData = [checkBoxData, radioButtonData, inputLineData]
     data = self.newDialog(demoDialogData)
     if data:
         messageBox('Your order is accepted', mfInformation, (mfOKButton, ))
     else:
         messageBox('You cancelled the order', mfError, (mfOKButton, ))
示例#10
0
    def __call__(self):
        saAttr = win32security.SECURITY_ATTRIBUTES()
        saAttr.bInheritHandle = 1

        self.hChildStdoutRd = win32pipe.CreateNamedPipe(
            self.stdoutPipeName,
            win32con.PIPE_ACCESS_INBOUND
            | win32con.FILE_FLAG_OVERLAPPED,  # open mode
            win32con.PIPE_TYPE_BYTE,  # pipe mode
            1,  # max instances
            WindowsShell.BUFFER_SIZE,  # out buffer size
            WindowsShell.BUFFER_SIZE,  # in buffer size
            15,  # timeout
            saAttr)

        hChildStdoutWr = win32file.CreateFile(
            self.stdoutPipeName, win32con.GENERIC_WRITE,
            win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE, saAttr,
            win32con.OPEN_EXISTING, win32con.FILE_FLAG_OVERLAPPED, 15)

        win32api.SetHandleInformation(self.hChildStdoutRd,
                                      win32con.HANDLE_FLAG_INHERIT, 0)

        self.hChildStderrRd = win32pipe.CreateNamedPipe(
            self.stderrPipeName,
            win32con.PIPE_ACCESS_INBOUND
            | win32con.FILE_FLAG_OVERLAPPED,  # open mode
            win32con.PIPE_TYPE_BYTE,  # pipe mode
            1,  # max instances
            WindowsShell.BUFFER_SIZE,  # out buffer size
            WindowsShell.BUFFER_SIZE,  # in buffer size
            15,  # timeout
            saAttr)

        hChildStderrWr = win32file.CreateFile(
            self.stderrPipeName, win32con.GENERIC_WRITE,
            win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE, saAttr,
            win32con.OPEN_EXISTING, win32con.FILE_FLAG_OVERLAPPED, 15)

        win32api.SetHandleInformation(self.hChildStderrRd,
                                      win32con.HANDLE_FLAG_INHERIT, 0)

        # Create a pipe for the child process's STDIN. This one is opened
        # in duplex mode so we can read from it too in order to detect when
        # the child closes their end of the pipe.

        self.hChildStdinWr = win32pipe.CreateNamedPipe(
            self.stdinPipeName,
            win32con.PIPE_ACCESS_DUPLEX
            | win32con.FILE_FLAG_OVERLAPPED,  # open mode
            win32con.PIPE_TYPE_BYTE,  # pipe mode
            1,  # max instances
            WindowsShell.BUFFER_SIZE,  # out buffer size
            WindowsShell.BUFFER_SIZE,  # in buffer size
            15,  # timeout... 0 gives a default 50 ms
            saAttr)

        hChildStdinRd = win32file.CreateFile(
            self.stdinPipeName, win32con.GENERIC_READ,
            win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE, saAttr,
            win32con.OPEN_EXISTING,
            win32con.FILE_FLAG_OVERLAPPED | win32con.FILE_FLAG_NO_BUFFERING,
            15)

        win32api.SetHandleInformation(self.hChildStdinWr,
                                      win32con.HANDLE_FLAG_INHERIT, 0)

        # set the info structure for the new process.  This is where
        # we tell the process to use the pipes for stdout/err/in.
        StartupInfo = win32process.STARTUPINFO()
        StartupInfo.hStdOutput = hChildStdoutWr
        StartupInfo.hStdError = hChildStderrWr
        StartupInfo.hStdInput = hChildStdinRd
        StartupInfo.dwFlags = win32process.STARTF_USESTDHANDLES

        flags = win32process.CREATE_UNICODE_ENVIRONMENT

        try:
            processHandle, threadHandle, dwPid, dwTid = win32process.CreateProcess(
                None,  # name
                self.cmdline,  # command line
                None,  # process handle not inheritable
                None,  # thread handle not inheritable
                True,  # handles are inherited
                flags,  # creation flags
                None,  # NULL, use parent environment
                None,  # current directory
                StartupInfo)  # STARTUPINFO pointer
        except pywintypes.error as e:
            logger.exception('%s\n%s\n', self.cmdline, e.strerror)
            messageBox(f'{self.cmdline}\n{e.strerror}', mfError,
                       (mfOKButton, ))
            return None

        win32file.CloseHandle(processHandle)
        win32file.CloseHandle(threadHandle)
        win32file.CloseHandle(hChildStderrWr)
        win32file.CloseHandle(hChildStdoutWr)
        win32file.CloseHandle(hChildStdinRd)

        self.stdin = os.fdopen(msvcrt.open_osfhandle(int(self.hChildStdinWr),
                                                     0),
                               'wb',
                               buffering=0)
        self.stdout = os.fdopen(msvcrt.open_osfhandle(int(self.hChildStdoutRd),
                                                      0),
                                'rb',
                                buffering=0)
        self.stderr = os.fdopen(msvcrt.open_osfhandle(int(self.hChildStderrRd),
                                                      0),
                                'rb',
                                buffering=0)
        fds = WindowPipe(stdin=self.stdin,
                         stdout=self.stdout,
                         stderr=self.stderr)
        return fds
示例#11
0
 def About(self):
     messageBox('\x03Dynamic Text Demo', mfInformation, (mfOKButton, ))
示例#12
0
 def error(self):
     messageBox(self.errorMsg.format(self.min, self.max), mfError,
                (mfOKButton, ))
示例#13
0
 def doWork(self):
     messageBox('\003Directory Dialog\nCurrent Directory is {}'.format(os.getcwd()), mfInformation, (mfOKButton,))
     data = self.newDialog()
     messageBox('\003Directory Dialog\nCurrent Directory is now {}\n{}'.format(os.getcwd(), data), mfInformation, (mfOKButton,))
示例#14
0
 def error(self):
     messageBox(self.errorMsg, mfError, (mfOKButton,))