Esempio n. 1
0
 def kb_event(self, win, zxchar):
     s = zx2str([zxchar])
     if s in 'sS' or zxchar == 12:
         if "Linux" in platform.system():
             self.mainwin.cls()
             self.mainwin.prttxt(
                 str2zx('\nshutdown initiated\n\n    good bye.',
                        upper_inv=True))
             self.mrg.update(wait_till_sync_done=True)
             subprocess.run(
                 ["sudo", "shutdown", "-h", "0"]
             )  # sudo is reqired if the process was started via /etc/rc.local
         else:
             self.mainwin.prttxt(
                 str2zx('\nshutdown not supported on %s host.' %
                        (platform.system()),
                        upper_inv=False))
     elif s in 'xX':
         self.close()
         app.clear()
         return
     elif s in 'uU':
         if self.proc is None:
             self.start()
     else:
         self.mainwin.cls()
         self.print_help()
Esempio n. 2
0
    def kb_event(self, win, zxchar):
        #win.prtchar(zxchar)
        bright = {'1': 1.5, '2': 1.2, '3': 1.0, '4': 0.83, '5': 0.67}
        contr = {'6': 0.2, '7': 0.33, '8': 0.5, '9': 0.8, '0': 1.2}
        s = zx2str([zxchar])
        if s in 'xX' or zxchar == 12:
            self.close()
            return
        elif s in 'fF':
            self.delay_s = 0.15
        elif s in 'sS':
            self.delay_s = 3.0
        elif s in 'dD':
            self.floyd_stb = not self.floyd_stb
        elif s in 'iI':
            self.invert = not self.invert
        elif s in 'rR':
            self.h_v_rot += 1

        elif s in 'pP':
            if self.app_state == AppState.SHOW:
                self.app_state = AppState.PIC_QUERY_YN
                if self.ctrlwin: self.ctrlwin.close()
                self.ctrlwin = TextWindow(self.mgr,
                                          10,
                                          1,
                                          18,
                                          19,
                                          border=WindowBorderFrame(),
                                          kb_event=self.kb_event_query,
                                          cursor_off=True)
                self.ctrlwin.prttxt(str2zx('save? Y/N', upper_inv=True))

        elif s in 'mM':
            self.movie.clear()
            self.replay_ix = 0
            if self.app_state == AppState.SHOW:
                self.app_state = AppState.MOVIE_REC
                if self.ctrlwin: self.ctrlwin.close()
                self.ctrlwin = TextWindow(self.mgr,
                                          13,
                                          1,
                                          17,
                                          19,
                                          border=WindowBorderFrame(),
                                          kb_event=self.kb_event_query,
                                          cursor_off=True)
                self.ctrlwin.prttxt(str2zx('recording', upper_inv=True))

        elif s in bright:
            self.brightness = bright[s]
        elif s in contr:
            self.contrast = contr[s]
        # TODO invers, save_pic, help, exit
        self.ctrlwin_timeout = time.time() + 3
        self.check_show_ctrlwin()
        self.event.reschedule(0.2, 5.0)
Esempio n. 3
0
    def kb_event(self, win, zxchar):
        #win.prtchar(zxchar)
        s = zx2str([zxchar])

        if s in 'xXuU' or zxchar == 12:
            self.do_exit = True
            self.close()
        else:
            self.show()
Esempio n. 4
0
 def kb_event(self, win, char):
     if char == 12:
         self.mainwin.close()
         app.clear()
         # TODO clear threads
     else:
         win.prtchar(char)
         s = zx2str([char])
         #if s=='\n': s='\r\n'
         self.proc.stdin.write(s)
         self.proc.stdin.flush()
Esempio n. 5
0
 def kb_event(self,win,zxchar):
     s=zx2str( [zxchar] )
     if s in 'xX' or zxchar==12:
         if self.proc:
             self.proc.terminate()
         else:
             self.close()
             self.active=False
             self.mainwin.close()
             self.revent.remove()
             app.clear()
             return
     elif s in 'uU':
         if self.proc is None:
             self.start()
