⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 standalone.py

📁 PHP写的图片查看器
💻 PY
📖 第 1 页 / 共 2 页
字号:
        pass    print 'server stopped'# --- graphical interface: --------------------------------------------------def gui(port):    """Graphical interface (starts web server and pops up a control window)."""    class GUI:        def __init__(self, window, port):            self.window = window            self.server = None            self.scanner = None            import Tkinter            self.server_frm = Tkinter.Frame(window)            self.title_lbl = Tkinter.Label(self.server_frm,                text='Starting server...\n ')            self.open_btn = Tkinter.Button(self.server_frm,                text='open browser', command=self.open, state='disabled')            self.quit_btn = Tkinter.Button(self.server_frm,                text='quit serving', command=self.quit, state='disabled')            self.window.title('ViewCVS standalone')            self.window.protocol('WM_DELETE_WINDOW', self.quit)            self.title_lbl.pack(side='top', fill='x')            self.open_btn.pack(side='left', fill='x', expand=1)            self.quit_btn.pack(side='right', fill='x', expand=1)            # Early loading of configuration here.  Used to            # allow tinkering with configuration settings through the gui:            viewcvs.handle_config()            if not LIBRARY_DIR:                viewcvs.cfg.options.cvsgraph_conf = "../cgi/cvsgraph.conf.dist"            self.options_frm = Tkinter.Frame(window)            # cvsgraph toggle:            self.cvsgraph_ivar = Tkinter.IntVar()            self.cvsgraph_ivar.set(viewcvs.cfg.options.use_cvsgraph)            self.cvsgraph_toggle = Tkinter.Checkbutton(self.options_frm,                text="enable cvsgraph (needs binary)", var=self.cvsgraph_ivar,                command=self.toggle_use_cvsgraph)            self.cvsgraph_toggle.pack(side='top', anchor='w')            # enscript toggle:            self.enscript_ivar = Tkinter.IntVar()            self.enscript_ivar.set(viewcvs.cfg.options.use_enscript)            self.enscript_toggle = Tkinter.Checkbutton(self.options_frm,                text="enable enscript (needs binary)", var=self.enscript_ivar,                command=self.toggle_use_enscript)            self.enscript_toggle.pack(side='top', anchor='w')            # show_subdir_lastmod toggle:            self.subdirmod_ivar = Tkinter.IntVar()            self.subdirmod_ivar.set(viewcvs.cfg.options.show_subdir_lastmod)            self.subdirmod_toggle = Tkinter.Checkbutton(self.options_frm,                text="show subdir last mod (dir view)", var=self.subdirmod_ivar,                command=self.toggle_subdirmod)            self.subdirmod_toggle.pack(side='top', anchor='w')            # use_re_search toggle:            self.useresearch_ivar = Tkinter.IntVar()            self.useresearch_ivar.set(viewcvs.cfg.options.use_re_search)            self.useresearch_toggle = Tkinter.Checkbutton(self.options_frm,                text="allow regular expr search", var=self.useresearch_ivar,                command=self.toggle_useresearch)            self.useresearch_toggle.pack(side='top', anchor='w')            # directory view template:            self.dirtemplate_lbl = Tkinter.Label(self.options_frm,                text='Chooose HTML Template for the Directory pages:')            self.dirtemplate_lbl.pack(side='top', anchor='w')            self.dirtemplate_svar = Tkinter.StringVar()            self.dirtemplate_svar.set(viewcvs.cfg.templates.directory)            self.dirtemplate_entry = Tkinter.Entry(self.options_frm,                width = 40, textvariable=self.dirtemplate_svar)            self.dirtemplate_entry.bind('<Return>', self.set_templates_directory)            self.dirtemplate_entry.pack(side='top', anchor='w')            self.templates_dir = Tkinter.Radiobutton(self.options_frm,                text="directory.ezt", value="templates/directory.ezt",                 var=self.dirtemplate_svar, command=self.set_templates_directory)            self.templates_dir.pack(side='top', anchor='w')            self.templates_dir_alt = Tkinter.Radiobutton(self.options_frm,                text="dir_alternate.ezt", value="templates/dir_alternate.ezt",                 var=self.dirtemplate_svar, command=self.set_templates_directory)            self.templates_dir_alt.pack(side='top', anchor='w')            # log view template:            self.logtemplate_lbl = Tkinter.Label(self.options_frm,                text='Chooose HTML Template for the Log pages:')            self.logtemplate_lbl.pack(side='top', anchor='w')            self.logtemplate_svar = Tkinter.StringVar()            self.logtemplate_svar.set(viewcvs.cfg.templates.log)            self.logtemplate_entry = Tkinter.Entry(self.options_frm,                width = 40, textvariable=self.logtemplate_svar)            self.logtemplate_entry.bind('<Return>', self.set_templates_log)            self.logtemplate_entry.pack(side='top', anchor='w')            self.templates_log = Tkinter.Radiobutton(self.options_frm,                text="log.ezt", value="templates/log.ezt",                 var=self.logtemplate_svar, command=self.set_templates_log)            self.templates_log.pack(side='top', anchor='w')            self.templates_log_table = Tkinter.Radiobutton(self.options_frm,                text="log_table.ezt", value="templates/log_table.ezt",                 var=self.logtemplate_svar, command=self.set_templates_log)            self.templates_log_table.pack(side='top', anchor='w')            # query view template:            self.querytemplate_lbl = Tkinter.Label(self.options_frm,                text='Template for the database query page:')            self.querytemplate_lbl.pack(side='top', anchor='w')            self.querytemplate_svar = Tkinter.StringVar()            self.querytemplate_svar.set(viewcvs.cfg.templates.query)            self.querytemplate_entry = Tkinter.Entry(self.options_frm,                width = 40, textvariable=self.querytemplate_svar)            self.querytemplate_entry.bind('<Return>', self.set_templates_query)            self.querytemplate_entry.pack(side='top', anchor='w')            self.templates_query = Tkinter.Radiobutton(self.options_frm,                text="query.ezt", value="templates/query.ezt",                 var=self.querytemplate_svar, command=self.set_templates_query)            self.templates_query.pack(side='top', anchor='w')            # pack and set window manager hints:            self.server_frm.pack(side='top', fill='x')            self.options_frm.pack(side='top', fill='x')            self.window.update()            self.minwidth = self.window.winfo_width()            self.minheight = self.window.winfo_height()            self.expanded = 0            self.window.wm_geometry('%dx%d' % (self.minwidth, self.minheight))            self.window.wm_minsize(self.minwidth, self.minheight)            import threading            threading.Thread(target=serve, args=(port, self.ready)).start()        def toggle_use_cvsgraph(self, event=None):            viewcvs.cfg.options.use_cvsgraph = self.cvsgraph_ivar.get()        def toggle_use_enscript(self, event=None):            viewcvs.cfg.options.use_enscript = self.enscript_ivar.get()        def toggle_subdirmod(self, event=None):            viewcvs.cfg.options.show_subdir_lastmod = self.subdirmod_ivar.get()        def toggle_useresearch(self, event=None):            viewcvs.cfg.options.use_re_search = self.useresearch_ivar.get()        def set_templates_log(self, event=None):            viewcvs.cfg.templates.log = self.logtemplate_svar.get()        def set_templates_directory(self, event=None):            viewcvs.cfg.templates.directory = self.dirtemplate_svar.get()        def set_templates_query(self, event=None):            viewcvs.cfg.templates.query = self.querytemplate_svar.get()        def ready(self, server):            """used as callback parameter to the serve() function"""            self.server = server            self.title_lbl.config(                text='ViewCVS standalone server at\n' + server.url)            self.open_btn.config(state='normal')            self.quit_btn.config(state='normal')        def open(self, event=None, url=None):            """opens a browser window on the local machine"""            url = url or self.server.url            try:                import webbrowser                webbrowser.open(url)            except ImportError: # pre-webbrowser.py compatibility                if sys.platform == 'win32':                    os.system('start "%s"' % url)                elif sys.platform == 'mac':                    try:                        import ic                        ic.launchurl(url)                    except ImportError: pass                else:                    rc = os.system('netscape -remote "openURL(%s)" &' % url)                    if rc: os.system('netscape "%s" &' % url)        def quit(self, event=None):            if self.server:                self.server.quit = 1            self.window.quit()    import Tkinter    try:        gui = GUI(Tkinter.Tk(), port)        Tkinter.mainloop()    except KeyboardInterrupt:        pass# --- command-line interface: ----------------------------------------------def cli(argv):    """Command-line interface (looks at argv to decide what to do)."""    import getopt    class BadUsage(Exception): pass    try:        opts, args = getopt.getopt(argv[1:], 'gp:r:',             ['gui', 'port=', 'repository='])        for opt, val in opts:            if opt in ('-g', '--gui'):                options.start_gui = 1            elif opt in ('-r', '--repository'):                options.repository = val            elif opt in ('-p', '--port'):                try:                    options.port = int(val)                except ValueError:                    raise BadUsage        if options.start_gui:            gui(options.port)            return        elif options.port:            def ready(server):                print 'server ready at %s' % server.url            serve(options.port, ready)            return        raise BadUsage    except (getopt.error, BadUsage):        cmd = sys.argv[0]        port = options.port        print """ViewCVS standalone - a simple standalone HTTP-ServerUsage: %(cmd)s [ <options> ]Available Options:-p <port> or --port=<port>    Start an HTTP server on the given port on the local machine.    Default port is %(port)d.-r <path> or --repository=<path>    Specify another path for the default CVS repository "Development".    If you don't have your repository at /home/cvsroot you will need to    use this option or you have to install first and edit viewcvs.conf.-g or --gui    Pop up a graphical interface for serving and testing ViewCVS.""" % locals()if __name__ == '__main__':     if LIBRARY_DIR:        sys.path.insert(0, LIBRARY_DIR)    else:        sys.path[:0] = ['lib']        os.chdir('lib')    import viewcvs    import apache_icons    options = Options()    cli(sys.argv)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -