Пример #1
0
 def showClientCEV485View(self):
     self.mBottomArea.children = []
     if self.uartfd == None:
         dialite.inform(title="串口信息",message="串口没有打开!")
         return
     with self.mBottomArea:
         ClientCEV485View(uartfd=self.uartfd,flex=1)
Пример #2
0
 def openPortCallback(self,port):
     """ 串口打开处理 """
     self.uartfd = self.udr.createHandler(port)
     if (self.uartfd != None):
         dialite.inform(title="串口信息",message="串口%s已打开" % port.device)
         self.setSerialInfo(port.device)
         return True
     dialite.inform(title="串口信息",message="串口%s打开失败" % port.device)
     return False
Пример #3
0
 def _start_botton_evthandler(self,*events):
     if self.listenMode.checked and self.isThreadStarted == False:
         self.isThreadStarted = True
         self.btnStart.text = "模拟结束"
         self.recvThread = threading.Thread(target=self._doListenRS485,args=(self.uartFD,))
         self.recvThread.setDaemon(True)
         self.recvThread.start()
     elif self.listenMode.checked and self.isThreadStarted:
         self.isThreadStarted = False
         self.recvThread.join()
         dialite.inform(title="模拟工作状态",message="模拟工作结束")
         self.btnStart.text = "模拟启动"
Пример #4
0
def test_unsupported_platform1():
    """ Unsupported platform, fallback to terminal. """

    o_platform = sys.platform
    o_stdin = sys.stdin
    o_app = dialite._the_app

    sys.platform = 'meh'

    sys.stdin = FakeStdin()

    try:

        app = dialite._select_app()
        assert app.works()
        assert isinstance(app, TerminalApp)
        dialite._the_app = app

        assert dialite.is_supported()

        with capture_log('info') as log:
            dialite.inform()
        assert len(log) == 1 and '[I' in log[0]

        with capture_log('info') as log:
            dialite.warn()  # no problem
        assert len(log) == 1 and '[W' in log[0]

        with capture_log('info') as log:
            dialite.fail()
        assert len(log) == 1 and '[E' in log[0]

        assert dialite.ask_ok()
        assert dialite.ask_retry()
        assert dialite.ask_yesno()

        sys.stdin.answer = 'no'
        assert not dialite.ask_ok()
        assert not dialite.ask_retry()
        assert not dialite.ask_yesno()

    finally:
        sys.platform = o_platform
        sys.stdin = o_stdin
        dialite._the_app = o_app
Пример #5
0
def test_unsupported_platform1():
    """ Unsupported platform, fallback to terminal. """
    
    o_platform = sys.platform
    o_stdin = sys.stdin
    o_app = dialite._the_app
    
    sys.platform = 'meh'
    
    sys.stdin = FakeStdin()
    
    try:
        
        app = dialite._get_app(True)
        assert app.works()
        assert isinstance(app, TerminalApp)
        
        assert dialite.is_supported()
        
        with capture_log('info') as log:
            dialite.inform()
        assert len(log) == 1 and '[I' in log[0]
        
        with capture_log('info') as log:
            dialite.warn()  # no problem
        assert len(log) == 1 and '[W' in log[0]
        
        with capture_log('info') as log:
            dialite.fail()
        assert len(log) == 1 and '[E' in log[0]
        
        assert dialite.ask_ok()
        assert dialite.ask_retry()
        assert dialite.ask_yesno()
        
        sys.stdin.answer = 'no'
        assert not dialite.ask_ok()
        assert not dialite.ask_retry()
        assert not dialite.ask_yesno()
    
    finally:
        sys.platform = o_platform
        sys.stdin = o_stdin
        dialite._the_app = o_app
Пример #6
0
def test_unsupported_platform2():
    """ Unsupported platform, and also no terminal. """
    
    o_platform = sys.platform
    o_stdin = sys.stdin
    o_app = dialite._the_app
    o_open = webbrowser.open
    
    sys.platform = 'meh'
    sys.stdin = None
    webbrowser.open = lambda x:None
    
    try:
        
        app = dialite._get_app(True)
        assert app.works()
        assert isinstance(app, StubApp)
        
        assert not dialite.is_supported()
        
        dialite.inform()  # no problem
        
        dialite.warn()  # no problem
        
        dialite.fail()  # no problem
        # with raises(SystemExit):
        #     dialite.fail()
        
        with raises(SystemExit):
            dialite.ask_ok()
        
        with raises(SystemExit):
            dialite.ask_retry()
            
        with raises(SystemExit):
            dialite.ask_yesno()
    
    finally:
        sys.platform = o_platform
        sys.stdin = o_stdin
        dialite._the_app = o_app
        webbrowser.open = o_open
Пример #7
0
def test_osx():
    """ Pretend that this is OS X. """
    
    o_platform = sys.platform
    o_app = dialite._the_app
    sys.platform = 'darwin'
    
    try:
        
        app = FakeOSXApp()
        # assert app.works()
        assert isinstance(app, OSXApp)
        dialite._the_app = app
        
        assert dialite.is_supported()
        
        dialite.inform()
        assert len(app._messages) == 1
        
        dialite.warn()
        assert len(app._messages) == 2
        
        dialite.fail()
        assert len(app._messages) == 3
        
        assert dialite.ask_ok()
        assert len(app._messages) == 4
        
        assert dialite.ask_retry()
        assert len(app._messages) == 5
        
        assert dialite.ask_yesno()
        assert len(app._messages) == 6
    
    finally:
        sys.platform = o_platform
        dialite._the_app = o_app
Пример #8
0
def test_linux():
    """ Pretend that this is Linux. """
    
    o_platform = sys.platform
    o_app = dialite._the_app
    sys.platform = 'linux'
    
    try:
        
        app = FakeLinuxApp()
        # assert app.works()
        assert isinstance(app, LinuxApp)
        dialite._the_app = app
        
        assert dialite.is_supported()
        
        dialite.inform()
        assert len(app._messages) == 1 and 'info' in app._messages[-1]
        
        dialite.warn()
        assert len(app._messages) == 2 and 'warn' in app._messages[-1]
        
        dialite.fail()
        assert len(app._messages) == 3 and 'error' in app._messages[-1]
        
        assert dialite.ask_ok()
        assert len(app._messages) == 4 and 'question' in app._messages[-1]
        
        assert dialite.ask_retry()
        assert len(app._messages) == 5 and 'question' in app._messages[-1]
        
        assert dialite.ask_yesno()
        assert len(app._messages) == 6 and 'question' in app._messages[-1]
    
    finally:
        sys.platform = o_platform
        dialite._the_app = o_app
Пример #9
0
assert res is True

res = dialite.ask_yesno(PREFIX + 'yes-no', 'Sudo make me a sandwich.')
assert res is True

# Unicode

res = dialite.ask_yesno(PREFIX + 'unicode',
                  'Do you see "double quotes", \'single quotes\', '
                  'a euro symbol (€), pi symbol (π), an A with a roof (Â)?')
assert res is True

# Three message boxes

res = dialite.inform(PREFIX + 'info', 'Awesome! '
                     'We will now show three dialogs: info, warn, error. '
                     'This is the first one; an info dialog.')
assert res is None

res = dialite.warn(PREFIX + 'warn', 'This is the second one; a warning.')
assert res is None

res = dialite.fail(PREFIX + 'error', 'This is the third one; an error.')
assert res is None

# Check results

res = dialite.ask_yesno(PREFIX + 'check',
                  'Did the past three boxes look something like an info, '
                  'warning, and error dialog, and have only an OK option?')
assert res is True