コード例 #1
0
 def file_new(self, force=False):
     if self.recording or (not force and not self.file_new_ask()): return
     ext = dict([(t, ext)
                 for (_, t, desc, ext) in self.FILE_TYPES])[self.outtype]
     if self.moviefile:
         moviefile = self.moviefile
     else:
         moviefile = os.path.join(self.tempdir,
                                  'pyvnc2swf-%d%s' % (os.getpid(), ext))
     self.info.filename = moviefile
     self.fp = None
     if self.outtype == 'vnc' or self.outtype == 'novnc':
         self.fp = file(self.info.filename, 'wb')
         self.client = RFBNetworkClientForRecordingWithTk(
             self.host,
             self.port,
             self.fp,
             pwdfile=self.pwdfile,
             preferred_encoding=self.preferred_encoding,
             debug=self.debug,
             outtype=self.outtype,
             info=self.info)
         self.stream = None
     else:
         self.stream = StreamFactory(self.outtype)(self.info)
         self.client = RFBNetworkClientWithTk(
             self.host,
             self.port,
             RFBStreamConverter(self.info, self.stream),
             pwdfile=self.pwdfile,
             preferred_encoding=self.preferred_encoding)
     self.set_status()
     return True
コード例 #2
0
def vnc2swf(info,
            outtype='swf5',
            host='localhost',
            port=5900,
            preferred_encoding=(0, ),
            subprocess=None,
            pwdfile=None,
            vncfile=None,
            debug=0,
            merge=False):
    fp = None
    if outtype == 'vnc' or outtype == 'novnc':
        if info.filename == '-':
            fp = sys.stdout
        else:
            fp = file(info.filename, 'wb')
        client = RFBNetworkClientForRecording(
            host,
            port,
            fp,
            pwdfile=pwdfile,
            preferred_encoding=preferred_encoding,
            debug=debug,
            outtype=outtype,
            info=info)
    else:
        stream = StreamFactory(outtype)(info, debug=debug)
        converter = RFBStreamConverter(info, stream, debug=debug)
        if vncfile:
            client = RFBFileParser(vncfile, converter, debug=debug)
        else:
            client = RFBNetworkClient(host,
                                      port,
                                      converter,
                                      pwdfile=pwdfile,
                                      preferred_encoding=preferred_encoding,
                                      debug=debug)
    try:
        client.init().auth().start()
    except socket.error, e:
        print >> stderr, 'Socket error:', e
コード例 #3
0
ファイル: vnc2swf.py プロジェクト: antlong/castro
 def file_new(self, force=False):
   if self.recording or (not force and not self.file_new_ask()): return
   ext = dict([ (t,ext) for (_,t,desc,ext) in self.FILE_TYPES ])[self.outtype]
   if self.moviefile:
     moviefile = self.moviefile
   else:
     moviefile = os.path.join(self.tempdir, 'pyvnc2swf-%d%s' % (os.getpid(), ext))
   self.info.filename = moviefile
   self.fp = None
   if self.outtype == 'vnc':
     self.fp = file(self.info.filename, 'wb')
     self.client = RFBNetworkClientForRecordingWithTk(
       self.host, self.port, self.fp, pwdfile=self.pwdfile,
       preferred_encoding=self.preferred_encoding)
     self.stream = None
   else:
     self.stream = StreamFactory(self.outtype)(self.info)
     self.client = RFBNetworkClientWithTk(
       self.host, self.port, RFBStreamConverter(self.info, self.stream),
       pwdfile=self.pwdfile,
       preferred_encoding=self.preferred_encoding)
   self.set_status()
   return True
