def export_all(cls): try: dname = dialog.export_directory() p = state.get_state().get_project() try: p.export_prep(dname) except generic.ExportFileAlreadyExistsException: # TODO: ask user if they are ok with overwrite. pass p.export(dname) except generic.ExportException as e: dialog.popup_error("Export Failed", str(e)) return dialog.popup("Export", "Successful")
def add_entries(cls): fnames = dialog.load_images() if not fnames: return state.get_state().get_project().add_entity(fnames)
def new_project(cls): # TODO: ask user if they want to continue during pending changes state.get_state().reset_project()
def load_project(cls): fname = dialog.load_project() if not fname: return # TODO: ask user if they want to continue during pending changes state.get_state().load_new_project(fname)
def save_project(cls): fname = dialog.save_project() if not fname: return state.get_state().get_project().save_project(fname)
def draw(cls): root = window.Window.get_tk() p = state.get_state().get_project() # Menu bar menubar = tk.Menu( root, bg=COLOR_TITLE_BG, fg=COLOR_TITLE_FG, ) root.config(menu=menubar) m_file = tk.Menu(menubar, tearoff=0) menubar.add_cascade(label='File', menu=m_file) m_file.add_command(label='New Project', command=cls.new_project) # TODO: Currently we have "save as", we should also have simple save. m_file.add_command(label='Save Project', command=cls.save_project) m_file.add_command(label='Load Project', command=cls.load_project) m_file.add_separator() # TODO: human can export all where there # are unsaved changes for current image. m_file.add_command(label='Export All', command=cls.export_all) m_file.add_separator() m_file.add_command(label='Exit', command=cls._exit) m_help = tk.Menu(menubar, tearoff=0) menubar.add_cascade(label='Help', menu=m_help) # TODO: implement help support m_help.add_command(label='Get Started') m_help.add_command(label='About', command=cls.show_about) # Frames lframe = tk.Frame( root, borderwidth=ui.FRAME_BORDER, bg=COLOR_LEFT_BG, ) rframe = tk.Frame( root, borderwidth=ui.FRAME_BORDER, bg=COLOR_RIGHT_BG, ) lframe.place(relheight=1, relwidth=0.3, relx=0, rely=0) rframe.place(relheight=1, relwidth=0.7, relx=0.3, rely=0) # Left side tk.Button( lframe, text="Add entries", command=cls.add_entries, pady=ui.FRAME_BORDER, borderwidth=ui.FRAME_BORDER, ).pack(side=tk.TOP) for it, e in enumerate(p.get_entities()): cls.populate_entity(it, lframe, e) # Right Side selected_entity = None if cls.radio_selected_index >= 0 and cls.radio_selected_index < len( p.get_entities()): selected_entity = p.get_entities()[cls.radio_selected_index] cls.populate_entity_details(rframe, selected_entity)
def load_project(): fname = dialog.load_project() if not fname: return state.get_state().load_project(fname) window.Window.update_window(fillform.FillForm)
def new_project(): state.get_state().create_new_project() window.Window.update_window(fillform.FillForm)