<commit_before>import os, sys, inspect
# realpath() will make the script run, even if you symlink it
cmd_folder = os.path.realpath(os.path.abspath(os.path.split(inspect.getfile( inspect.currentframe() ))[0]))
if cmd_folder not in sys.path:
    sys.path.insert(0, cmd_folder)
# to include modules from a subfolder
cmd_subfolder = os.path.realpath(os.path.abspath(os.path.join(os.path.split(inspect.getfile( inspect.currentframe() ))[0],"include")))
if cmd_subfolder not in sys.path:
    sys.path.insert(0, cmd_subfolder)


import datetime
import time
import picamera
import numpy as np
import cv2
import RPi.GPIO as GPIO
import patterns
import ConfigParser
import smbus
from BerryImu import BerryImu
from squid import *

zoom_step = 0.03

zoom_xy_min = 0.0
zoom_xy = 0.0
zoom_xy_max = 0.4

zoom_wh_min = 1.0
zoom_wh = 1.0
zoom_wh_max = 0.2



def update_zoom():
    #print "Setting camera to (%s, %s, %s, %s)" % (globals['zoom_xy'], globals['zoom_xy'], globals['zoom_wh'], globals['zoom_wh'])
    camera.zoom = (globals['zoom_xy'], globals['zoom_xy'], globals['zoom_wh'], globals['zoom_wh'])
    print "Camera at (x, y, w, h) = ", camera.zoom

def set_min_zoom():
    globals['zoom_xy'] = globals['zoom_xy_min']
    globals['zoom_wh'] = globals['zoom_wh_min']

def set_max_zoom():
    globals['zoom_xy'] = globals['zoom_xy_max']
    globals['zoom_wh'] = globals['zoom_wh_max']

def zoom_out():
    if globals['zoom_xy'] - globals['zoom_step'] < globals['zoom_xy_min']:
        set_min_zoom()
    else:
        globals['zoom_xy'] -= globals['zoom_step']
        globals['zoom_wh'] += (globals['zoom_step'] * 2)
    update_zoom()

def zoom_in():
    if globals['zoom_xy'] + globals['zoom_step'] > globals['zoom_xy_max']:
        set_max_zoom()
    else:
        globals['zoom_xy'] += globals['zoom_step']
        globals['zoom_wh'] -= (globals['zoom_step'] * 2)
    update_zoom()

def get_file_name():  # new
    return datetime.datetime.now().strftime("%Y-%m-%d_%H.%M.%S.h264")

gunRange = 30
alphaValue = 64

# subclass for ConfigParser to add comments for settings
# (adapted from jcollado's solution on stackoverflow)
class ConfigParserWithComments(ConfigParser.ConfigParser):<commit_msg>fixed globals issue<commit_after>import os, sys, inspect
# realpath() will make the script run, even if you symlink it
cmd_folder = os.path.realpath(os.path.abspath(os.path.split(inspect.getfile( inspect.currentframe() ))[0]))
if cmd_folder not in sys.path:
    sys.path.insert(0, cmd_folder)
# to include modules from a subfolder
cmd_subfolder = os.path.realpath(os.path.abspath(os.path.join(os.path.split(inspect.getfile( inspect.currentframe() ))[0],"include")))
if cmd_subfolder not in sys.path:
    sys.path.insert(0, cmd_subfolder)


import datetime
import time
import picamera
import numpy as np
import cv2
import RPi.GPIO as GPIO
import patterns
import ConfigParser
import smbus
from BerryImu import BerryImu
from squid import *

zooms = {

    'zoom_step' : 0.03

    'zoom_xy_min' : 0.0
    'zoom_xy' : 0.0
    'zoom_xy_max' : 0.4

    'zoom_wh_min' : 1.0
    'zoom_wh' : 1.0
    'zoom_wh_max' : 0.2

}

def update_zoom():
    #print "Setting camera to (%s, %s, %s, %s)" % (zooms['zoom_xy'], zooms['zoom_xy'], zooms['zoom_wh'], zooms['zoom_wh'])
    camera.zoom = (zooms['zoom_xy'], zooms['zoom_xy'], zooms['zoom_wh'], zooms['zoom_wh'])
    print "Camera at (x, y, w, h) = ", camera.zoom

def set_min_zoom():
    zooms['zoom_xy'] = zooms['zoom_xy_min']
    zooms['zoom_wh'] = zooms['zoom_wh_min']

def set_max_zoom():
    zooms['zoom_xy'] = zooms['zoom_xy_max']
    zooms['zoom_wh'] = zooms['zoom_wh_max']

def zoom_out():
    if zooms['zoom_xy'] - zooms['zoom_step'] < zooms['zoom_xy_min']:
        set_min_zoom()
    else:
        zooms['zoom_xy'] -= zooms['zoom_step']
        zooms['zoom_wh'] += (zooms['zoom_step'] * 2)
    update_zoom()

def zoom_in():
    if zooms['zoom_xy'] + zooms['zoom_step'] > zooms['zoom_xy_max']:
        set_max_zoom()
    else:
        zooms['zoom_xy'] += zooms['zoom_step']
        zooms['zoom_wh'] -= (zooms['zoom_step'] * 2)
    update_zoom()

def get_file_name():  # new
    return datetime.datetime.now().strftime("%Y-%m-%d_%H.%M.%S.h264")

gunRange = 30
alphaValue = 64

# subclass for ConfigParser to add comments for settings
# (adapted from jcollado's solution on stackoverflow)
class ConfigParserWithComments(ConfigParser.ConfigParser):
{'fraction_non_alphanumeric': 0.1537231612608497, 'fraction_numerical': 0.013248058474189127, 'mean_word_length': 4.426270136307311, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5473714', 'n_tokens_mistral': 1664, 'n_tokens_neox': 1608, 'n_words': 358}