def menu(self, menu: MenuData) -> MenuData: menu.setdefault(lang.get("menu_bar.file.menu_name"), {}).setdefault( "exit", {} ).setdefault( lang.get("menu_bar.file.close_world"), lambda evt: self._close_self_callback ) return self._extensions[self.GetSelection()].menu(menu)
def _open_world(self, path: str): """Open a world panel add add it to the notebook""" if path in self._open_worlds: self.world_tab_holder.SetSelection( self.world_tab_holder.GetPageIndex(self._open_worlds[path])) self._disable_enable() else: try: world = WorldPageUI(self.world_tab_holder, path, lambda: self.close_world(path)) except LoaderNoneMatched as e: log.error(f"Could not find a loader for this world.\n{e}") wx.MessageBox( f"{lang.get('select_world.no_loader_found')}\n{e}") except Exception as e: log.error(lang.get("select_world.loading_world_failed"), exc_info=True) dialog = TracebackDialog( self, lang.get("select_world.loading_world_failed"), str(e), traceback.format_exc(), ) dialog.ShowModal() dialog.Destroy() else: self._open_worlds[path] = world self._add_world_tab(world, world.world_name)
def menu(self, menu: MenuData) -> MenuData: menu.setdefault(lang.get("menu_bar.help.menu_name"), {}).setdefault( "control", {}).setdefault( lang.get("program_convert.menu_bar.help.user_guide"), lambda evt: self._help_controls(), ) return menu
def menu(self, menu: MenuData) -> MenuData: menu.setdefault(lang.get("menu_bar.file.menu_name"), {}).setdefault( "system", {} ).setdefault( f"{lang.get('program_3d_edit.menu_bar.file.save')}\tCtrl+s", lambda evt: self._canvas.save(), ) # menu.setdefault(lang.get('menu_bar.file.menu_name'), {}).setdefault('system', {}).setdefault('Save As', lambda evt: self.GetGrandParent().close_world(self.world.world_path)) menu.setdefault( lang.get("program_3d_edit.menu_bar.edit.menu_name"), {} ).setdefault("history", {}).update( { f"{lang.get('program_3d_edit.menu_bar.edit.undo')}\tCtrl+z": lambda evt: self._canvas.undo(), f"{lang.get('program_3d_edit.menu_bar.edit.redo')}\tCtrl+y": lambda evt: self._canvas.redo(), } ) menu.setdefault( lang.get("program_3d_edit.menu_bar.edit.menu_name"), {} ).setdefault("operation", {}).update( { f"{lang.get('program_3d_edit.menu_bar.edit.cut')}\tCtrl+x": lambda evt: self._canvas.cut(), f"{lang.get('program_3d_edit.menu_bar.edit.copy')}\tCtrl+c": lambda evt: self._canvas.copy(), f"{lang.get('program_3d_edit.menu_bar.edit.paste')}\tCtrl+v": lambda evt: self._canvas.paste_from_cache(), f"{lang.get('program_3d_edit.menu_bar.edit.delete')}\tDelete": lambda evt: self._canvas.delete(), } ) menu.setdefault( lang.get("program_3d_edit.menu_bar.edit.menu_name"), {} ).setdefault("shortcut", {}).update( { f"{lang.get('program_3d_edit.menu_bar.edit.goto')}\tCtrl+g": lambda evt: self._canvas.goto(), f"{lang.get('program_3d_edit.menu_bar.edit.select_all')}\tCtrl+A": lambda evt: self._canvas.select_all(), } ) menu.setdefault(lang.get("menu_bar.options.menu_name"), {}).setdefault( "options", {} ).setdefault( lang.get("program_3d_edit.menu_bar.options.controls"), lambda evt: self._edit_controls(), ) menu.setdefault(lang.get("menu_bar.options.menu_name"), {}).setdefault( "options", {} ).setdefault( lang.get("program_3d_edit.menu_bar.options.options"), lambda evt: self._edit_options(), ) menu.setdefault(lang.get("menu_bar.help.menu_name"), {}).setdefault( "help", {} ).setdefault( lang.get("program_3d_edit.menu_bar.help.controls"), lambda evt: self._help_controls(), ) return menu
def __init__(self, parent, open_world_callback): super().__init__(parent) self._open_world_callback = open_world_callback self._sizer = wx.BoxSizer(wx.VERTICAL) self.SetSizer(self._sizer) text = wx.StaticText( self, wx.ID_ANY, lang.get("select_world.recent_worlds"), wx.DefaultPosition, wx.DefaultSize, 0, ) text.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL)) self._sizer.Add( text, 0, wx.ALL | wx.ALIGN_CENTER, 5, ) self._world_list = None self.rebuild()
def _on_close_app(self, evt): for path, page in list(self._open_worlds.items()): self.close_world(path) if self.world_tab_holder.GetPageCount() > 1: wx.MessageBox(lang.get("app.world_still_used")) else: evt.Skip()
def __init__(self, parent, open_world_callback): super(WorldSelectAndRecentUI, self).__init__(parent, wx.HORIZONTAL) self._open_world_callback = open_world_callback sizer = wx.BoxSizer(wx.VERTICAL) self.SetSizer(sizer) warning_text = wx.StaticText( self, label=lang.get("select_world.open_world_warning"), ) warning_text.SetFont(wx.Font(20, wx.DEFAULT, wx.NORMAL, wx.NORMAL)) sizer.Add(warning_text, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.TOP, 5) # bar bottom_sizer = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(bottom_sizer, 1, wx.EXPAND) left_sizer = wx.BoxSizer(wx.VERTICAL) bottom_sizer.Add(left_sizer, 1, wx.EXPAND) select_world = WorldSelectUI(self, self._update_recent) left_sizer.Add(select_world, 1, wx.ALL | wx.EXPAND, 5) right_sizer = wx.BoxSizer(wx.VERTICAL) bottom_sizer.Add(right_sizer, 1, wx.EXPAND) self._recent_worlds = RecentWorldUI(self, self._update_recent) right_sizer.Add(self._recent_worlds, 1, wx.EXPAND, 5)
def create_menu(self): menu_dict = {} menu_dict.setdefault(lang.get("menu_bar.file.menu_name"), {}).setdefault( "system", {} ).setdefault( lang.get("menu_bar.file.open_world"), lambda evt: self._show_open_world() ) # menu_dict.setdefault(lang.get('menu_bar.file.menu_name'), {}).setdefault('system', {}).setdefault('Create World', lambda: self.world.save()) menu_dict.setdefault(lang.get("menu_bar.file.menu_name"), {}).setdefault( "exit", {} ).setdefault(lang.get("menu_bar.file.quit"), lambda evt: self.Close()) menu_dict = self._last_page.menu(menu_dict) menu_bar = wx.MenuBar() for menu_name, menu_data in menu_dict.items(): menu = wx.Menu() separator = False for menu_section in menu_data.values(): if separator: menu.AppendSeparator() separator = True for menu_item_name, menu_item_options in menu_section.items(): callback = None menu_item_description = None wx_id = None if callable(menu_item_options): callback = menu_item_options elif isinstance(menu_item_options, tuple): if len(menu_item_options) >= 1: callback = menu_item_options[0] if len(menu_item_options) >= 2: menu_item_description = menu_item_options[1] if len(menu_item_options) >= 3: wx_id = menu_item_options[2] else: continue if not menu_item_description: menu_item_description = "" if not wx_id: wx_id = wx.ID_ANY menu_item: wx.MenuItem = menu.Append( wx_id, menu_item_name, menu_item_description ) self.Bind(wx.EVT_MENU, callback, menu_item) menu_bar.Append(menu, menu_name) self.SetMenuBar(menu_bar)
def _convert_event(self, evt): if self.out_world_path is None: wx.MessageBox(lang.get("program_convert.select_before_converting")) return self.convert_button.Disable() global work_count work_count += 1 thread_pool_executor.submit(self._convert_method)
def _open_world(self, evt): dir_dialog = wx.DirDialog( None, lang.get("select_world.open_world_dialogue"), "", wx.DD_DEFAULT_STYLE | wx.DD_DIR_MUST_EXIST, ) try: if dir_dialog.ShowModal() == wx.ID_CANCEL: return path = dir_dialog.GetPath() except Exception: wx.LogError(lang.get("select_world.select_directory_failed")) return finally: dir_dialog.Destroy() self.open_world_callback(path)
def __init__(self, parent): wx.Frame.__init__( self, parent, id=wx.ID_ANY, title=f"Amulet V{__version__}", pos=wx.DefaultPosition, size=wx.Size(560, 400), style=wx.CAPTION | wx.CLOSE_BOX | wx.MINIMIZE_BOX | wx.MAXIMIZE_BOX | wx.MAXIMIZE | wx.SYSTEM_MENU | wx.TAB_TRAVERSAL | wx.CLIP_CHILDREN | wx.RESIZE_BORDER, ) self.locale = wx.Locale( wx.LANGUAGE_ENGLISH ) # TODO: work out proper localisation icon = wx.Icon() icon.CopyFromBitmap(image.logo.icon128.bitmap()) self.SetIcon(icon) self._open_worlds: Dict[str, CLOSEABLE_PAGE_TYPE] = {} self.world_tab_holder = flatnotebook.FlatNotebook( self, agwStyle=NOTEBOOK_MENU_STYLE ) self.world_tab_holder.Bind( flatnotebook.EVT_FLATNOTEBOOK_PAGE_CLOSING, self._on_page_close ) self._main_menu = AmuletMainMenu(self.world_tab_holder, self._open_world) self._last_page: BasePageUI = self._main_menu self._add_world_tab(self._main_menu, lang.get("main_menu.tab_name")) self.Bind(wx.EVT_CLOSE, self._on_close_app) self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self._page_change) if update_check: self.Bind( update_check.EVT_UPDATE_CHECK, lambda evt: update_check.show_update_window(self, __version__, evt), ) update_check.check_for_update(__version__, self) self.Show()
def __init__(self, parent, open_world_callback): super(WorldSelectUI, self).__init__(parent) self.open_world_callback = open_world_callback self.header = simple.SimplePanel(self, wx.HORIZONTAL) self.header_open_world = wx.Button(self.header, wx.ID_ANY, label=lang.get('open_world_button')) self.header_open_world.Bind(wx.EVT_BUTTON, self._open_world) self.header.add_object(self.header_open_world) self.add_object(self.header, 0, 0) self.content = ScrollableWorldsUI(self, open_world_callback) self.add_object(self.content, 1, wx.EXPAND)
def __init__(self, parent, current_version: str, new_version: str): wx.Dialog.__init__(self, parent) sizer_1 = wx.BoxSizer(wx.VERTICAL) static_text_1 = wx.StaticText( self, label=lang.get("update_check.newer_version_released")) static_text_2 = wx.StaticText( self, label=f"{lang.get('update_check.new_version')} v{new_version}") static_text_3 = wx.StaticText( self, label= f"{lang.get('update_check.current_version')} v{current_version}") sizer_1.Add(static_text_1, 0, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL, 5) sizer_1.Add(static_text_2, 0, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL, 5) sizer_1.Add(static_text_3, 0, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL, 5) sizer_2 = wx.BoxSizer(wx.HORIZONTAL) update_button = wx.Button(self, label=lang.get("update_check.update")) ok_button = wx.Button(self, label=lang.get("update_check.ok")) sizer_2.Add(update_button, 0, wx.ALL, 5) sizer_2.Add((0, 0), 1, wx.EXPAND, 5) sizer_2.Add(ok_button, 0, wx.ALL, 5) sizer_1.Add(sizer_2, 1, wx.EXPAND, 5) self.SetSizerAndFit(sizer_1) self.Centre() update_button.Bind( wx.EVT_BUTTON, lambda evt: self.goto_download_page(new_version, evt)) ok_button.Bind(wx.EVT_BUTTON, lambda evt: self.Close())
def __init__(self, parent, open_world_callback): super().__init__(parent) self.open_world_callback = open_world_callback sizer = wx.BoxSizer(wx.VERTICAL) self.SetSizer(sizer) self.header_open_world = wx.Button( self, label=lang.get("select_world.open_world_button")) self.header_open_world.Bind(wx.EVT_BUTTON, self._open_world) sizer.Add(self.header_open_world) content = ScrollableWorldsUI(self, open_world_callback) sizer.Add(content, 1, wx.EXPAND)
def __init__(self, parent, open_world_callback): super(RecentWorldUI, self).__init__(parent) self._open_world_callback = open_world_callback self.add_object( wx.StaticText( self, wx.ID_ANY, lang.get('recent_worlds'), wx.DefaultPosition, wx.DefaultSize, 0, ), 0, wx.ALL | wx.ALIGN_CENTER) self._world_list = None self.rebuild()
def __init__(self, parent: wx.Window, open_world_callback: Callable[[str], None]): super().__init__( parent, title=lang.get("select_world.title"), pos=wx.Point(50, 50), size=wx.Size(*[int(s * 0.95) for s in parent.GetSize()]), style=wx.CAPTION | wx.CLOSE_BOX | wx.MAXIMIZE_BOX # | wx.MAXIMIZE | wx.SYSTEM_MENU | wx.TAB_TRAVERSAL | wx.CLIP_CHILDREN | wx.RESIZE_BORDER, ) self.Bind(wx.EVT_CLOSE, self._hide_event) self._open_world_callback = open_world_callback self.world_select = WorldSelectAndRecentUI(self, self._run_callback)
def __init__(self, parent): wx.Frame.__init__( self, parent, id=wx.ID_ANY, title=f"Amulet V{version}", pos=wx.DefaultPosition, size=wx.Size(560, 400), style=wx.CAPTION | wx.CLOSE_BOX | wx.MINIMIZE_BOX | wx.MAXIMIZE_BOX | wx.MAXIMIZE | wx.SYSTEM_MENU | wx.TAB_TRAVERSAL | wx.CLIP_CHILDREN | wx.RESIZE_BORDER, ) self.locale = wx.Locale( wx.LANGUAGE_ENGLISH) # TODO: work out proper localisation icon = wx.Icon() icon.CopyFromBitmap( wx.Bitmap( os.path.join(os.path.dirname(__file__), 'img', 'icon64.png'), wx.BITMAP_TYPE_ANY)) self.SetIcon(icon) self._open_worlds: Dict[str, CLOSEABLE_PAGE_TYPE] = {} self.world_tab_holder = flatnotebook.FlatNotebook( self, agwStyle=NOTEBOOK_MENU_STYLE) self.world_tab_holder.Bind(flatnotebook.EVT_FLATNOTEBOOK_PAGE_CLOSING, self._on_page_close) self._main_menu = AmuletMainMenu(self.world_tab_holder, self._open_world) self._last_page: BaseWorldUI = self._main_menu self._add_world_tab(self._main_menu, lang.get('main_menu')) self.Bind(wx.EVT_CLOSE, self._on_close_app) self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self._page_change) self.Show()
def _output_world_callback(self, path): if path == self.world.world_path: wx.MessageBox( lang.get("program_convert.input_output_must_different")) return try: out_world_format = load_format(path) self.out_world_path = path except Exception: return for child in list(self._output.GetChildren())[1:]: child.Destroy() self._output.add_object(WorldUI(self._output, out_world_format), 0) self._output.Layout() self._output.Fit() self.Layout()
def __init__(self, parent: wx.Window, title: str, start: PointCoordinates): super().__init__(parent, title, wx.HORIZONTAL) x, y, z = start x_text = wx.StaticText(self, label=lang.get("program_3d_edit.goto_ui.x_label")) self.x = wx.SpinCtrlDouble(self, min=-30000000, max=30000000, initial=x) self.x.SetToolTip(lang.get("program_3d_edit.goto_ui.x_label_tooltip")) self.x.SetDigits(2) y_text = wx.StaticText(self, label=lang.get("program_3d_edit.goto_ui.y_label")) self.y = wx.SpinCtrlDouble(self, min=-30000000, max=30000000, initial=y) self.y.SetToolTip(lang.get("program_3d_edit.goto_ui.y_label_tooltip")) self.y.SetDigits(2) z_text = wx.StaticText(self, label=lang.get("program_3d_edit.goto_ui.z_label")) self.z = wx.SpinCtrlDouble(self, min=-30000000, max=30000000, initial=z) self.z.SetToolTip(lang.get("program_3d_edit.goto_ui.z_label_tooltip")) self.z.SetDigits(2) self.sizer.Add(x_text, 0, wx.CENTER | wx.ALL, 5) self.sizer.Add(self.x, 1, wx.CENTER | wx.TOP | wx.BOTTOM | wx.RIGHT, 5) self.sizer.Add(y_text, 0, wx.CENTER | wx.TOP | wx.BOTTOM | wx.RIGHT, 5) self.sizer.Add(self.y, 1, wx.CENTER | wx.TOP | wx.BOTTOM | wx.RIGHT, 5) self.sizer.Add(z_text, 0, wx.CENTER | wx.TOP | wx.BOTTOM | wx.RIGHT, 5) self.sizer.Add(self.z, 1, wx.CENTER | wx.TOP | wx.BOTTOM | wx.RIGHT, 5) self.x.Bind(wx.EVT_CHAR, self._on_text) self.y.Bind(wx.EVT_CHAR, self._on_text) self.z.Bind(wx.EVT_CHAR, self._on_text) copy_button = wx.BitmapButton( self, bitmap=image.icon.tablericons.copy.bitmap(20, 20) ) copy_button.Bind(wx.EVT_BUTTON, lambda evt: self._copy()) copy_button.SetToolTip(lang.get("program_3d_edit.goto_ui.copy_button_tooltip")) self.bottom_sizer.Insert(0, copy_button, 0, wx.ALL, 5) paste_button = wx.BitmapButton( self, bitmap=image.icon.tablericons.clipboard.bitmap(20, 20) ) paste_button.Bind(wx.EVT_BUTTON, lambda evt: self._paste()) paste_button.SetToolTip( lang.get("program_3d_edit.goto_ui.paste_button_tooltip") ) self.bottom_sizer.Insert(1, paste_button, 0, wx.TOP | wx.BOTTOM | wx.RIGHT, 5) self.Fit()
def __init__(self, parent, world: "World", close_self_callback: Callable[[], None]): wx.Panel.__init__(self, parent) self._sizer = wx.BoxSizer(wx.VERTICAL) self.SetBackgroundColour( tuple(int(v * 255) for v in EditCanvas.background_colour)) self.SetSizer(self._sizer) self._world = world self._canvas: Optional[EditCanvas] = None self._close_self_callback = close_self_callback self._sizer.AddStretchSpacer(1) self._temp_msg = wx.StaticText( self, label=lang.get("program_3d_edit.canvas.please_wait")) self._temp_msg.SetFont(wx.Font(40, wx.DECORATIVE, wx.NORMAL, wx.NORMAL)) self._sizer.Add(self._temp_msg, 0, flag=wx.ALIGN_CENTER_HORIZONTAL) self._temp_loading_bar = wx.Gauge(self, range=10000) self._sizer.Add(self._temp_loading_bar, 0, flag=wx.EXPAND) self._sizer.AddStretchSpacer(1)
def __init__(self, parent): wx.Frame.__init__( self, parent, id=wx.ID_ANY, title=f"Amulet V{version}", pos=wx.DefaultPosition, size=wx.Size(560, 400), style=wx.CAPTION | wx.CLOSE_BOX | wx.MINIMIZE_BOX | wx.MAXIMIZE_BOX | wx.MAXIMIZE | wx.SYSTEM_MENU | wx.TAB_TRAVERSAL | wx.CLIP_CHILDREN | wx.RESIZE_BORDER, ) icon = wx.Icon() icon.CopyFromBitmap(wx.Bitmap(os.path.join(os.path.dirname(__file__), 'img', 'icon64.png'), wx.BITMAP_TYPE_ANY)) self.SetIcon(icon) self._open_worlds: Dict[str, BaseWorldUI] = {} self.world_tab_holder = wx.Notebook( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, 0 ) self._main_menu = AmuletMainMenu(self.world_tab_holder, self._open_world) self._last_page: BaseWorldUI = self._main_menu self._add_world_tab( self._main_menu, lang.get('main_menu') ) self.Bind(wx.EVT_CLOSE, self._on_close) self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self._page_change) self.Show()
def _convert_method(self): global work_count try: out_world = load_format(self.out_world_path) log.info( f"Converting world {self.world.level_path} to {out_world.path}" ) out_world: WorldFormatWrapper out_world.open() self.world.save(out_world, self._update_loading_bar) out_world.close() message = lang.get("program_convert.conversion_completed") log.info( f"Finished converting world {self.world.level_path} to {out_world.path}" ) except Exception as e: message = f"Error during conversion\n{e}" log.error(message, exc_info=True) self._update_loading_bar(0, 100) self.convert_button.Enable() wx.MessageBox(message) work_count -= 1
def _paste_operation(self): if all(self._scale.value): fake_levels = self.canvas.renderer.fake_levels level_index: int = fake_levels.active_level_index if level_index is not None: render_level: RenderLevel = fake_levels.render_levels[ level_index] yield from paste_iter( self.canvas.world, self.canvas.dimension, render_level.level, render_level.dimension, self._location.value, self._scale.value, self._rotation.value, self._copy_air.GetValue(), self._copy_water.GetValue(), self._copy_lava.GetValue(), ) else: raise OperationSuccessful( lang.get("program_3d_edit.paste_tool.zero_scale_message"))
def show_goto( parent: wx.Window, x: float, y: float, z: float ) -> Optional[Tuple[float, float, float]]: dialog = GoTo(parent, lang.get("program_3d_edit.goto_ui.title"), (x, y, z)) if dialog.ShowModal() == wx.ID_OK: return dialog.location
def __init__(self, container, world: World): SimplePanel.__init__( self, container ) self.world = world self._close_world_button = wx.Button(self, wx.ID_ANY, label='Close World') self._close_world_button.Bind(wx.EVT_BUTTON, self._close_world) self.add_object(self._close_world_button, 0, wx.ALL | wx.CENTER) self._input = SimplePanel(self, wx.HORIZONTAL) self.add_object(self._input, 0, wx.ALL|wx.CENTER) self._input.add_object( wx.StaticText( self._input, wx.ID_ANY, 'Input World: ', wx.DefaultPosition, wx.DefaultSize, 0, ), 0, wx.ALL|wx.CENTER ) self._input.add_object( WorldUI(self._input, self.world.world_wrapper), 0, wx.ALL|wx.CENTER ) self._output = SimplePanel(self, wx.HORIZONTAL) self.add_object(self._output, 0, wx.ALL | wx.CENTER) self._output.add_object( wx.StaticText( self._output, wx.ID_ANY, 'Output World: ', wx.DefaultPosition, wx.DefaultSize, 0, ), 0, wx.ALL | wx.CENTER ) self._select_output_button = wx.Button(self, wx.ID_ANY, label='Select Output World') self._select_output_button.Bind(wx.EVT_BUTTON, self._show_world_select) self.add_object(self._select_output_button, 0, wx.ALL | wx.CENTER) self._convert_bar = SimplePanel(self, wx.HORIZONTAL) self.add_object(self._convert_bar, 0, wx.ALL | wx.CENTER) self.loading_bar = wx.Gauge( self._convert_bar, wx.ID_ANY, 100, wx.DefaultPosition, wx.DefaultSize, wx.GA_HORIZONTAL, ) self._convert_bar.add_object(self.loading_bar, options=wx.ALL | wx.EXPAND) self.loading_bar.SetValue(0) self.convert_button = wx.Button(self._convert_bar, wx.ID_ANY, label=lang.get('convert')) self._convert_bar.add_object(self.convert_button) self.convert_button.Bind(wx.EVT_BUTTON, self._convert_event) self.out_world_path = None
def __init__(self, container, world: BaseLevel, close_self_callback: Callable[[], None]): SimplePanel.__init__(self, container) self.world = world self._close_self_callback = close_self_callback self._close_world_button = wx.Button( self, wx.ID_ANY, label=lang.get("world.close_world")) self._close_world_button.Bind(wx.EVT_BUTTON, self._close_world) self.add_object(self._close_world_button, 0, wx.ALL | wx.CENTER) self._input = SimplePanel(self, wx.HORIZONTAL) self.add_object(self._input, 0, wx.ALL | wx.CENTER) self._input.add_object( wx.StaticText( self._input, wx.ID_ANY, "{}: ".format(lang.get("program_convert.input_world")), wx.DefaultPosition, wx.DefaultSize, 0, ), 0, wx.ALL | wx.CENTER, ) self._input.add_object(WorldUI(self._input, self.world.level_wrapper), 0, wx.ALL | wx.CENTER) self._output = SimplePanel(self, wx.HORIZONTAL) self.add_object(self._output, 0, wx.ALL | wx.CENTER) self._output.add_object( wx.StaticText( self._output, wx.ID_ANY, "{}: ".format(lang.get("program_convert.output_world")), wx.DefaultPosition, wx.DefaultSize, 0, ), 0, wx.ALL | wx.CENTER, ) self._select_output_button = wx.Button( self, wx.ID_ANY, label=lang.get("program_convert.select_output_world")) self._select_output_button.Bind(wx.EVT_BUTTON, self._show_world_select) self.add_object(self._select_output_button, 0, wx.ALL | wx.CENTER) self._convert_bar = SimplePanel(self, wx.HORIZONTAL) self.add_object(self._convert_bar, 0, wx.ALL | wx.CENTER) self.loading_bar = wx.Gauge( self._convert_bar, wx.ID_ANY, 100, wx.DefaultPosition, wx.DefaultSize, wx.GA_HORIZONTAL, ) self._convert_bar.add_object(self.loading_bar, options=wx.ALL | wx.EXPAND) self.loading_bar.SetValue(0) self.convert_button = wx.Button( self._convert_bar, wx.ID_ANY, label=lang.get("program_convert.convert_button"), ) self._convert_bar.add_object(self.convert_button) self.convert_button.Bind(wx.EVT_BUTTON, self._convert_event) self.out_world_path = None
def __init__(self, canvas: "EditCanvas"): wx.BoxSizer.__init__(self, wx.HORIZONTAL) DefaultBaseToolUI.__init__(self, canvas) self._selection = BlockSelectionBehaviour(self.canvas) self._inspect_block = InspectBlockBehaviour(self.canvas, self._selection) self._button_panel = wx.Panel(canvas) button_sizer = wx.BoxSizer(wx.VERTICAL) self._button_panel.SetSizer(button_sizer) def add_button(label: str, tooltip: str, action: Callable[[wx.PyEventBinder], None]): button = wx.Button(self._button_panel, label=label) button.SetToolTip(tooltip) button_sizer.Add(button, 0, wx.ALL | wx.EXPAND, 5) button.Bind(wx.EVT_BUTTON, action) add_button( lang.get("program_3d_edit.select_tool.delete_button"), lang.get("program_3d_edit.select_tool.delete_button_tooltip"), lambda evt: self.canvas.delete(), ) add_button( lang.get("program_3d_edit.select_tool.copy_button"), lang.get("program_3d_edit.select_tool.copy_button_tooltip"), lambda evt: self.canvas.copy(), ) add_button( lang.get("program_3d_edit.select_tool.cut_button"), lang.get("program_3d_edit.select_tool.cut_button_tooltip"), lambda evt: self.canvas.cut(), ) add_button( lang.get("program_3d_edit.select_tool.paste_button"), lang.get("program_3d_edit.select_tool.paste_button_tooltip"), lambda evt: self.canvas.paste_from_cache(), ) self.Add(self._button_panel, 0, wx.ALIGN_CENTER_VERTICAL) self._x1: wx.SpinCtrl = self._add_row( lang.get("program_3d_edit.select_tool.scroll_point_x1"), wx.SpinCtrl, min=-30000000, max=30000000, ) self._y1: wx.SpinCtrl = self._add_row( lang.get("program_3d_edit.select_tool.scroll_point_y1"), wx.SpinCtrl, min=-30000000, max=30000000, ) self._z1: wx.SpinCtrl = self._add_row( lang.get("program_3d_edit.select_tool.scroll_point_z1"), wx.SpinCtrl, min=-30000000, max=30000000, ) self._x1.Bind(wx.EVT_SPINCTRL, self._box_input_change) self._y1.Bind(wx.EVT_SPINCTRL, self._box_input_change) self._z1.Bind(wx.EVT_SPINCTRL, self._box_input_change) self._x1.SetValidator(IntValidator()) self._y1.SetValidator(IntValidator()) self._z1.SetValidator(IntValidator()) self._x2: wx.SpinCtrl = self._add_row( lang.get("program_3d_edit.select_tool.scroll_point_x2"), wx.SpinCtrl, min=-30000000, max=30000000, ) self._y2: wx.SpinCtrl = self._add_row( lang.get("program_3d_edit.select_tool.scroll_point_y2"), wx.SpinCtrl, min=-30000000, max=30000000, ) self._z2: wx.SpinCtrl = self._add_row( lang.get("program_3d_edit.select_tool.scroll_point_z2"), wx.SpinCtrl, min=-30000000, max=30000000, ) self._x2.Bind(wx.EVT_SPINCTRL, self._box_input_change) self._y2.Bind(wx.EVT_SPINCTRL, self._box_input_change) self._z2.Bind(wx.EVT_SPINCTRL, self._box_input_change) self._x2.SetValidator(IntValidator()) self._y2.SetValidator(IntValidator()) self._z2.SetValidator(IntValidator()) self._x1.Disable() self._y1.Disable() self._z1.Disable() self._x2.Disable() self._y2.Disable() self._z2.Disable() self._x1.SetToolTip( lang.get("program_3d_edit.select_tool.scroll_point_x1_tooltip")) self._y1.SetToolTip( lang.get("program_3d_edit.select_tool.scroll_point_y1_tooltip")) self._z1.SetToolTip( lang.get("program_3d_edit.select_tool.scroll_point_z1_tooltip")) self._x2.SetToolTip( lang.get("program_3d_edit.select_tool.scroll_point_x2_tooltip")) self._y2.SetToolTip( lang.get("program_3d_edit.select_tool.scroll_point_y2_tooltip")) self._z2.SetToolTip( lang.get("program_3d_edit.select_tool.scroll_point_z2_tooltip")) self._x1.SetBackgroundColour((160, 215, 145)) self._y1.SetBackgroundColour((160, 215, 145)) self._z1.SetBackgroundColour((160, 215, 145)) self._x2.SetBackgroundColour((150, 150, 215)) self._y2.SetBackgroundColour((150, 150, 215)) self._z2.SetBackgroundColour((150, 150, 215)) self._box_size_selector_fstring = lang.get( "program_3d_edit.select_tool.box_size_selector_fstring") try: box_size_fstring = self._box_size_selector_fstring.format(x=0, y=0, z=0) except: self._box_size_selector_fstring = "dx={x},dy={y},dz={z}" box_size_fstring = self._box_size_selector_fstring.format(x=0, y=0, z=0) self._box_size_selector_text = wx.StaticText( self._button_panel, label=box_size_fstring, style=wx.ALIGN_CENTER_HORIZONTAL) self._box_size_selector_text.SetToolTip( lang.get("program_3d_edit.select_tool.box_size_selector_tooltip")) button_sizer.Add(self._box_size_selector_text, 0, wx.ALL | wx.EXPAND, 5) self._box_volume_text = wx.StaticText(self._button_panel, label="0x0x0", style=wx.ALIGN_CENTER_HORIZONTAL) button_sizer.Add(self._box_volume_text, 0, wx.ALL | wx.EXPAND, 5) self._box_volume_text.SetToolTip( lang.get("program_3d_edit.select_tool.box_size_tooltip")) self._point1_move = Point1MoveButton( self._button_panel, self.canvas.camera, self.canvas.key_binds, lang.get("program_3d_edit.select_tool.button_point1"), lang.get("program_3d_edit.select_tool.button_point1_tooltip"), self._selection, ) self._point1_move.SetBackgroundColour((160, 215, 145)) self._point1_move.Disable() button_sizer.Add(self._point1_move, 0, wx.ALL | wx.EXPAND, 5) self._point2_move = Point2MoveButton( self._button_panel, self.canvas.camera, self.canvas.key_binds, lang.get("program_3d_edit.select_tool.button_point2"), lang.get("program_3d_edit.select_tool.button_point2_tooltip"), self._selection, ) self._point2_move.SetBackgroundColour((150, 150, 215)) self._point2_move.Disable() button_sizer.Add(self._point2_move, 0, wx.ALL | wx.EXPAND, 5) self._selection_move = SelectionMoveButton( self._button_panel, self.canvas.camera, self.canvas.key_binds, lang.get("program_3d_edit.select_tool.button_selection_box"), lang.get( "program_3d_edit.select_tool.button_selection_box_tooltip"), self._selection, ) self._selection_move.SetBackgroundColour((255, 255, 255)) self._selection_move.Disable() button_sizer.Add(self._selection_move, 0, wx.ALL | wx.EXPAND, 5)
def __init__(self, canvas: "EditCanvas"): wx.BoxSizer.__init__(self, wx.HORIZONTAL) DefaultBaseToolUI.__init__(self, canvas) self._selection = ChunkSelectionBehaviour(self.canvas) self._button_panel = wx.Panel(canvas) button_sizer = wx.BoxSizer(wx.VERTICAL) self._button_panel.SetSizer(button_sizer) y_sizer = wx.FlexGridSizer(2, 5, 5) button_sizer.Add(y_sizer, flag=wx.ALL, border=5) min_y_label = wx.StaticText( self._button_panel, label=lang.get("program_3d_edit.chunk_tool.min_y")) y_sizer.Add(min_y_label, flag=wx.ALIGN_CENTER) self._min_y = wx.SpinCtrl( self._button_panel, min=-30_000_000, max=30_000_000, initial=256, ) self._min_y.SetToolTip( lang.get("program_3d_edit.chunk_tool.min_y_tooltip")) y_sizer.Add(self._min_y, flag=wx.ALIGN_CENTER) self._min_y.Bind(wx.EVT_SPINCTRL, self._on_update_clipping) max_y_label = wx.StaticText( self._button_panel, label=lang.get("program_3d_edit.chunk_tool.max_y")) y_sizer.Add(max_y_label, flag=wx.ALIGN_CENTER) self._max_y = wx.SpinCtrl( self._button_panel, min=-30_000_000, max=30_000_000, initial=0, ) self._max_y.SetToolTip( lang.get("program_3d_edit.chunk_tool.max_y_tooltip")) y_sizer.Add(self._max_y, flag=wx.ALIGN_CENTER) self._max_y.Bind(wx.EVT_SPINCTRL, self._on_update_clipping) self._dimensions: Dict[Dimension, Tuple[int, int]] = {} delete_button = wx.Button( self._button_panel, label=lang.get("program_3d_edit.chunk_tool.delete_chunks"), ) delete_button.SetToolTip( lang.get("program_3d_edit.chunk_tool.delete_chunks_tooltip")) button_sizer.Add(delete_button, 0, wx.LEFT | wx.BOTTOM | wx.RIGHT | wx.EXPAND, 5) delete_button.Bind(wx.EVT_BUTTON, self._delete_chunks) prune_button = wx.Button( self._button_panel, label=lang.get("program_3d_edit.chunk_tool.prune_chunks"), ) prune_button.SetToolTip( lang.get("program_3d_edit.chunk_tool.prune_chunks_tooltip")) button_sizer.Add(prune_button, 0, wx.LEFT | wx.BOTTOM | wx.RIGHT | wx.EXPAND, 5) prune_button.Bind(wx.EVT_BUTTON, self._prune_chunks) self.Add(self._button_panel, 0, wx.ALIGN_CENTER_VERTICAL)
def get_java_dir(): if platform == "win32": return os.path.join(os.getenv('APPDATA'), '.minecraft') elif platform == "darwin": return os.path.expanduser('~/Library/Application Support/minecraft') else: return os.path.expanduser('~/.minecraft') def get_java_saves_dir(): return os.path.join(get_java_dir(), 'saves') minecraft_world_paths = {lang.get('java_platform'): get_java_saves_dir()} if platform == "win32": minecraft_world_paths[lang.get('bedrock_platform')] = os.path.join( os.getenv('LOCALAPPDATA'), 'Packages', 'Microsoft.MinecraftUWP_8wekyb3d8bbwe', 'LocalState', 'games', 'com.mojang', 'minecraftWorlds') world_images: Dict[str, Tuple[int, wx.Bitmap, int]] = {} def get_world_image(image_path: str) -> Tuple[wx.Bitmap, int]: if image_path not in world_images or world_images[image_path][ 0] != os.stat(image_path)[8]: img = wx.Image(image_path, wx.BITMAP_TYPE_ANY) width = min((img.GetWidth() / img.GetHeight()) * 128, 300)
import pkgutil import re from amulet.api.errors import LoaderNoneMatched from amulet import load_level import amulet_map_editor from amulet_map_editor import programs, log, lang from amulet_map_editor.api.datatypes import MenuData from amulet_map_editor.api.framework.pages import BasePageUI from amulet_map_editor.api.framework.programs import BaseProgram, AboutProgram from amulet_map_editor.api.wx.ui.traceback_dialog import TracebackDialog _extensions: List[Tuple[str, Type[BaseProgram]]] = [] _fixed_extensions: List[Tuple[str, Type[BaseProgram]]] = [ (lang.get("program_about.tab_name"), AboutProgram) ] def load_extensions(): if not _extensions: _extensions.extend(_fixed_extensions) prefix = f"{programs.__name__}." extensions = [] # source support for _, name, _ in pkgutil.iter_modules(programs.__path__, prefix): extensions.append(load_extension(name)) # pyinstaller support