Esempio n. 6
0
 def kb_event_query(self, win, zxchar):
     #win.prtchar(zxchar)
     s = zx2str([zxchar])
     if self.app_state in (AppState.PIC_QUERY_NAME,
                           AppState.MOVIE_QUERY_NAME):
         if zxchar in (117, 118):  # enter,break
             if zxchar == 118:  # enter
                 self.edlin.kb_event(zxchar)
                 if self.app_state == AppState.PIC_QUERY_NAME:
                     if self.edlin.val:
                         # safe pic
                         name = zx2str(self.edlin.val,
                                       to_lower=True).strip()
                         #path
                         mwin = self.mgr.show_msg_win(str2zx("save pic .."))
                         p = zxpi_paths.get_current_work_path() / 'pics'
                         if not p.exists(): p.mkdir(parents=True)
                         n = p / (name + '.zxscr')
                         with n.open('wb') as f:
                             lrg = self.calc_lrg_from_array(self.last_pic)
                             nr, nc = lrg.shape
                             for row in range(nr):
                                 #for col in range(nc):
                                 f.write(bytes([v for v in lrg[row]]))
                             print("Saved to", str(n))
                         mwin.close()
                 elif self.app_state == AppState.MOVIE_QUERY_NAME:
                     if self.edlin.val:
                         # save movie
                         name = zx2str(self.edlin.val,
                                       to_lower=True).strip()
                         #path
                         pth = zxpi_paths.get_current_work_path() / 'movies'
                         if not pth.exists(): pth.mkdir(parents=True)
                         n = pth / (name + '.zxmovie')
                         mwin = self.mgr.show_msg_win(
                             str2zx("save movie .."))
                         mv_dat = bytearray()
                         with n.open('wb') as f:
                             for p in self.movie:
                                 lrg = self.calc_lrg_from_array(p)
                                 nr, nc = lrg.shape
                                 for row in range(nr):
                                     #for col in range(nc):
                                     rowdat = bytearray(
                                         [v for v in lrg[row]])
                                     mv_dat += rowdat
                                     f.write(rowdat)
                             print("Saved as", str(n))
                         self.mgr.update(0.1)
                         n = pth / (name + '.p')
                         with n.open('wb') as f:
                             f.write(
                                 create_comp_viewer(compress_scr(mv_dat)))
                         mwin.close()
             if self.edlin:
                 self.edlin.close()
                 self.edlin = None
             self.app_state = AppState.SHOW
             self.ctrlwin_timeout = 0
             if self.ctrlwin:
                 self.ctrlwin.close()
                 self.ctrlwin = None
         else:
             self.edlin.kb_event(zxchar)
     elif self.app_state in (AppState.MOVIE_REC, ):
         self.end_movie_rec()
     else:
         if s in 'yYzZ':
             if self.app_state in (AppState.PIC_QUERY_YN,
                                   AppState.MOVIE_QUERY_YN):
                 self.app_state = AppState.PIC_QUERY_NAME if self.app_state == AppState.PIC_QUERY_YN else AppState.MOVIE_QUERY_NAME
                 if self.ctrlwin: self.ctrlwin.close()
                 self.ctrlwin = TextWindow(self.mgr,
                                           12,
                                           2,
                                           18,
                                           19,
                                           border=WindowBorderFrame(),
                                           kb_event=self.kb_event_query,
                                           cursor_off=True)
                 self.ctrlwin.prttxt(str2zx('file name:', upper_inv=True))
                 self.edlin = LinEd(self.ctrlwin,
                                    0,
                                    1,
                                    11,
                                    maxchar=255,
                                    history=None)
         else:
             self.app_state = AppState.SHOW
             if self.ctrlwin:
                 self.ctrlwin.close()
                 self.ctrlwin = None
         self.event.reschedule(0.2, 5.0)
