本文整理汇总了Python中BEE2_config.GEN_OPTS类的典型用法代码示例。如果您正苦于以下问题:Python GEN_OPTS类的具体用法?Python GEN_OPTS怎么用?Python GEN_OPTS使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GEN_OPTS类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: clear_caches
def clear_caches():
"""Wipe the cache times in configs.
This will force package resources to be extracted again.
"""
import gameMan
import packageLoader
restart_ok = messagebox.askokcancel(
title='Allow Restart?',
message='Restart the BEE2 to re-extract packages?',
)
if not restart_ok:
return
for game in gameMan.all_games:
game.mod_time = 0
game.save()
GEN_OPTS['General']['cache_time'] = '0'
for pack_id in packageLoader.packages:
packageLoader.PACK_CONFIG[pack_id]['ModTime'] = '0'
save() # Save any option changes..
gameMan.CONFIG.save_check()
GEN_OPTS.save_check()
packageLoader.PACK_CONFIG.save_check()
utils.restart_app()
示例2: refresh_cache
def refresh_cache(self):
"""Copy over the resource files into this game."""
screen_func = export_screen.step
copy2 = shutil.copy2
def copy_func(src, dest):
screen_func('RES')
copy2(src, dest)
for folder in os.listdir('../cache/resources/'):
source = os.path.join('../cache/resources/', folder)
if folder == 'instances':
dest = self.abs_path(INST_PATH)
elif folder.casefold() == 'bee2':
continue # Skip app icons
else:
dest = self.abs_path(os.path.join('bee2', folder))
LOGGER.info('Copying to "{}" ...', dest)
try:
shutil.rmtree(dest)
except (IOError, shutil.Error):
pass
shutil.copytree(source, dest, copy_function=copy_func)
LOGGER.info('Cache copied.')
# Save the new cache modification date.
self.mod_time = GEN_OPTS.get_int('General', 'cache_time', 0)
self.save()
CONFIG.save_check()
示例3: refresh_cache
def refresh_cache(self):
"""Copy over the resource files into this game."""
screen_func = export_screen.step
copy = shutil.copy
def copy_func(src, dest):
screen_func("RES")
copy(src, dest)
for folder in os.listdir("../cache/resources/"):
source = os.path.join("../cache/resources/", folder)
if not os.path.isdir(source):
continue # Skip DS_STORE, desktop.ini, etc.
if folder == "instances":
dest = self.abs_path(INST_PATH)
elif folder.casefold() == "bee2":
continue # Skip app icons
else:
dest = self.abs_path(os.path.join("bee2", folder))
LOGGER.info('Copying to "{}" ...', dest)
try:
shutil.rmtree(dest)
except (IOError, shutil.Error):
pass
# This handles existing folders, without raising in os.makedirs().
utils.merge_tree(source, dest, copy_function=copy_func)
LOGGER.info("Cache copied.")
# Save the new cache modification date.
self.mod_time = GEN_OPTS.get_int("General", "cache_time", 0)
self.save()
CONFIG.save_check()
示例4: load_after_export
def load_after_export():
"""Read the 'After Export' radio set."""
AFTER_EXPORT_ACTION.set(GEN_OPTS.get_int(
'General',
'after_export_action',
AFTER_EXPORT_ACTION.get()
))
示例5: load_opt
def load_opt():
"""Load the checkbox's values."""
var.set(GEN_OPTS.get_bool(
section,
item,
default,
))
示例6: check_cache
def check_cache(zip_list):
"""Check to see if any zipfiles are invalid, and if so extract the cache."""
global copy_process
from BEE2_config import GEN_OPTS
LOGGER.info('Checking cache...')
cache_packs = GEN_OPTS.get_int('General', 'cache_pack_count')
# We need to match the number of packages too, to account for removed ones.
cache_stale = (len(packageLoader.packages) == cache_packs) or any(
pack.is_stale()
for pack in
packageLoader.packages.values()
)
if not cache_stale:
# We've already done the copying..
LOGGER.info('Cache is still fresh, skipping extraction')
done_callback()
return
copy_process = multiprocessing.Process(
target=do_copy,
args=(zip_list, currently_done),
)
copy_process.daemon = True
LOGGER.info('Starting background extraction process!')
copy_process.start()
TK_ROOT.after(UPDATE_INTERVAL, update)
示例7: cache_valid
def cache_valid(self):
"""Check to see if the cache is valid."""
cache_time = GEN_OPTS.get_int('General', 'cache_time', 0)
if cache_time == self.mod_time:
LOGGER.info("Skipped copying cache!")
return True
LOGGER.info("Cache invalid - copying..")
return False
示例8: add_vars
def add_vars(data):
"""
Add the given stylevars to our list.
"""
global var_list
var_list = sorted(data, key=operator.attrgetter('id'))
for var in var_list:
var.default = GEN_OPTS.get_bool('StyleVar', var.id, var.default)
示例9: _send_msg
def _send_msg(self, command, *args):
"""Send a message to the daemon."""
_PIPE_MAIN_SEND.send((command, id(self), args))
# Check the messages coming back as well.
while _PIPE_MAIN_REC.poll():
command, arg = _PIPE_MAIN_REC.recv()
if command == 'main_set_compact':
# Save the compact state to the config.
GEN_OPTS['General']['compact_splash'] = '1' if arg else '0'
GEN_OPTS.save_check()
elif command == 'cancel':
# Mark this loadscreen as cancelled.
_SCREEN_CANCEL_FLAG[arg] = True
else:
raise ValueError('Bad command from daemon: ' + repr(command))
# If the flag was set for us, raise an exception - the loading thing
# will then stop.
if _SCREEN_CANCEL_FLAG[id(self)]:
_SCREEN_CANCEL_FLAG[id(self)] = False
LOGGER.info('User cancelled loading screen.')
raise Cancelled
示例10: update_modtimes
def update_modtimes():
"""Update the cache modification times, so next time we don't extract.
This should only be done if we've copied all the files.
"""
import time
from BEE2_config import GEN_OPTS
LOGGER.info('Setting modtimes..')
for pack in packageLoader.packages.values():
# Set modification times for each package.
pack.set_modtime()
# Reset package cache times for removed packages. This ensures they'll be
# detected if re-added.
for pak_id in packageLoader.PACK_CONFIG:
if pak_id not in packageLoader.packages:
packageLoader.PACK_CONFIG[pak_id]['ModTime'] = '0'
# Set the overall cache time to now.
GEN_OPTS['General']['cache_time'] = str(int(time.time()))
GEN_OPTS['General']['cache_pack_count'] = str(len(packageLoader.packages))
packageLoader.PACK_CONFIG.save()
GEN_OPTS.save()
示例11: add_vars
def add_vars(style_vars, styles):
"""
Add the given stylevars to our list.
"""
VAR_LIST.clear()
VAR_LIST.extend(
sorted(style_vars, key=operator.attrgetter('id'))
)
for var in VAR_LIST: # type: packageLoader.StyleVar
var.enabled = GEN_OPTS.get_bool('StyleVar', var.id, var.default)
for style in styles:
STYLES[style.id] = style
示例12: make_pane
def make_pane(tool_frame):
"""Create the styleVar pane.
"""
global window
window = SubPane(
TK_ROOT,
options=GEN_OPTS,
title='Style Properties',
name='style',
resize_y=True,
tool_frame=tool_frame,
tool_img=png.png('icons/win_stylevar'),
tool_col=2,
)
UI['style_can'] = Canvas(window, highlightthickness=0)
# need to use a canvas to allow scrolling
UI['style_can'].grid(sticky='NSEW')
window.rowconfigure(0, weight=1)
UI['style_scroll'] = ttk.Scrollbar(
window,
orient=VERTICAL,
command=UI['style_can'].yview,
)
UI['style_scroll'].grid(column=1, row=0, rowspan=2, sticky="NS")
UI['style_can']['yscrollcommand'] = UI['style_scroll'].set
canvas_frame = ttk.Frame(UI['style_can'])
frame_all = ttk.Labelframe(canvas_frame, text="All:")
frame_all.grid(row=0, sticky='EW')
frm_chosen = ttk.Labelframe(canvas_frame, text="Selected Style:")
frm_chosen.grid(row=1, sticky='EW')
ttk.Separator(
canvas_frame,
orient=HORIZONTAL,
).grid(row=2, sticky='EW', pady=(10, 5))
frm_other = ttk.Labelframe(canvas_frame, text="Other Styles:")
frm_other.grid(row=3, sticky='EW')
UI['stylevar_chosen_none'] = ttk.Label(
frm_chosen,
text='No Options!',
font='TkMenuFont',
justify='center',
)
UI['stylevar_other_none'] = ttk.Label(
frm_other,
text='None!',
font='TkMenuFont',
justify='center',
)
for pos, (var_id, name, default) in enumerate(styleOptions):
# Add the special stylevars which apply to all styles
tk_vars[var_id] = IntVar(
value=GEN_OPTS.get_bool('StyleVar', var_id, default)
)
checkbox_special[var_id] = ttk.Checkbutton(
frame_all,
variable=tk_vars[var_id],
text=name,
command=functools.partial(set_stylevar, var_id)
)
checkbox_special[var_id].grid(row=pos, column=0, sticky="W", padx=3)
for var in var_list:
tk_vars[var.id] = IntVar(value=var.default)
args = {
'variable': tk_vars[var.id],
'text': var.name,
'command': functools.partial(set_stylevar, var.id)
}
checkbox_chosen[var.id] = ttk.Checkbutton(frm_chosen, **args)
checkbox_other[var.id] = ttk.Checkbutton(frm_other, **args)
UI['style_can'].create_window(0, 0, window=canvas_frame, anchor="nw")
UI['style_can'].update_idletasks()
UI['style_can'].config(
scrollregion=UI['style_can'].bbox(ALL),
width=canvas_frame.winfo_reqwidth(),
)
ttk.Sizegrip(
window,
cursor="sb_v_double_arrow",
).grid(row=1, column=0)
UI['style_can'].bind('<Configure>', flow_stylevar)
# Scroll globally even if canvas is not selected.
window.bind(
"<MouseWheel>",
lambda e: scroll(int(-1*(e.delta/120))),
)
window.bind(
"<Button-4>",
#.........这里部分代码省略.........
示例13: quit_command
def quit_command():
from BEE2_config import GEN_OPTS
window.withdraw()
GEN_OPTS.save_check()
示例14: init_backup_settings
def init_backup_settings():
"""Initialise the auto-backup settings widget."""
from BEE2_config import GEN_OPTS
check_var = tk.IntVar(
value=GEN_OPTS.get_bool('General', 'enable_auto_backup')
)
count_value = GEN_OPTS.get_int('General', 'auto_backup_count', 0)
back_dir = GEN_OPTS.get_val('Directories', 'backup_loc', 'backups/')
def check_callback():
GEN_OPTS['General']['enable_auto_backup'] = utils.bool_as_int(
check_var.get()
)
def count_callback():
GEN_OPTS['General']['auto_backup_count'] = str(count.value)
def directory_callback(path):
GEN_OPTS['Directories']['backup_loc'] = path
UI['auto_frame'] = frame = ttk.LabelFrame(
window,
)
UI['auto_enable'] = enable_check = ttk.Checkbutton(
frame,
text='Automatic Backup After Export',
variable=check_var,
command=check_callback,
)
frame['labelwidget'] = enable_check
frame.grid(row=2, column=0, columnspan=3)
dir_frame = ttk.Frame(
frame,
)
dir_frame.grid(row=0, column=0)
ttk.Label(
dir_frame,
text='Directory',
).grid(row=0, column=0)
UI['auto_dir'] = tk_tools.FileField(
dir_frame,
loc=back_dir,
is_dir=True,
callback=directory_callback,
)
UI['auto_dir'].grid(row=1, column=0)
count_frame = ttk.Frame(
frame,
)
count_frame.grid(row=0, column=1)
ttk.Label(
count_frame,
text='Keep (Per Game):'
).grid(row=0, column=0)
count = tk_tools.ttk_Spinbox(
count_frame,
range=range(50),
command=count_callback,
)
count.grid(row=1, column=0)
count.value = count_value
示例15: auto_backup
def auto_backup(game: 'gameMan.Game', loader: LoadScreen):
"""Perform an automatic backup for the given game.
We do this seperately since we don't need to read the property files.
"""
from BEE2_config import GEN_OPTS
if not GEN_OPTS.get_bool('General', 'enable_auto_backup'):
# Don't backup!
loader.skip_stage(AUTO_BACKUP_STAGE)
return
folder = find_puzzles(game)
if not folder:
loader.skip_stage(AUTO_BACKUP_STAGE)
return
# Keep this many previous
extra_back_count = GEN_OPTS.get_int('General', 'auto_backup_count', 0)
to_backup = os.listdir(folder)
backup_dir = GEN_OPTS.get_val('Directories', 'backup_loc', 'backups/')
os.makedirs(backup_dir, exist_ok=True)
# A version of the name stripped of special characters
# Allowed: a-z, A-Z, 0-9, '_-.'
safe_name = utils.whitelist(
game.name,
valid_chars=BACKUP_CHARS,
)
loader.set_length(AUTO_BACKUP_STAGE, len(to_backup))
if extra_back_count:
back_files = [
AUTO_BACKUP_FILE.format(game=safe_name, ind='')
] + [
AUTO_BACKUP_FILE.format(game=safe_name, ind='_'+str(i+1))
for i in range(extra_back_count)
]
# Move each file over by 1 index, ignoring missing ones
# We need to reverse to ensure we don't overwrite any zips
for old_name, new_name in reversed(
list(zip(back_files, back_files[1:]))
):
LOGGER.info(
'Moving: {old} -> {new}',
old=old_name,
new=new_name,
)
old_name = os.path.join(backup_dir, old_name)
new_name = os.path.join(backup_dir, new_name)
try:
os.remove(new_name)
except FileNotFoundError:
pass # We're overwriting this anyway
try:
os.rename(old_name, new_name)
except FileNotFoundError:
pass
final_backup = os.path.join(
backup_dir,
AUTO_BACKUP_FILE.format(game=safe_name, ind=''),
)
LOGGER.info('Writing backup to "{}"', final_backup)
with open(final_backup, 'wb') as f:
with ZipFile(f, mode='w', compression=ZIP_LZMA) as zip_file:
for file in to_backup:
zip_file.write(
os.path.join(folder, file),
file,
ZIP_LZMA,
)
loader.step(AUTO_BACKUP_STAGE)