def run_game(): """运行图片选择游戏""" # 初始化屏幕对象 pygame.init() sp_settings = Settings() screen = pygame.display.set_mode( (sp_settings.screen_width, sp_settings.screen_height)) pygame.display.set_caption('Select Picture') # gf.generate_pictures(sp_settings) # 生成图片库(首次使用时需要) files = os.listdir('images') # 获取images下所有图片名称 # 加载所有图片 all_pictures = Group() selected_pictures = Group() unselected_pictures = Group() optional_pictures = Group() for file in files: pics = Pictures(sp_settings, screen, file) pics.update() all_pictures.add(pics) # 初始化剩余图片数量 stats = PicturesStats(len(all_pictures.sprites())) gf.choice_pictures(stats, all_pictures, selected_pictures, unselected_pictures, optional_pictures) # 提示信息 tips = Tips(sp_settings, screen, stats) # 统计图表 st_chart = Statistic(sp_settings, screen) # 弹出登录框 user_name = easygui.enterbox('Pls input you name...', title='') while not user_name: # 输入正确的名字或按cancel结束循环 if user_name is None: # cancel 退出程序 sys.exit() user_name = easygui.enterbox('Pls input you name...', title='') easygui.msgbox('Welcome %s' % (user_name, )) st_chart.load_history(user_name + '.txt') pygame.display.set_caption(user_name.title() + 'Select Picture ...') # 无限循环 while True: # 监听事件 gf.check_events(sp_settings, screen, stats, st_chart, all_pictures, user_name, selected_pictures, unselected_pictures, optional_pictures) gf.update_help_string(sp_settings, stats, optional_pictures) gf.update_tips(tips) gf.update_screen(sp_settings, screen, stats, tips, st_chart, all_pictures, selected_pictures, unselected_pictures, optional_pictures)
def exposure_pic(): # Get a single picture from an exposure if request.method == 'GET': image_name = request.args.get('image_name', None) pi_id = request.args.get('pi_id', None) expo_id = request.args.get('expo_id', None) if (image_name == None) and (pi_id == None) and (expo_id == None): data = request.get_json(force=True) image_name = data['image_name'] pi_id = data['pi_id'] expo_id = data['expo_id'] # Construct filepath from information provided expo_dir = os.path.expanduser( '~') + '/Pictures/' + pi_id + '/' + expo_id # Send image from server to url return send_from_directory(expo_dir, image_name, as_attachment=True) # Add a new picture to an exposure if request.method == 'POST': # Grab required information from the request timestamp = request.form['timestamp'] filename = request.form['filename'] pi_id = request.form['pi_id'] expo_id = request.form['expo_id'] image_capture = request.files['photo'] # Check that the directory for the pi is on the server pi_base = os.path.expanduser('~') + '/Pictures/' pi_dir = pi_base + pi_id if not os.path.exists(pi_dir): os.makedirs(pi_dir) # Check that the specific exposure directory is there expo_base = os.path.expanduser('~') + '/Pictures/' + pi_id + '/' expo_dir = expo_base + expo_id if not os.path.exists(expo_dir): os.makedirs(expo_dir) # Create picture specific filepath pic_path = expo_dir + '/' + filename # Save image to server photos = UploadSet('photos', IMAGES) app.config['UPLOADED_PHOTOS_DEST'] = expo_dir configure_uploads(app, photos) photos.save(image_capture) # Save image information to database # Create and save new picture newPicture = Pictures(pic_path) session.add(newPicture) session.commit() # Save link to exposure_pictures newExposure = Exposures_Pictures(expo_id, newPicture.picture_id) session.add(newExposure) session.commit() ''' Uncomment this to put it back to previous # Update user to let them know new exposures user_pi = session.query(Pi).filter_by(pi_id=pi_id).one() user_id = row2dict(user_pi)['user_id'] updatedUser = session.query(Users).filter_by(user_id=user_id).one() updatedUser.updated = 1 session.commit() ''' return picture_schema.jsonify(newPicture) return
app.add_url_rule('/', view_func=Main.as_view('main'), methods=["GET"]) app.add_url_rule('/<page>/', view_func=Main.as_view('main'), methods=["GET"]) app.add_url_rule('/login/', view_func=Login.as_view('login'), methods=["GET", "POST"]) app.add_url_rule('/remote/', view_func=Remote.as_view('remote'), methods=['GET', 'POST']) app.add_url_rule('/music/', view_func=Music.as_view('music'), methods=['GET']) app.add_url_rule('/pictures/', view_func=Pictures.as_view('pictures'), methods=['GET']) @app.errorhandler(404) def page_not_found(error): return flask.render_template('404.html'), 404 app.debug = True app.run()
from menu import Menu from pictures import Pictures from magia import Magia from os import system #system("pause") #menu głowne które prowadzi nas do wyboru trybu MainMenu = Menu() MainMenu.WelcomeAutor() MainMenu.Introduction() choice = MainMenu.Menu() #wczytywanie obrazka #tryb 1 kodowanie Coder = Magia() PictureReader = Pictures() system("cls") if int(choice) == 1: image = PictureReader.readPicture() Coder.codeMsg(image) elif int(choice) == 2: image = PictureReader.readPicture() Coder.decodeMsg(image) #tryb 2 dekodowanie system("pause")