def invoke(self, context_: UIWindow.ActionContext) -> UIWindow.ActionResult: context = typing.cast( DocumentController.DocumentController.ActionContext, context_) application = typing.cast(Application, context.application) application.show_choose_project_dialog() return UIWindow.ActionResult(UIWindow.ActionStatus.FINISHED)
def show_new_project_dialog() -> None: NewProjectAction().invoke( UIWindow.ActionContext(self, None, None))
class OpenProjectAction(UIWindow.Action): action_id = "project.open_project" action_name = _("Open Project...") def invoke(self, context_: UIWindow.ActionContext) -> UIWindow.ActionResult: context = typing.cast( DocumentController.DocumentController.ActionContext, context_) application = typing.cast(Application, context.application) application.show_open_project_dialog() return UIWindow.ActionResult.FINISHED class ChooseProjectAction(UIWindow.Action): action_id = "project.choose_project" action_name = _("Choose Project...") def invoke(self, context_: UIWindow.ActionContext) -> UIWindow.ActionResult: context = typing.cast( DocumentController.DocumentController.ActionContext, context_) application = typing.cast(Application, context.application) application.show_choose_project_dialog() return UIWindow.ActionResult.FINISHED UIWindow.register_action(NewProjectAction()) UIWindow.register_action(OpenProjectAction()) UIWindow.register_action(ChooseProjectAction())
def invoke(self, context: UIWindow.ActionContext) -> UIWindow.ActionResult: context = typing.cast( DocumentController.DocumentController.ActionContext, context) class NewProjectDialog(Dialog.ActionDialog): def __init__(self, ui, app: Application, event_loop: asyncio.AbstractEventLoop, profile: Profile.Profile): super().__init__(ui, title=_("New Project"), app=app, persistent_id="new_project_dialog") self.directory = self.ui.get_persistent_string( "project_directory", self.ui.get_document_location()) project_base_name = _( "Nion Swift Project") + " " + datetime.datetime.now( ).strftime("%Y%m%d") project_base_index = 0 project_base_index_str = "" while os.path.exists( os.path.join( self.directory, project_base_name + project_base_index_str)): project_base_index += 1 project_base_index_str = " " + str(project_base_index) self.project_name = project_base_name + project_base_index_str def safe_request_close(): event_loop.call_soon(self.request_close) def handle_new_and_close(): app.create_project_reference( pathlib.Path(self.directory), self.__project_name_field.text) safe_request_close() return True column = self.ui.create_column_widget() directory_header_row = self.ui.create_row_widget() directory_header_row.add_spacing(13) directory_header_row.add( self.ui.create_label_widget(_("Projects Folder: "), properties={"font": "bold"})) directory_header_row.add_stretch() directory_header_row.add_spacing(13) show_directory_row = self.ui.create_row_widget() show_directory_row.add_spacing(26) directory_label = self.ui.create_label_widget(self.directory) show_directory_row.add(directory_label) show_directory_row.add_stretch() show_directory_row.add_spacing(13) choose_directory_row = self.ui.create_row_widget() choose_directory_row.add_spacing(26) choose_directory_button = self.ui.create_push_button_widget( _("Choose...")) choose_directory_row.add(choose_directory_button) choose_directory_row.add_stretch() choose_directory_row.add_spacing(13) project_name_header_row = self.ui.create_row_widget() project_name_header_row.add_spacing(13) project_name_header_row.add( self.ui.create_label_widget(_("Project Name: "), properties={"font": "bold"})) project_name_header_row.add_stretch() project_name_header_row.add_spacing(13) project_name_row = self.ui.create_row_widget() project_name_row.add_spacing(26) project_name_field = self.ui.create_line_edit_widget( properties={"width": 400}) project_name_field.text = self.project_name project_name_field.on_return_pressed = handle_new_and_close project_name_field.on_escape_pressed = safe_request_close project_name_row.add(project_name_field) project_name_row.add_stretch() project_name_row.add_spacing(13) column.add_spacing(12) column.add(directory_header_row) column.add_spacing(8) column.add(show_directory_row) column.add_spacing(8) column.add(choose_directory_row) column.add_spacing(16) column.add(project_name_header_row) column.add_spacing(8) column.add(project_name_row) column.add_stretch() column.add_spacing(16) def choose() -> None: existing_directory, directory = self.ui.get_existing_directory_dialog( _("Choose Project Directory"), self.directory) if existing_directory: self.directory = existing_directory directory_label.text = self.directory self.ui.set_persistent_string("project_directory", self.directory) choose_directory_button.on_clicked = choose self.add_button(_("Cancel"), lambda: True) self.add_button(_("Create Project"), handle_new_and_close) self.content.add(column) self.__project_name_field = project_name_field def show(self, *, size: Geometry.IntSize = None, position: Geometry.IntPoint = None) -> None: super().show(size=size, position=position) self.__project_name_field.focused = True self.__project_name_field.select_all() application = typing.cast(Application, context.application) new_project_dialog = NewProjectDialog(application.ui, application, application.event_loop, application.profile) new_project_dialog.show() return UIWindow.ActionResult(UIWindow.ActionStatus.FINISHED)