Пример #1
0
def handle_config(args):
    try:
        pref = Preferences.acquire()
    except Preferences.ConfigFileInUseError:
        logger.error(
            "Config file currently in use. Close any open formation studio "
            "windows to continue."
        )
        sys.exit(1)
    except Exception:
        logger.error("Unable to open config files")
        sys.exit(1)

    param = args.config
    key = param[0].replace(".", "::")
    if pref.exists(key):
        if len(param) == 1:
            neat_print(pref.get(key))
        elif len(param) == 2:
            pref.set(key, _parse(param[1]))
        else:
            pref.set(key, [_parse(v) for v in param[1:]])
        sys.exit(0)
    logger.error("Key %s not found", param[0])
    sys.exit(1)
Пример #2
0
 def update_defaults(cls):
     pref = Preferences.acquire()
     path = "features::{}".format(cls.name)
     if not pref.exists(path):
         pref.set(path, copy.deepcopy(cls._defaults))
     else:
         pref.update_defaults(path, copy.deepcopy(cls._defaults))
Пример #3
0
def _clear_config():
    if not os.path.exists(dirs.user_config_dir):
        sys.exit(0)
    try:
        Preferences.acquire()
    except Preferences.ConfigFileInUseError:
        logger.error(
            "Config file currently in use. Close any open formation studio "
            "windows to continue."
        )
        sys.exit(1)
    except:
        pass
    try:
        shutil.rmtree(dirs.user_config_dir)
    except:
        logger.error("Could not delete config files")
Пример #4
0
    def __init__(self, master, studio=None, **cnf):
        if not self._var_init:
            self._init_var(studio)
        super().__init__(master, studio, **cnf)

        f = Frame(self, **self.style.surface)
        f.pack(side="top", fill="both", expand=True, pady=4)
        f.pack_propagate(0)

        self._widget_set = Spinner(self._header, width=150)
        self._widget_set.config(**self.style.no_highlight)
        self._widget_set.set_values(list(self.CLASSES.keys()))
        self._widget_set.pack(side="left")
        self._widget_set.on_change(self.collect_groups)
        self._select_pane = ScrolledFrame(f, width=150)
        self._select_pane.place(x=0, y=0, relwidth=0.4, relheight=1)

        self._search_btn = Button(self._header, image=get_icon_image("search", 15, 15), width=25, height=25,
                                  **self.style.button)
        self._search_btn.pack(side="right")
        self._search_btn.on_click(self.start_search)
        self._search_selector = Label(self._select_pane.body, **self.style.text, text="search", anchor="w")
        self._search_selector.configure(**self.style.hover)

        self._widget_pane = ScrolledFrame(f, width=150)
        self._select_pane.body.config(**self.style.surface)
        self._widget_pane.place(relx=0.4, y=0, relwidth=0.6, relheight=1)

        self._pool = {}
        self._selectors = []
        self._selected = None
        self._component_cache = None
        self._extern_groups = []
        self._widget = None
        self.collect_groups(self.get_pref("widget_set"))
        # add custom widgets config to settings
        templates.update(_widget_pref_template)
        self._custom_group = None
        self._custom_widgets = []
        Preferences.acquire().add_listener(self._custom_pref_path, self._init_custom)
        self._reload_custom()
Пример #5
0
 def write(self, path):
     """
     Writes contents of the designer to a file specified by path
     :param path: Path to file to be written to
     :return: String
     """
     file_loader = infer_format(path)
     pref = Preferences.acquire()
     pref_path = f"designer::{file_loader.name.lower()}"
     pref.set_default(pref_path, {})
     with open(path, 'w') as dump:
         # generate an upto-date tree first
         self.generate()
         dump.write(file_loader(node=self.root).generate(**pref.get(pref_path)))
Пример #6
0
    def __init__(self, master, studio, **cnf):
        super().__init__(master, studio, **cnf)
        self.setup_style_pane()

        pref: Preferences = Preferences.acquire()
        pref.add_listener("designer::descriptive_names",
                          lambda _: self.styles_for(self._current))

        self._identity_group = self.add_group(IdentityGroup)
        self._layout_group = self.add_group(LayoutGroup)
        self._attribute_group = self.add_group(AttributeGroup)

        self.add_group_instance(self._layout_group._grid_config.column_config)
        self.add_group_instance(self._layout_group._grid_config.row_config)
Пример #7
0
    ActionNotifier, TabView, Label
)
from hoverset.ui.icons import get_icon_image
from hoverset.data.images import load_tk_image
from hoverset.util.execution import Action
from hoverset.data.utils import get_resource_path
from hoverset.ui.dialogs import MessageDialog
from hoverset.ui.menu import MenuUtils, EnableIf, dynamic_menu, LoadLater
from hoverset.data import actions
from hoverset.data.keymap import ShortcutManager, CharKey, KeyMap, BlankKey
from hoverset.platform import platform_is, MAC

from formation import AppBuilder
from formation.formats import get_file_types

pref = Preferences.acquire()


class StudioApplication(Application):
    ICON_PATH = get_resource_path(studio, "resources/images/formation_icon.png")
    THEME_PATH = pref.get("resource::theme")

    def __init__(self, master=None, **cnf):
        super().__init__(master, **cnf)
        # Load icon asynchronously to prevent issues which have been known to occur when loading it synchronously
        icon_image = load_tk_image(self.ICON_PATH)
        self.load_styles(self.THEME_PATH)
        self.iconphoto(True, icon_image)
        self.pref = pref
        self._restore_position()
        self.title('Formation Studio')
Пример #8
0
 def _reload_custom(self):
     self._init_custom(Preferences.acquire().get(self._custom_pref_path))
Пример #9
0
 def set_pref(cls, short_path, value):
     Preferences.acquire().set(cls.get_pref_path(short_path), value)
Пример #10
0
 def get_pref(cls, short_path):
     return Preferences.acquire().get(cls.get_pref_path(short_path))
Пример #11
0
        cls._cache_icon_path = os.path.join(cache_path, "image")
        if style.colors["accent"] != cache_color \
                or not cls._cache_exists(cls._cache_icon_path)\
                or cls._cache_is_stale():
            if not os.path.exists(cache_path):
                make_path(cache_path)
            cls(pref).mainloop()

        set_image_resource_path(cls._cache_icon_path)
        pref.set("resource::icon_cache_color", style.colors["accent"])

    def check_resources(self):

        self._message("Preparing graphic resources...")
        with shelve.open(self._cache_icon_path) as cache:
            with shelve.open(self._default_icon_path) as defaults:
                color = parse_color(self.style.colors["accent"], self)
                step = 1 / len(defaults) * 1
                for image in defaults:
                    if not image.startswith("_"):
                        cache[image] = _recolor(defaults[image], color)
                    else:
                        cache[image] = defaults[image]
                    self.update_progress(step)


if __name__ == "__main__":

    from studio.preferences import Preferences
    ResourceLoader(Preferences.acquire()).mainloop()