Esempio n. 7
0
 def kb_event(self, win, char):
     if self.inp_mode == InpMode.MENU:
         if char == 56:  # S
             self.inp_win.cls()
             self.inp_win.prttxt(
                 str2zx(' please enter server address: ', inverse=True))
             self.ed = LinEd(self.inp_win, 0, 1, 29, 255,
                             bytes(str2zx(self.server)))
             self.inp_mode = InpMode.INP_SRV
         elif char == 53:  # P
             self.inp_win.cls()
             self.inp_win.prttxt(
                 str2zx(' please enter port number: ', inverse=True))
             self.ed = LinEd(self.inp_win, 0, 1, 6, 5,
                             bytes(str2zx(str(self.port))))
             self.inp_mode = InpMode.INP_PORT
         elif char == 60:  # W
             self.inp_win.cls()
             self.inp_win.prttxt(
                 str2zx(' please enter pass word: ', inverse=True))
             self.ed = LinEd(self.inp_win, 0, 1, 29, 255)
             self.inp_mode = InpMode.INP_PWORD
         elif char == 51:  # N
             self.inp_win.cls()
             self.inp_win.prttxt(
                 str2zx(' please enter nickname: ', inverse=True))
             self.ed = LinEd(self.inp_win, 0, 1, 29, 255,
                             bytes(str2zx(self.nick)))
             self.inp_mode = InpMode.INP_NICK
         elif char == 40:  # C
             self.inp_win.cls()
             self.inp_win.prttxt(
                 str2zx('   /join /part /quit /help', inverse=False))
             self.ed = LinEd(self.inp_win, 0, 1, 29, 255)
             self.connect()
         elif char == 61 or char == 117:  # x or break
             self.close()
             app.clear()
             # TODO clear threads
     elif self.inp_mode in (InpMode.INP_SRV, InpMode.INP_PORT,
                            InpMode.INP_PWORD, InpMode.INP_NICK):
         if char in (117, 118):  # enter,break
             if char == 118:  # enter
                 if self.inp_mode == InpMode.INP_SRV:
                     if self.ed.val.strip():
                         self.server = zx2str(self.ed.val, to_lower=True)
                 if self.inp_mode == InpMode.INP_NICK:
                     if self.ed.val.strip():
                         self.nick = zx2str(self.ed.val, to_lower=True)
                 elif self.inp_mode == InpMode.INP_PWORD:
                     self.pword = zx2str(self.ed.val, to_lower=True)
                 else:
                     try:
                         self.port = int(zx2str(self.ed.val))
                     except:
                         pass
             self.ed.close()
             self.ed = None
             self.inp_mode = InpMode.MENU
             self.choose_site()
         else:
             self.ed.kb_event(char)
     elif self.inp_mode == InpMode.ONLINE:
         if char == 118:  # enter
             s = zx2str(self.ed.val, to_lower=True).strip()
             self.ed.clear()
             if s.startswith("/q"):
                 self.listener.send('QUIT :bye\r\n')
                 time.sleep(0.1)
                 self.disconnect()
                 self.ed.close()
                 self.ed = None
                 self.inp_mode = InpMode.MENU
                 self.choose_site()
             elif s.startswith("/join ") and len(s.split()) == 2:
                 self.channel = '#' + s.split()[1]
                 self.listener.send('JOIN %s\r\n' % (self.channel))
             elif s.startswith("/part") and self.channel:
                 self.listener.send('PART %s\r\n' % (self.channel))
                 self.channel = ''
             elif s.startswith("/list"):
                 self.listener.send('LIST\r\n')
             elif s.startswith("/names"):
                 self.listener.send('NAMES %s\r\n' % (self.channel))
             elif s.startswith("/h"):
                 self.mainwin.cls()
                 z = str2zx('\n\n HELP on the irc client usage \n\n',
                            inverse=True)
                 z += str2zx(
                     '\n/JOIN <mychannel>  join channel\n      (just omit the hash tag)\n',
                     upper_inv=True)
                 z += str2zx('\n/PART   leave the channel\n',
                             upper_inv=True)
                 z += str2zx('\n/NAMES  show who is there\n',
                             upper_inv=True)
                 z += str2zx('\n/LIST   list all channels\n',
                             upper_inv=True)
                 z += str2zx('\n/QUIT   exit from server\n', upper_inv=True)
                 z += str2zx(
                     '\n after joining, type a message   to all users in that channel\n',
                     upper_inv=True)
                 z += str2zx('\n        have fun       \n', inverse=True)
                 self.mainwin.prttxt(z)
             elif s.startswith("/"):
                 z = str2zx('\n??? unknown cmd %s' % (s.strip()))
                 self.mainwin.prttxt(z)
             else:
                 self.listener.send('PRIVMSG %s :%s\r\n' %
                                    (self.channel, s))
                 z = str2zx('\n<%s> %s' % (self.nick, s.strip()))
                 self.mainwin.prttxt(z)
         else:
             self.ed.kb_event(char)
Esempio n. 8
0
    def kb_event(self, win, zxchar):
        #win.prtchar(zxchar)
        s = zx2str([zxchar])
        redraw = False
        if s in 'nN':
            self.show_offset += self.max_lines
            redraw = True
        elif zxchar == 12:  # break
            mwin = self.mgr.show_msg_win(str2zx("exit. bye."))
            raise Exception('Exit')
        elif s in 'pP':
            self.show_offset -= self.max_lines
            redraw = True
        elif s in 'uUxX':
            if self.cwd.parents:
                self.cwd = self.cwd.parents[0]
                self.get_dir()
                redraw = True
        elif s in 'hH':  # Home directory
            self.cwd = self.homecwd
            self.get_dir()
            redraw = True
        elif s in 'wW':
            self.mgr.show_dialog(str2zx('press NEWLINE', upper_inv=True))
        elif zxchar in self.f_index:
            ix = self.f_index.index(zxchar) + self.show_offset
            if ix < len(self.cwdfiles):
                fi = self.cwdfiles[ix]
                if fi.is_dir():
                    self.cwd = fi
                    self.get_dir()
                    redraw = True
                elif fi.suffix.lower() == '.p':
                    name = str(fi)
                    print("LOAD ", name)
                    mwin = self.mgr.show_msg_win(
                        str2zx("load %s .." % (fi.stem)))
                    mwin.close()
                    self.mgr.server.load_p_file(name)
                    #time.sleep(0.5) # todo remove, was just for diag
                elif fi.suffix.lower() == '.py':
                    mwin = self.mgr.show_msg_win(
                        str2zx("open %s .." % (fi.stem)))
                    try:
                        spath = self.cwdfiles[ix]
                        target = Path.cwd(
                        ) / 'apps' / 'tmp' / self.cwdfiles[ix].name
                        if spath != target: copyfile(str(spath), str(target))
                        print("Copy from ", str(spath))
                        print("Copy to ", str(target))
                        module = "apps.tmp." + fi.stem  # we are already in apps
                        newmod = importlib.import_module(module)
                        importlib.reload(newmod)
                        mwin.close()
                        newmod.start(self.mgr)
                    except Exception as e:
                        mwin.close()
                        print(e)
                        traceback.print_exc()
                        self.mgr.show_dialog(str2zx("error loading module"))
#                    eval("print(globals())")
#                   print("Eval GLOB",modcmd)
#                  eval("print(globals())", globals())
#                 r=eval(modcmd, globals())
#                print("LOADed PYTHON ")
                elif fi.suffix.lower() in ('.zxscr', '.zxmovie'):
                    try:
                        apps.media_viewer.start(self.mgr, fi)
                    except Exception as e:
                        print(e)
                        traceback.print_exc()
                        self.mgr.show_dialog(str2zx("error showing file"))

        if redraw:

            self.show_offset = min(self.show_offset, len(self.cwdfiles) - 2)
            self.show_offset = max(0, self.show_offset)
            self.show_dir()