def routine_from_shortcut(self, shortcut): search = list(filter( lambda r: self.bindings[r] == shortcut, self.bindings)) if len(search) > 0: return actions.get_routine(search[0]) return None
def _invoke(self, routine_key): # Things get slightly complicated, we need to use the key to # access the actual method in the current program context # the method as returned by global actions module is a Routine object routine = actions.get_routine(routine_key) if routine: routine.invoke()
def upgrade(self, version): try: # run formation cli upgrade command proc_info = subprocess.run([sys.executable, "-m", "studio", "-u"], capture_output=True) if proc_info.returncode != 0 or proc_info.stderr: self.show_error_plain( "Something went wrong. Failed to upgrade formation-studio" f" to version {version} ," f" Exited with code: {proc_info.returncode}") if proc_info.stderr: self.extra_info.config(state="normal") self.extra_info.pack(side="top", fill="x", padx=20, pady=10) self.extra_info.clear() self.extra_info.set(str(proc_info.stderr)) self.extra_info.config(state="disabled") else: self.show_info( "Upgrade successful. Restart to complete installation") self.show_button( "Restart", lambda _: get_routine("STUDIO_RESTART").invoke()) return except Exception as e: self.show_error_plain(e) self.show_button("Retry", lambda _: self.install(version))
def commit(self): super().commit() for action, key in self.bindings.items(): routine = actions.get_routine(action) if routine: routine.shortcut = key for instance in ShortcutManager.instances: instance.update_bindings()
def render(self): self.key_label = Label(self, text=self.value[1].label, **self.style.dark_text_accent) self.key_label.pack(side="right") routine = actions.get_routine(self.value[0]) self.desc = Label(self, text=routine.desc, **self.style.dark_text) self.desc.pack(side="left")
def restart(): exit_success = actions.get_routine("STUDIO_EXIT").invoke() if not exit_success: return pref._release() # allow some time before starting time.sleep(2) python = sys.executable os.execl(python, python, sys.argv[0])
def pick_key(self): if self.shortcut_list.get(): item = self.shortcut_list.get() routine = actions.get_routine(item.value[0]) key = ShortcutPicker.pick(self.window, routine.desc, self) if key: # overwrite any present bindings by replacing with blank key overwritten = self.routine_from_shortcut(key) overwritten_item = self.get_item(key) if overwritten: self.bindings[overwritten.key] = BlankKey if overwritten_item: overwritten_item.set_key(BlankKey) self.bindings[routine.key] = key item.set_key(key)
def _load_design(self, path, progress=None): # Loading designs is elaborate so better do it on its own thread # Capture any errors that occur while loading # This helps the user single out syntax errors and other value errors try: self.design_path = path self.root_obj = self.builder.load(path, self) self.context.on_load_complete() except Exception as e: self.clear() self.studio.on_session_clear(self) accelerator = actions.get_routine("STUDIO_RELOAD").accelerator text = f"{str(e)}\nPress {accelerator} to reload" if accelerator else f"{str(e)} \n reload design" self._show_empty(True, text=text, image=get_tk_image("dialog_error", 50, 50)) # MessageDialog.show_error(parent=self.studio, title='Error loading design', message=str(e)) finally: if progress: progress.destroy() self._verify_version()
def remove_key(self): if self.shortcut_list.get(): item = self.shortcut_list.get() routine = actions.get_routine(item.value[0]) self.bindings[routine.key] = BlankKey item.set_key(BlankKey)
def apply_and_restart(self, *_): self.apply() get_routine("STUDIO_RESTART").invoke()