コード例 #4
0
ファイル: vnc2swf.py プロジェクト: xtengf/Mikrokosmos
class VNC2SWFWithTk:

  FILE_TYPES = [
    ('Flash(v5)', 'swf5',  'Macromedia Flash Files', '.swf'),    # 0
    ('Flash(v7)', 'swf7',  'Macromedia Flash Files', '.swf'),    # 1
    ('FLV',       'flv',   'Macromedia Flash Video Files', '.flv'), # 3
    ('MPEG',      'mpeg',  'MPEG Files', '.mpeg'),               # 2
    ('VNCRec',    'vnc',   'VNCRec Files', '.vnc'),              # 4
    ]

  def __init__(self, tempdir, info,
               outtype='swf5', host='localhost', port=5900,
               preferred_encoding=(0,), subprocess=None, pwdfile=None,
               debug=0):
    self.tempdir = tempdir
    self.moviefile = info.filename
    self.info = info
    self.debug = debug
    self.preferred_encoding = preferred_encoding
    self.subprocess = subprocess
    self.pwdfile = pwdfile
    self.outtype = outtype
    self.host = host
    self.port = port
    self.recording = False
    self.exit_immediately = False
    self.root = Tkinter.Tk()
    self.root.title('vnc2swf.py')
    self.root.wm_protocol('WM_DELETE_WINDOW', self.file_exit)
    self.toggle_button = Tkinter.Button(master=self.root)
    self.toggle_button.pack(side=Tkinter.LEFT)
    self.status_label = Tkinter.Label(master=self.root, justify=Tkinter.LEFT)
    self.status_label.pack(side=Tkinter.LEFT)
    self.setup_menubar()
    self.file_new(True)
    return

  def frames(self):
    return self.stream and self.stream.output_frames

  # Set up the GUI components.
  def setup_menubar(self):

    def option_server():
      x = tkEntryDialog('Server', 'Server? (host:port)', pattern='^([^:/]+(:\d+)?|)$',
                        default='%s:%d' % (self.host, self.port), master=self.root).result
      if not x: return
      m = re.match(r'^([^:/]*)(:(\d+))?', x)
      if not m:
        tkMessageBox.showerror('Invalid address: %s' % x)
        return
      (host, port) = (m.group(1) or 'localhost', int(m.group(3) or '5900'))
      if host != self.host or port != self.port and self.file_new_ask():
        (self.host, self.port) = (host, port)
        self.file_new(True)
      return

    def option_framerate():
      x = tkEntryDialog('Framerate', 'Framerate? (fps)', pattern='^([1-9][.0-9]+|)$',
                        default=self.info.framerate, master=self.root).result
      if not x: return
      framerate = float(x)
      if framerate != self.info.framerate and self.file_new_ask():
        self.info.framerate = framerate
        self.file_new(True)
      return

    def option_clipping():
      try:
        s = self.info.get_clipping()
      except ValueError:
        s = ''
      x = tkEntryDialog('Clipping', 'Clipping? (ex. 640x480+0+0)',
                        pattern='^(\d+x\d+\+\d+\+\d+|)$',
                        default=s, master=self.root).result
      if not x: return
      if x != s and self.file_new_ask():
        self.info.set_clipping(x)
        self.file_new(True)
      return

    record_type = Tkinter.StringVar(self.root)
    record_type.set(self.outtype)
    def option_type():
      if record_type.get() != self.outtype and self.file_new_ask():
        self.outtype = record_type.get()
        self.file_new()
      else:
        record_type.set(self.outtype)
      return

    menubar = Tkinter.Menu(self.root)
    self.file_menu = Tkinter.Menu(menubar, tearoff=0)
    self.file_menu.add_command(label="New...", underline=0, command=self.file_new, accelerator='Alt-N')
    self.file_menu.add_command(label="Save as...", underline=0, command=self.file_saveas, accelerator='Alt-S')
    self.file_menu.add_separator()
    self.file_menu.add_command(label="Exit", underline=1, command=self.file_exit)
    self.option_menu = Tkinter.Menu(menubar, tearoff=0)
    self.option_menu.add_command(label="Server...", underline=0, command=option_server)
    self.option_menu.add_command(label="Clipping...", underline=0, command=option_clipping)
    self.option_menu.add_command(label="Framerate...", underline=0, command=option_framerate)
    type_submenu = Tkinter.Menu(self.option_menu, tearoff=0)
    for (k,v,_,_) in self.FILE_TYPES:
      type_submenu.add_radiobutton(label=k, value=v, variable=record_type, command=option_type)
    self.option_menu.add_cascade(label="Type", underline=0, menu=type_submenu)
    menubar.add_cascade(label="File", underline=0, menu=self.file_menu)
    menubar.add_cascade(label="Option", underline=0, menu=self.option_menu)
    self.root.config(menu=menubar)
    self.root.bind('<Alt-n>', lambda e: self.file_new())
    self.root.bind('<Alt-s>', lambda e: self.file_saveas())
    return

  # Change the current status of UI.
  def set_status(self):

    def enable_menus(state):
      self.file_menu.entryconfig(0, state=state) # "File->New..."
      self.option_menu.entryconfig(0, state=state) # "Option->Server..."
      self.option_menu.entryconfig(1, state=state) # "Option->Clipping..."
      self.option_menu.entryconfig(2, state=state) # "Option->Framerate..."
      self.option_menu.entryconfig(3, state=state) # "Option->Type"
      return

    # "File->Save As..."
    if not self.recording and self.frames():
      self.file_menu.entryconfig(1, state='normal')
    else:
      self.file_menu.entryconfig(1, state='disabled')

    s = []
    if not self.recording:
      s.append('Ready (%d frames recorded).' % (self.frames() or 0))
      self.toggle_button.config(text='Start', underline=0)
      self.toggle_button.config(background='#80ff80', activebackground='#00ff00')
      self.toggle_button.config(command=self.record)
      self.root.bind('<s>', lambda e: self.record())
      self.root.bind('<space>', lambda e: self.record())
      enable_menus('normal')
    else:
      s.append('Recording.')
      self.toggle_button.config(text='Stop', underline=0)
      self.toggle_button.config(background='#ff8080', activebackground='#ff0000')
      self.toggle_button.config(command=self.client.interrupt)
      self.root.bind('<s>', lambda e: self.client.interrupt())
      self.root.bind('<space>', lambda e: self.client.interrupt())
      enable_menus('disabled')
    if self.host != 'localhost' or self.port != 5900:
      s.append('Server: %s:%d' % (self.host, self.port))
    if self.info.clipping:
      s.append('Clipping: %s' % self.info.get_clipping())
    if self.info.framerate:
      s.append('Framerate: %s' % self.info.framerate)
    self.status_label.config(text='\n'.join(s))
    return

  # File->New
  def file_new_ask(self):
    if self.frames():
      if not tkMessageBox.askokcancel('New file', 'Discard the current session?'):
        return False
    return True

  def file_new(self, force=False):
    if self.recording or (not force and not self.file_new_ask()): return
    ext = dict([ (t,ext) for (_,t,desc,ext) in self.FILE_TYPES ])[self.outtype]
    if self.moviefile:
      moviefile = self.moviefile
    else:
      moviefile = os.path.join(self.tempdir, 'pyvnc2swf-%d%s' % (os.getpid(), ext))
    self.info.filename = moviefile
    self.fp = None
    if self.outtype == 'vnc':
      self.fp = file(self.info.filename, 'wb')
      self.client = RFBNetworkClientForRecordingWithTk(
        self.host, self.port, self.fp, pwdfile=self.pwdfile,
        preferred_encoding=self.preferred_encoding)
      self.stream = None
    else:
      self.stream = StreamFactory(self.outtype)(self.info)
      self.client = RFBNetworkClientWithTk(
        self.host, self.port, RFBStreamConverter(self.info, self.stream),
        pwdfile=self.pwdfile,
        preferred_encoding=self.preferred_encoding)
    self.set_status()
    return True

  # File->SaveAs
  def file_saveas(self):
    if self.recording or not self.frames(): return
    (ext,desc) = dict([ (t,(ext,desc)) for (_,t,desc,ext) in self.FILE_TYPES ])[self.outtype]
    filename = tkFileDialog.asksaveasfilename(
      master=self.root, title='Vnc2swf Save As', defaultextension=ext,
      filetypes=[(desc,'*'+ext), ("All Files", "*")]
      )
    if not filename: return
    if self.stream:
      # Finish the movie.
      self.stream.close()
      self.stream = None
      if self.fp:
        self.fp.close()
        self.fp = None
    shutil.move(self.info.filename, filename)
    self.info.write_html(filename=filename)
    self.set_status()
    return

  # File->Exit
  def file_exit(self):
    if self.recording:
      self.client.interrupt()
      self.exit_immediately = True
    else:
      if self.frames():
        if not tkMessageBox.askokcancel('Exit', 'Discard the current session?'):
          return
      self.root.destroy()
    return

  # Do recording.
  def record(self):
    self.client.tk_init(self.root)
    try:
      self.client.init().auth().start()
    except socket.error, e:
      return self.error('Socket error', e)
    except RFBError, e:
      return self.error('RFB protocol error', e)