def main(): monitor.load_commands() monitor.load_folders() app = QtGui.QApplication(sys.argv) test = Main() test.show() sys.stdout = OutLog(test.ui.logTextEdit, sys.stdout) sys.stderr = OutLog(test.ui.logTextEdit, sys.stderr, QtGui.QColor(255, 100, 200)) monitor.start_monitor() app.exec_()
def main(): # load config config = load_config() _consumer_key = "" _consumer_secret = "" if config.has_section('client'): _consumer_key = config.get('client', '_consumer_key') _consumer_secret = config.get('client', '_consumer_secret') # init client client = Client(_consumer_key, _consumer_secret) # auth before use auth(client, config) if client.is_authed(): global local_path global g_ind if config.has_section('sync'): local_path = config.get('sync', 'local_path') if not local_path: home_dir = os.path.expanduser('~') default_dir = os.path.join(home_dir, "kuaipan") is_create_default = False if not os.path.exists(default_dir): is_create_default = True os.mkdir(default_dir) dialog = gtk.FileChooserDialog(title="请选择快盘文件同步到本地存放的文件夹", parent=None, action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER, buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN,gtk.RESPONSE_OK)) dialog.set_current_folder(default_dir) filter = gtk.FileFilter() filter.set_name("所有文件夹") filter.add_pattern("*") dialog.add_filter(filter) response = dialog.run() if response == gtk.RESPONSE_OK: print dialog.get_filename(), 'selected' local_path = dialog.get_filename() if is_create_default and local_path != default_dir: os.rmdir(default_dir) config.add_section('sync') config.set('sync', 'local_path', local_path) fp = open(get_cfg_path(), 'w') config.write(fp) else: print 'Closed, no files selected' dialog.destroy() if not local_path: return ac_info = client.get_account_info() print('is authed') print(ac_info) window = gtk.Window(gtk.WINDOW_TOPLEVEL) g_ind = init_indicator(ac_info, client) # start sync thread start_sync(client, local_path, g_ind) # start monitor thread start_monitor(client, local_path, g_ind) # start run application gtk.main() else: print('not authed')