diff --git a/__main__.py b/__main__.py index cef8a9c..5eca83d 100644 --- a/__main__.py +++ b/__main__.py @@ -1,6 +1,22 @@ +from wx import App, Locale + + +class StandAloneApp(App): + def __init__( + self, redirect=False, filename=None, useBestVisual=False, clearSigInt=True + ): + super().__init__(redirect, filename, useBestVisual, clearSigInt) + + def OnInit(self): + from kicad_amf_plugin.settings.setting_manager import SETTING_MANAGER + + self.locale = Locale(SETTING_MANAGER.get_language()) + return True + + if __name__ == "__main__": from kicad_amf_plugin.plugin._main import _main - from wx import App - app = App() + + app = StandAloneApp() _main() app.MainLoop() diff --git a/docs/place_order_new.gif b/docs/place_order_new.gif new file mode 100644 index 0000000..9a321aa Binary files /dev/null and b/docs/place_order_new.gif differ diff --git a/kicad_amf_plugin/gui/app_base.py b/kicad_amf_plugin/gui/app_base.py index a048b6a..fa30dfa 100644 --- a/kicad_amf_plugin/gui/app_base.py +++ b/kicad_amf_plugin/gui/app_base.py @@ -1,13 +1,12 @@ -from kicad_amf_plugin.language.lang_const import get_supported_language from kicad_amf_plugin.language.lang_const import LANG_DOMAIN from kicad_amf_plugin.settings.supported_layer_count import AVAILABLE_LAYER_COUNTS import builtins import sys import os from kicad_amf_plugin import PLUGIN_ROOT -from kicad_amf_plugin.gui.event.pcb_fabrication_evt_list import EVT_LOCALE_CHANGE from kicad_amf_plugin.kicad.board_manager import load_board_manager from kicad_amf_plugin.utils.combo_box_ignore_wheel import ComboBoxIgnoreWheel +from kicad_amf_plugin.icon import GetImagePath import wx # add translation macro to builtin similar to what gettext does @@ -23,17 +22,17 @@ def _displayHook(obj): class BaseApp(wx.EvtHandler): def __init__(self): super().__init__() - self.Bind(EVT_LOCALE_CHANGE, self.on_locale_changed) - # work around for Python stealing "_" sys.displayhook = _displayHook - self.locale = None wx.Locale.AddCatalogLookupPathPrefix( os.path.join(PLUGIN_ROOT, "language", "locale") ) + existing_locale = wx.GetLocale() + if existing_locale is not None: + existing_locale.AddCatalog(LANG_DOMAIN) def load_success(self): from kicad_amf_plugin.settings.setting_manager import SETTING_MANAGER - self.update_language(SETTING_MANAGER.language) + SETTING_MANAGER.register_app(self) self.board_manager = load_board_manager() if self.board_manager.board.GetCopperLayerCount() not in AVAILABLE_LAYER_COUNTS: @@ -41,40 +40,6 @@ def load_success(self): return False return True - def on_locale_changed(self, evt): - self.update_language(evt.GetInt()) - info = wx.MessageDialog( - self.main_wind, - _( - "Restart the plugin to apply the new locale ?\nFor full translation(including the options), restarting KiCad is required" - ), - _("Tip"), - wx.YES | wx.ICON_QUESTION | wx.NO, - ) - res = info.ShowModal() - info.Destroy() - if res == wx.ID_YES: - if self.main_wind: - self.main_wind.Destroy() - self.startup_dialog() - - def update_language(self, lang: int): - if lang in get_supported_language(): - selLang = lang - else: - wx.MessageBox(f"Unexpected language id {lang}") - selLang = wx.LANGUAGE_ENGLISH - if self.locale: - assert sys.getrefcount(self.locale) <= 2 - del self.locale - - self.locale = wx.Locale(selLang) - if self.locale.IsOk(): - self.locale.AddCatalog(LANG_DOMAIN) - else: - wx.MessageBox(self.locale.GetLocale() + _(" is not supported")) - self.locale = None - def startup_dialog(self): from kicad_amf_plugin.gui.main_frame import MainFrame from kicad_amf_plugin.settings.setting_manager import SETTING_MANAGER @@ -82,4 +47,5 @@ def startup_dialog(self): self.main_wind = MainFrame( self.board_manager, SETTING_MANAGER.get_window_size() ) + self.main_wind.SetIcon(wx.Icon(GetImagePath("Huaqiu.ico"))) self.main_wind.Show() diff --git a/kicad_amf_plugin/gui/main_frame.py b/kicad_amf_plugin/gui/main_frame.py index 4841cf6..7d38cde 100644 --- a/kicad_amf_plugin/gui/main_frame.py +++ b/kicad_amf_plugin/gui/main_frame.py @@ -1,5 +1,10 @@ from kicad_amf_plugin.gui.summary.price_summary_model import PriceCategory from kicad_amf_plugin.kicad.board_manager import BoardManager +from kicad_amf_plugin.kicad.fabrication_data_generator_evt import ( + EVT_BUTTON_FABRICATION_DATA_GEN_RES, + FabricationDataGenEvent, + GenerateStatus, +) from kicad_amf_plugin.order.supported_region import SupportedRegion from kicad_amf_plugin.pcb_fabrication.base.base_info_view import BaseInfoView from kicad_amf_plugin.pcb_fabrication.process.process_info_view import ProcessInfoView @@ -37,6 +42,7 @@ import webbrowser import json from kicad_amf_plugin.order.order_region import OrderRegion, URL_KIND +from kicad_amf_plugin.kicad.fabrication_data_generator_thread import DataGenThread from enum import Enum @@ -79,16 +85,33 @@ def __init__(self, board_manager: BoardManager, size, parent=None): ) self._board_manager = board_manager self._fabrication_data_gen = None + self._fabrication_data_gen_thread = None self._pcb_form_parts: "dict[PCBFormPart, FormPanelBase]" = {} + self._data_gen_progress: wx.ProgressDialog = None + self._dataGenThread: DataGenThread = None SINGLE_PLUGIN.register_main_wind(self) self.init_ui() + def show_data_gen_progress_dialog(self): + if self._data_gen_progress is not None: + self._data_gen_progress.Destroy() + self._data_gen_progress = None + self._data_gen_progress = wx.ProgressDialog( + _("Preparing for your order"), + _("The browser will be launched automatically while ready"), + maximum=GenerateStatus.MAX_PROGRESS, + parent=self, + style=0 | wx.PD_APP_MODAL, + ) + def init_ui(self): self.SetSizeHints(wx.DefaultSize, wx.DefaultSize) - main_sizer = wx.BoxSizer(wx.HORIZONTAL) + left_sizer = wx.BoxSizer(wx.HORIZONTAL) + self.main_splitter = wx.SplitterWindow(self, style=wx.SP_LIVE_UPDATE) + self.left_panel_container = wx.Panel(self.main_splitter) pcb_fab_scroll_wind = wx.ScrolledWindow( - self, + self.left_panel_container, wx.ID_ANY, wx.DefaultPosition, wx.Size(-1, -1), @@ -104,9 +127,14 @@ def init_ui(self): pcb_fab_scroll_wind.SetSizer(lay_pcb_fab_panel) pcb_fab_scroll_wind.Layout() - self.summary_view = SummaryPanel(self) - main_sizer.Add(pcb_fab_scroll_wind, 1, wx.EXPAND, 8) - main_sizer.Add(self.summary_view, 0, wx.EXPAND, 8) + self.summary_view = SummaryPanel(self.main_splitter) + left_sizer.Add(pcb_fab_scroll_wind, 1, wx.EXPAND, 8) + self.left_panel_container.SetSizer(left_sizer) + self.left_panel_container.Layout() + left_sizer.Fit(self.left_panel_container) + self.main_splitter.SplitVertically( + self.left_panel_container, self.summary_view, 400 + ) self.Bind( EVT_LAYER_COUNT_CHANGE, @@ -121,15 +149,49 @@ def init_ui(self): self.Bind(EVT_ORDER_REGION_CHANGED, self.on_order_region_changed) self.Bind(wx.EVT_SIZE, self.OnSize, self) self.Bind(wx.EVT_CLOSE, self.OnClose, self) + self.Bind( + wx.EVT_SPLITTER_SASH_POS_CHANGED, + self.on_sash_pos_changed, + self.main_splitter, + ) + + self.main_splitter.Bind(wx.EVT_IDLE, self.main_splitter_on_idle) + + self.Bind( + EVT_BUTTON_FABRICATION_DATA_GEN_RES, self.on_fabrication_data_gen_progress + ) for i in self._pcb_form_parts.values(): i.init() i.on_region_changed() + main_sizer = wx.BoxSizer(wx.HORIZONTAL) + main_sizer.Add(self.main_splitter, 1, wx.EXPAND, 5) self.SetSizer(main_sizer) self.Layout() self.Centre(wx.BOTH) + def on_fabrication_data_gen_progress(self, evt: FabricationDataGenEvent): + if self._data_gen_progress is not None: + res = evt.get_status() + if GenerateStatus.RUNNING == res.get_status(): + self._data_gen_progress.Update(res.get_progress(), res.get_message()) + else: + self._data_gen_progress.Destroy() + self._data_gen_progress = None + if GenerateStatus.FAILED == res.get_status(): + wx.MessageBox(f"{res.get_message()}") + + def on_sash_pos_changed(self, evt): + sash_pos = evt.GetSashPosition() + SETTING_MANAGER.set_mainwindow_sash_pos(sash_pos) + + def main_splitter_on_idle(self, evt): + self.main_splitter.SetSashPosition( + SETTING_MANAGER.get_mainwindow_sash_position() + ) + self.main_splitter.Unbind(wx.EVT_IDLE) + @property def fabrication_data_generator(self): if self._fabrication_data_gen is None: @@ -242,35 +304,24 @@ def on_update_price(self, evt): raise e # TODO remove me def on_place_order(self, evt): + self.show_data_gen_progress_dialog() if not self.form_is_valid(): return - try: - url = OrderRegion.get_url( - SETTING_MANAGER.order_region, URL_KIND.PLACE_ORDER - ) - if url is None: - wx.MessageBox(_("No available url for placing order in current region")) - return - with self.fabrication_data_generator.create_kicad_pcb_file() as zipfile: - rsp = requests.post( - url, - files={"file": open(zipfile, "rb")}, - data=self.get_place_order_form(), - ) - urls = json.loads(rsp.content) - for key in "url", "redirect": - if key in urls: - uat_url = str(urls[key]) - webbrowser.open(uat_url) - return - raise Exception("No available order url in the response") - except Exception as e: - wx.MessageBox(str(e)) - raise e # TODO remove me + url = OrderRegion.get_url(SETTING_MANAGER.order_region, URL_KIND.PLACE_ORDER) + if url is None: + wx.MessageBox(_("No available url for placing order in current region")) + return + if self._dataGenThread is not None: + self._dataGenThread.join() + self._dataGenThread = None + self._dataGenThread = DataGenThread( + self, self.fabrication_data_generator, self.get_place_order_form(), url + ) def adjust_size(self): for i in self._pcb_form_parts.values(): i.Layout() + self.left_panel_container.Layout() self.Layout() def on_order_region_changed(self, ev): diff --git a/kicad_amf_plugin/gui/summary/price_model_base.py b/kicad_amf_plugin/gui/summary/price_model_base.py index 16dc56e..bd747e6 100644 --- a/kicad_amf_plugin/gui/summary/price_model_base.py +++ b/kicad_amf_plugin/gui/summary/price_model_base.py @@ -1,10 +1,9 @@ from dataclasses import dataclass -from enum import Enum import abc import json -class PriceModelCol(Enum): +class PriceModelCol: DESC = 0 VALUE = DESC + 1 COL_COUNT = VALUE + 1 diff --git a/kicad_amf_plugin/gui/summary/summary_panel.py b/kicad_amf_plugin/gui/summary/summary_panel.py index a30eb87..7eac478 100644 --- a/kicad_amf_plugin/gui/summary/summary_panel.py +++ b/kicad_amf_plugin/gui/summary/summary_panel.py @@ -2,9 +2,8 @@ from kicad_amf_plugin.utils.roles import EditDisplayRole from .ui_summary_panel import UiSummaryPanel from kicad_amf_plugin.icon import GetImagePath -from kicad_amf_plugin.language.lang_setting_pop_menu import LangSettingPopMenu import wx -from .order_summary_model import OrderSummary, OrderSummaryModel +from .order_summary_model import OrderSummaryModel from .price_summary_model import PriceSummaryModel @@ -18,9 +17,9 @@ OrderRegionSettings = ( - EditDisplayRole(SupportedRegion.CHINA_MAINLAND, _("CN")), - EditDisplayRole(SupportedRegion.JAPAN, _("JP")), - EditDisplayRole(SupportedRegion.EUROPE_USA, _("EU/USA")), + EditDisplayRole(SupportedRegion.CHINA_MAINLAND, _("Mainland China")), + EditDisplayRole(SupportedRegion.EUROPE_USA, _("Worldwide (English)")), + EditDisplayRole(SupportedRegion.JAPAN, _("Worldwide (Japanese)")), ) @@ -29,10 +28,14 @@ def __init__(self, *args, **kw): super().__init__(*args, **kw) self.init_ui() - self.btn_set_language.Bind(wx.EVT_BUTTON, self.on_set_lang_clicked) self.btn_update_price.Bind(wx.EVT_BUTTON, self.on_update_price_clicked) self.btn_place_order.Bind(wx.EVT_BUTTON, self.on_place_order_clicked) self.choice_order_region.Bind(wx.EVT_CHOICE, self.on_region_changed) + self.Bind( + wx.EVT_SPLITTER_SASH_POS_CHANGED, + self.on_sash_changed, + self.splitter_detail_summary, + ) def init_ui(self): self.list_order_summary.AppendTextColumn( @@ -95,6 +98,12 @@ def init_ui(self): self.SetMinSize(wx.Size(max_width + 30, -1)) + def splitter_detail_summaryOnIdle(self, event): + self.splitter_detail_summary.SetSashPosition( + SETTING_MANAGER.get_summary_detail_sash_pos() + ) + self.splitter_detail_summary.Unbind(wx.EVT_IDLE) + def update_price_detail(self, price: "dict"): self.model_price_summary.update_price(price) @@ -113,6 +122,10 @@ def on_place_order_clicked(self, ev): evt = PlaceOrder(id=-1) wx.PostEvent(self.Parent, evt) + def on_sash_changed(self, evt): + sash_pos = evt.GetSashPosition() + SETTING_MANAGER.set_summary_detail_sash_pos(sash_pos) + def GetImagePath(self, bitmap_path): return GetImagePath(bitmap_path) @@ -123,11 +136,6 @@ def GetLineHeight(parent): line.Destroy() return height - def on_set_lang_clicked(self, evt): - menu = LangSettingPopMenu(SETTING_MANAGER.language) - self.PopupMenu(menu) - menu.Destroy() - def clear_content(self): for i in self.model_order_summary, self.model_price_summary: i.clear_content() diff --git a/kicad_amf_plugin/gui/summary/ui_summary_panel.fbp b/kicad_amf_plugin/gui/summary/ui_summary_panel.fbp index 95f2989..5bdf485 100644 --- a/kicad_amf_plugin/gui/summary/ui_summary_panel.fbp +++ b/kicad_amf_plugin/gui/summary/ui_summary_panel.fbp @@ -78,11 +78,11 @@ wxHORIZONTAL 1 none - + 5 wxALIGN_CENTER|wxALL 0 - + 1 1 1 @@ -110,7 +110,7 @@ 0 0 wxID_ANY - Shipping address + Website 0 0 @@ -139,11 +139,11 @@ -1 - + 5 wxALIGN_CENTER|wxALL 0 - + 1 1 1 @@ -213,126 +213,6 @@ 0 - - 5 - wxEXPAND | wxALL - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - - 0 - - - 0 - - 1 - m_staticline1 - 1 - - - protected - 1 - - Resizable - 1 - - wxLI_VERTICAL - ; ; forward_declare - 0 - - - - - - - - 5 - wxALL - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - PlateButton - 1 - self.btn_set_language=PlateButton(self,bmp= wx.Bitmap( self.GetImagePath(u"language.png" ),wx.BITMAP_TYPE_ANY ), style=PB_STYLE_GRADIENT ) - - 1 - - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - from kicad_amf_plugin.utils.platebtn import PlateButton ,PB_STYLE_GRADIENT - - 0 - - - 0 - -1,-1 - 1 - btn_set_language - 1 - - - protected - 1 - - Resizable - - 1 - - ; ; forward_declare - 0 - - - - - - @@ -341,80 +221,241 @@ 5 wxEXPAND 1 - + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 wxID_ANY - Cost detail + + 0 + + 0 + + 0 - sbSizer1 - wxVERTICAL - 1 - none - - 5 - wxALL|wxEXPAND - 1 - + 1 + splitter_detail_summary + 1 + + + protected + 1 + + Resizable + 0.0 + 0 + -1 + 1 + + wxSPLIT_HORIZONTAL + wxSP_LIVE_UPDATE + ; ; forward_declare + 0 + + + + + + + 1 + 1 + 1 + 1 + + + + + + + 1 + 0 + 1 1 + 0 + Dock + 0 + Left 1 + 1 + 0 0 wxID_ANY + + 0 + + 0 - list_price_detail + 1 + m_panel1 + 1 + + protected + 1 + Resizable + 1 - wxDV_ROW_LINES|wxDV_VERT_RULES ; ; forward_declare + 0 - + wxTAB_TRAVERSAL + + wxID_ANY + Cost detail + + sbSizer1 + wxVERTICAL + 1 + none + + 5 + wxALL|wxEXPAND + 1 + + + + 1 + 1 + + + 0 + wxID_ANY + + + list_price_detail + protected + + + wxDV_ROW_LINES|wxDV_VERT_RULES + ; ; forward_declare + + + + + + + - - - - 5 - wxEXPAND|wxFIXED_MINSIZE - 0 - - wxID_ANY - Order Summary - -1,-1 - sbSizer41 - wxVERTICAL - 1 - none - - 5 - wxALL|wxEXPAND - 1 - + + + 1 + 1 + 1 + 1 + + + + + + + 1 + 0 + 1 1 + 0 + Dock + 0 + Left 1 + 1 + 0 0 wxID_ANY + + 0 + + 0 - list_order_summary + 1 + m_panel2 + 1 + + protected + 1 + Resizable + 1 - wxDV_ROW_LINES|wxDV_VERT_RULES ; ; forward_declare + 0 - + wxTAB_TRAVERSAL + + wxID_ANY + Order Summary + -1,-1 + sbSizer41 + wxVERTICAL + 1 + none + + 5 + wxALL|wxEXPAND + 1 + + + + 1 + 1 + + + 0 + wxID_ANY + + + list_order_summary + protected + + + wxDV_ROW_LINES|wxDV_VERT_RULES + ; ; forward_declare + + + + + + + @@ -423,7 +464,7 @@ 5 wxEXPAND 0 - + bSizer31 wxVERTICAL diff --git a/kicad_amf_plugin/gui/summary/ui_summary_panel.py b/kicad_amf_plugin/gui/summary/ui_summary_panel.py index 84061a7..df03757 100644 --- a/kicad_amf_plugin/gui/summary/ui_summary_panel.py +++ b/kicad_amf_plugin/gui/summary/ui_summary_panel.py @@ -9,8 +9,8 @@ import wx import wx.xrc -from kicad_amf_plugin.utils.platebtn import PlateButton, PB_STYLE_GRADIENT import wx.dataview +from kicad_amf_plugin.utils.platebtn import PlateButton, PB_STYLE_GRADIENT from kicad_amf_plugin.utils.platebtn import ( PlateButton, PB_STYLE_GRADIENT, @@ -48,7 +48,7 @@ def __init__( self.m_staticText1 = wx.StaticText( sbSizer4.GetStaticBox(), wx.ID_ANY, - _("Shipping address"), + _("Website"), wx.DefaultPosition, wx.DefaultSize, 0, @@ -71,28 +71,26 @@ def __init__( sbSizer4.Add((0, 0), 1, wx.EXPAND, 5) - self.m_staticline1 = wx.StaticLine( - sbSizer4.GetStaticBox(), - wx.ID_ANY, - wx.DefaultPosition, - wx.DefaultSize, - wx.LI_VERTICAL, - ) - sbSizer4.Add(self.m_staticline1, 0, wx.EXPAND | wx.ALL, 5) - - self.btn_set_language = PlateButton( - self, - bmp=wx.Bitmap(self.GetImagePath("language.png"), wx.BITMAP_TYPE_ANY), - style=PB_STYLE_GRADIENT, - ) - sbSizer4.Add(self.btn_set_language, 0, wx.ALL, 5) - bSizer3.Add(sbSizer4, 1, wx.EXPAND, 5) bSizer1.Add(bSizer3, 0, wx.EXPAND, 5) + self.splitter_detail_summary = wx.SplitterWindow( + self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.SP_LIVE_UPDATE + ) + self.splitter_detail_summary.Bind( + wx.EVT_IDLE, self.splitter_detail_summaryOnIdle + ) + + self.m_panel1 = wx.Panel( + self.splitter_detail_summary, + wx.ID_ANY, + wx.DefaultPosition, + wx.DefaultSize, + wx.TAB_TRAVERSAL, + ) sbSizer1 = wx.StaticBoxSizer( - wx.StaticBox(self, wx.ID_ANY, _("Cost detail")), wx.VERTICAL + wx.StaticBox(self.m_panel1, wx.ID_ANY, _("Cost detail")), wx.VERTICAL ) self.list_price_detail = wx.dataview.DataViewCtrl( @@ -104,10 +102,18 @@ def __init__( ) sbSizer1.Add(self.list_price_detail, 1, wx.ALL | wx.EXPAND, 5) - bSizer1.Add(sbSizer1, 1, wx.EXPAND, 5) - + self.m_panel1.SetSizer(sbSizer1) + self.m_panel1.Layout() + sbSizer1.Fit(self.m_panel1) + self.m_panel2 = wx.Panel( + self.splitter_detail_summary, + wx.ID_ANY, + wx.DefaultPosition, + wx.DefaultSize, + wx.TAB_TRAVERSAL, + ) sbSizer41 = wx.StaticBoxSizer( - wx.StaticBox(self, wx.ID_ANY, _("Order Summary")), wx.VERTICAL + wx.StaticBox(self.m_panel2, wx.ID_ANY, _("Order Summary")), wx.VERTICAL ) self.list_order_summary = wx.dataview.DataViewCtrl( @@ -119,7 +125,11 @@ def __init__( ) sbSizer41.Add(self.list_order_summary, 1, wx.ALL | wx.EXPAND, 5) - bSizer1.Add(sbSizer41, 0, wx.EXPAND | wx.FIXED_MINSIZE, 5) + self.m_panel2.SetSizer(sbSizer41) + self.m_panel2.Layout() + sbSizer41.Fit(self.m_panel2) + self.splitter_detail_summary.SplitHorizontally(self.m_panel1, self.m_panel2, 0) + bSizer1.Add(self.splitter_detail_summary, 1, wx.EXPAND, 5) bSizer31 = wx.BoxSizer(wx.VERTICAL) @@ -148,6 +158,10 @@ def __init__( def __del__(self): pass + def splitter_detail_summaryOnIdle(self, event): + self.splitter_detail_summary.SetSashPosition(0) + self.splitter_detail_summary.Unbind(wx.EVT_IDLE) + # Virtual image path resolution method. Override this in your derived class. def GetImagePath(self, bitmap_path): return bitmap_path diff --git a/kicad_amf_plugin/icon/Huaqiu.ico b/kicad_amf_plugin/icon/Huaqiu.ico new file mode 100644 index 0000000..9f1618c Binary files /dev/null and b/kicad_amf_plugin/icon/Huaqiu.ico differ diff --git a/kicad_amf_plugin/kicad/board_manager.py b/kicad_amf_plugin/kicad/board_manager.py index e23ccf6..ae60c92 100644 --- a/kicad_amf_plugin/kicad/board_manager.py +++ b/kicad_amf_plugin/kicad/board_manager.py @@ -2,12 +2,12 @@ import wx import os + class EmptyBoardException(Exception): def __init__(self, *args: object) -> None: super().__init__(*args) - class BoardManager: def __init__(self, board) -> None: if board is None: diff --git a/kicad_amf_plugin/kicad/fabrication_data_generator.py b/kicad_amf_plugin/kicad/fabrication_data_generator.py index 2a357a2..2be4ae0 100644 --- a/kicad_amf_plugin/kicad/fabrication_data_generator.py +++ b/kicad_amf_plugin/kicad/fabrication_data_generator.py @@ -31,7 +31,6 @@ In2_Cu, In3_Cu, In4_Cu, - Refresh, ToMM, ) @@ -53,10 +52,6 @@ def nextpcb_root(self): def output_dir(self): return os.path.join(self.nextpcb_root, "output_files") - def __del__(self): - if os.path.exists(self.output_dir): - os.remove(self.output_dir) - def create_folders(self): """Create output folders if they not already exist.""" Path(self.output_dir).mkdir(parents=True, exist_ok=True) @@ -69,7 +64,6 @@ def fill_zones(self): filler = ZONE_FILLER(self.board) zones = self.board.Zones() filler.Fill(zones) - Refresh() def get_position(self, footprint): """Calculate position based on center of bounding box""" diff --git a/kicad_amf_plugin/kicad/fabrication_data_generator_evt.py b/kicad_amf_plugin/kicad/fabrication_data_generator_evt.py new file mode 100644 index 0000000..e5f036f --- /dev/null +++ b/kicad_amf_plugin/kicad/fabrication_data_generator_evt.py @@ -0,0 +1,43 @@ +import wx +import wx.lib.newevent + + +import wx + + +class GenerateStatus: + FAILED = 0 + RUNNING = 1 + SUCCESS = 2 + + MAX_PROGRESS = 1000 + + def __init__(self, status: int, msg: str = "", progress: int = -1) -> None: + self._status = status + self._msg = msg + self._progress = progress + + def get_status(self): + return self._status + + def get_message(self): + return self._msg + + def get_progress(self): + return self._progress + + +fabricationDataGenerateResult = wx.NewEventType() +EVT_BUTTON_FABRICATION_DATA_GEN_RES = wx.PyEventBinder(fabricationDataGenerateResult, 1) + + +class FabricationDataGenEvent(wx.PyCommandEvent): + def __init__(self, evtType, id=wx.ID_ANY): + wx.PyCommandEvent.__init__(self, evtType, id) + self._status: GenerateStatus = None + + def set_status(self, val: GenerateStatus): + self._status = val + + def get_status(self): + return self._status diff --git a/kicad_amf_plugin/kicad/fabrication_data_generator_thread.py b/kicad_amf_plugin/kicad/fabrication_data_generator_thread.py new file mode 100644 index 0000000..212fa80 --- /dev/null +++ b/kicad_amf_plugin/kicad/fabrication_data_generator_thread.py @@ -0,0 +1,92 @@ +import json +import time +import webbrowser +import requests +from threading import Thread +import wx + +from kicad_amf_plugin.kicad.fabrication_data_generator import FabricationDataGenerator +from kicad_amf_plugin.order.order_region import URL_KIND, OrderRegion +from kicad_amf_plugin.settings.setting_manager import SETTING_MANAGER +from .fabrication_data_generator_evt import ( + FabricationDataGenEvent, + fabricationDataGenerateResult, + GenerateStatus, +) + + +class DataGenThread(Thread): + def __init__(self, win: wx.Window, gen: FabricationDataGenerator, form, url): + super().__init__() + self.win = win + self.fabrication_data_generator = gen + self.place_order_form = form + self._url = url + self.start() + + def run(self): + try: + steps = ( + ( + _("Create fabrication data folder"), + self.fabrication_data_generator.create_folders, + ), + (_("Fill zones"), self.fabrication_data_generator.fill_zones), + (_("Generate gerber"), self.fabrication_data_generator.generate_geber), + ( + _("Generate excellon"), + self.fabrication_data_generator.generate_excellon, + ), + ( + _("Zip gerber and excellon file"), + self.fabrication_data_generator.zip_gerber_excellon, + ), + ) + + for idx_step in enumerate(steps): + ( + idx, + step, + ) = idx_step + desc, action = step + evt = FabricationDataGenEvent(fabricationDataGenerateResult) + evt.set_status( + GenerateStatus( + GenerateStatus.RUNNING, + desc, + int((idx + 1) * GenerateStatus.MAX_PROGRESS / (len(steps) + 1)), + ) + ) + wx.PostEvent(self.win, event=evt) + action() + + evt = FabricationDataGenEvent(fabricationDataGenerateResult) + evt.set_status( + GenerateStatus( + GenerateStatus.RUNNING, + _("Sending order request"), + GenerateStatus.MAX_PROGRESS - 1, + ) + ) + wx.PostEvent(self.win, event=evt) + rsp = requests.post( + self._url, + files={ + "file": open(self.fabrication_data_generator.zip_file_path, "rb") + }, + data=self.place_order_form, + ) + urls = json.loads(rsp.content) + for key in "url", "redirect": + if key in urls: + uat_url = str(urls[key]) + webbrowser.open(uat_url) + evt = FabricationDataGenEvent(fabricationDataGenerateResult) + evt.set_status(GenerateStatus(GenerateStatus.SUCCESS)) + wx.PostEvent(self.win, event=evt) + return + raise Exception("No available order url in the response") + except Exception as e: + evt = FabricationDataGenEvent(fabricationDataGenerateResult) + evt.set_status(GenerateStatus(GenerateStatus.FAILED, str(e))) + wx.PostEvent(self.win, event=evt) diff --git a/kicad_amf_plugin/language/constraint.py b/kicad_amf_plugin/language/constraint.py new file mode 100644 index 0000000..33a1653 --- /dev/null +++ b/kicad_amf_plugin/language/constraint.py @@ -0,0 +1,10 @@ +# language domain +LANG_DOMAIN = "kicad_amf_plugin" + + +ENGLISH = "English" + +DEFAULT_LANG = ENGLISH + + +CODE_TO_NAME = {"en": "English", "ja": "Japanese", "zh_CN": "Chinese"} diff --git a/kicad_amf_plugin/language/geni18n.py b/kicad_amf_plugin/language/geni18n.py index cddfef9..45b8d0d 100644 --- a/kicad_amf_plugin/language/geni18n.py +++ b/kicad_amf_plugin/language/geni18n.py @@ -17,10 +17,11 @@ catalog. """ +import platform import subprocess import sys import os -from lang_const import CODE_TO_NAME, LANG_DOMAIN, DEFAULT_LANG +from constraint import CODE_TO_NAME, LANG_DOMAIN, DEFAULT_LANG # we remove English as source code strings are in English supportedLang = [] @@ -32,11 +33,10 @@ appFolder = os.path.abspath( os.path.join(os.path.dirname(os.path.abspath(__file__)), "..") ) -import platform -m ,s , _ = platform.python_version_tuple() +m, s, _ = platform.python_version_tuple() -if os.name == "nt" and m == '3' and s == '8' : +if os.name == "nt" and m == "3" and s == "8": # setup some stuff to get at Python I18N tools/utilities pyExe = sys.executable pyFolder = os.path.split(pyExe)[0] diff --git a/kicad_amf_plugin/language/lang_const.py b/kicad_amf_plugin/language/lang_const.py index 8976a39..465d9b6 100644 --- a/kicad_amf_plugin/language/lang_const.py +++ b/kicad_amf_plugin/language/lang_const.py @@ -1,14 +1,4 @@ -# language domain -LANG_DOMAIN = "kicad_amf_plugin" - - -ENGLISH = "English" - -DEFAULT_LANG = ENGLISH - - -CODE_TO_NAME = {"en": "English", "ja": "Japanese", "zh_CN": "Chinese"} - +from .constraint import CODE_TO_NAME, ENGLISH, DEFAULT_LANG, LANG_DOMAIN try: from wx import LANGUAGE_JAPANESE_JAPAN diff --git a/kicad_amf_plugin/language/lang_setting_pop_menu.py b/kicad_amf_plugin/language/lang_setting_pop_menu.py deleted file mode 100644 index c5617c8..0000000 --- a/kicad_amf_plugin/language/lang_setting_pop_menu.py +++ /dev/null @@ -1,36 +0,0 @@ -import wx -from .lang_const import CODE_TO_NAME, code_to_wx -from kicad_amf_plugin.settings.setting_manager import SETTING_MANAGER - - -WX_ID_MAP = code_to_wx() - - -class LangSettingPopMenu(wx.Menu): - def __init__(self, current_lang_id: int): - super().__init__() - for lang in enumerate(CODE_TO_NAME): - idx, code = lang - idx = 10 + idx # Fix macos : menu item id cannot be zero - item = wx.MenuItem(id=idx, text=_(CODE_TO_NAME[code]), kind=wx.ITEM_CHECK) - wx_id = WX_ID_MAP[code] - if current_lang_id == wx_id: - item.Check(True) - else: - item.Check(False) - self.Append(item) - if wx.LANGUAGE_ENGLISH == wx_id: - self.Bind(wx.EVT_MENU, self.setup_en, id=idx) - elif wx.LANGUAGE_CHINESE_SIMPLIFIED == wx_id: - self.Bind(wx.EVT_MENU, self.setup_zh, id=idx) - else: - self.Bind(wx.EVT_MENU, self.setup_jp, id=idx) - - def setup_en(self, evt): - SETTING_MANAGER.set_language(wx.LANGUAGE_ENGLISH) - - def setup_jp(self, evt): - SETTING_MANAGER.set_language(wx.LANGUAGE_JAPANESE_JAPAN) - - def setup_zh(self, evt): - SETTING_MANAGER.set_language(wx.LANGUAGE_CHINESE_SIMPLIFIED) diff --git a/kicad_amf_plugin/language/locale/ja/LC_MESSAGES/kicad_amf_plugin.po b/kicad_amf_plugin/language/locale/ja/LC_MESSAGES/kicad_amf_plugin.po index 0e7d778..5e38b00 100644 --- a/kicad_amf_plugin/language/locale/ja/LC_MESSAGES/kicad_amf_plugin.po +++ b/kicad_amf_plugin/language/locale/ja/LC_MESSAGES/kicad_amf_plugin.po @@ -5,8 +5,8 @@ msgid "" msgstr "" "Project-Id-Version: \n" -"POT-Creation-Date: 2023-11-06 16:25+0800\n" -"PO-Revision-Date: 2023-11-06 16:34+0800\n" +"POT-Creation-Date: 2023-11-08 23:31+0800\n" +"PO-Revision-Date: 2023-11-08 23:34+0800\n" "Last-Translator: \n" "Language-Team: \n" "Language: ja\n" @@ -14,41 +14,33 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Generated-By: pygettext.py 1.5\n" -"X-Generator: Poedit 3.4.1\n" +"X-Generator: Poedit 3.4\n" -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\app_base.py:40 +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\app_base.py:37 msgid "Unsupported layer count!" msgstr "ボードレイヤーの数はサポートされていません!" -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\app_base.py:48 -msgid "" -"Restart the plugin to apply the new locale ?\n" -"For full translation(including the options), restarting KiCad is required" -msgstr "" -"プラグインを再起動して新しい言語設定を適用しますか?\n" -"完全な翻訳 (オプションを含む) が必要な場合は、KiCad を再起動してください" - -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\app_base.py:51 -msgid "Tip" -msgstr "先端" - -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\app_base.py:75 -msgid " is not supported" -msgstr "がサポートされていない" - -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\main_frame.py:75 +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\main_frame.py:81 msgid "HQ NextPCB Active Manufacturing" msgstr "HQネクストPCBアクティブ製造" -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\main_frame.py:219 +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\main_frame.py:100 +msgid "Preparing for your order" +msgstr "ご注文の準備中" + +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\main_frame.py:101 +msgid "The browser will be launched automatically while ready" +msgstr "準備が整うとブラウザが自動的に起動します" + +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\main_frame.py:281 msgid "No available url for querying price in current region" msgstr "現在の地域の価格を照会するための使用可能なURLがありません" -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\main_frame.py:239 +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\main_frame.py:301 msgid "Incorrect form parameter: " msgstr "フォームパラメータが正しくありません: " -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\main_frame.py:252 +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\main_frame.py:312 msgid "No available url for placing order in current region" msgstr "現在の地域で注文するための利用可能なURLがありません" @@ -208,32 +200,32 @@ msgstr "ロチェンマークアップ" msgid "SMT" msgstr "SMT" -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\summary_panel.py:22 -msgid "CN" -msgstr "CN" +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\summary_panel.py:20 +msgid "Mainland China" +msgstr "中国本土" -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\summary_panel.py:23 -msgid "JP" -msgstr "JP" +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\summary_panel.py:21 +msgid "Worldwide (English)" +msgstr "グローバル(英語)" -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\summary_panel.py:24 -msgid "EU/USA" -msgstr "EU/USA" +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\summary_panel.py:22 +msgid "Worldwide (Japanese)" +msgstr "グローバル(日本語)" -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\summary_panel.py:41 +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\summary_panel.py:42 msgid "Build Time" msgstr "納期" -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\summary_panel.py:48 +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\summary_panel.py:49 msgid "Qty" msgstr "量" -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\summary_panel.py:55 -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\summary_panel.py:76 +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\summary_panel.py:56 +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\summary_panel.py:77 msgid "Price" msgstr "価格" -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\summary_panel.py:69 +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\summary_panel.py:70 msgid "Item" msgstr "アイテム" @@ -242,34 +234,58 @@ msgid "Preference" msgstr "好み" #: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\ui_summary_panel.py:31 -msgid "Shipping address" -msgstr "注文地域" +msgid "Website" +msgstr "注文サイト" -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\ui_summary_panel.py:53 +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\ui_summary_panel.py:54 msgid "Cost detail" msgstr "費用の詳細" -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\ui_summary_panel.py:61 +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\ui_summary_panel.py:64 msgid "Order Summary" msgstr "注文の概要" -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\ui_summary_panel.py:71 +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\ui_summary_panel.py:78 msgid "Update Price" msgstr "価格を更新する" -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\ui_summary_panel.py:74 +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\ui_summary_panel.py:81 msgid "Add to Cart" msgstr "カートに追加" -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\language\lang_const.py:51 +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\kicad\fabrication_data_generator_thread.py:31 +msgid "Create fabrication data folder" +msgstr "製作データフォルダーの作成" + +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\kicad\fabrication_data_generator_thread.py:34 +msgid "Fill zones" +msgstr "フィルゾーン" + +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\kicad\fabrication_data_generator_thread.py:35 +msgid "Generate gerber" +msgstr "ガーバーを生成する" + +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\kicad\fabrication_data_generator_thread.py:37 +msgid "Generate excellon" +msgstr "エクセロンの生成" + +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\kicad\fabrication_data_generator_thread.py:41 +msgid "Zip gerber and excellon file" +msgstr "ガーバーおよび Excellon ファイルを ZIP 化する" + +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\kicad\fabrication_data_generator_thread.py:67 +msgid "Sending order request" +msgstr "注文リクエストの送信" + +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\language\lang_const.py:47 msgid "Chinese" msgstr "簡体字中国語" -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\language\lang_const.py:51 +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\language\lang_const.py:47 msgid "English" msgstr "英語" -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\language\lang_const.py:51 +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\language\lang_const.py:47 msgid "Japanese" msgstr "日本語" @@ -714,7 +730,44 @@ msgstr "積み重ねる" #: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\pcb_fabrication\special_process\ui_special_process.py:213 msgid "Metallized Sides Count" -msgstr "" +msgstr "金属化された側面の数" + +#~ msgid "" +#~ "Restart the plugin to apply the new locale ?\n" +#~ "For full translation(including the options), restarting KiCad is required" +#~ msgstr "" +#~ "プラグインを再起動して新しい言語設定を適用しますか?\n" +#~ "完全な翻訳 (オプションを含む) が必要な場合は、KiCad を再起動してください" + +#~ msgid "Tip" +#~ msgstr "先端" + +#~ msgid " is not supported" +#~ msgstr " がサポートされていない" + +#~ msgid "China" +#~ msgstr "中国" + +#~ msgid "Japan" +#~ msgstr "日本" + +#~ msgid "Others" +#~ msgstr "其它" + +#~ msgid "Shipping address" +#~ msgstr "注文地域" + +#~ msgid "Other countries/areas" +#~ msgstr "その他の国・地域" + +#~ msgid "CN" +#~ msgstr "CN" + +#~ msgid "JP" +#~ msgstr "JP" + +#~ msgid "EU/USA" +#~ msgstr "EU/USA" #~ msgid "Order Region" #~ msgstr "注文地域" diff --git a/kicad_amf_plugin/language/locale/zh_CN/LC_MESSAGES/kicad_amf_plugin.po b/kicad_amf_plugin/language/locale/zh_CN/LC_MESSAGES/kicad_amf_plugin.po index feacdb3..0ab4308 100644 --- a/kicad_amf_plugin/language/locale/zh_CN/LC_MESSAGES/kicad_amf_plugin.po +++ b/kicad_amf_plugin/language/locale/zh_CN/LC_MESSAGES/kicad_amf_plugin.po @@ -5,8 +5,8 @@ msgid "" msgstr "" "Project-Id-Version: \n" -"POT-Creation-Date: 2023-11-06 16:25+0800\n" -"PO-Revision-Date: 2023-11-06 16:33+0800\n" +"POT-Creation-Date: 2023-11-08 23:31+0800\n" +"PO-Revision-Date: 2023-11-08 23:32+0800\n" "Last-Translator: \n" "Language-Team: \n" "Language: zh_CN\n" @@ -14,41 +14,33 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Generated-By: pygettext.py 1.5\n" -"X-Generator: Poedit 3.4.1\n" +"X-Generator: Poedit 3.4\n" -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\app_base.py:40 +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\app_base.py:37 msgid "Unsupported layer count!" msgstr "板子层数不支持!" -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\app_base.py:48 -msgid "" -"Restart the plugin to apply the new locale ?\n" -"For full translation(including the options), restarting KiCad is required" -msgstr "" -"是否重启插件以应用新的语言设置?\n" -"如果需要完全翻译(包括选项),请重启 KiCad" - -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\app_base.py:51 -msgid "Tip" -msgstr "提示" - -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\app_base.py:75 -msgid " is not supported" -msgstr "不支持" - -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\main_frame.py:75 +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\main_frame.py:81 msgid "HQ NextPCB Active Manufacturing" msgstr "HQ NextPCB Active Manufacturing" -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\main_frame.py:219 +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\main_frame.py:100 +msgid "Preparing for your order" +msgstr "正在准备您的订单信息" + +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\main_frame.py:101 +msgid "The browser will be launched automatically while ready" +msgstr "订单准备好后会自动打开浏览器" + +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\main_frame.py:281 msgid "No available url for querying price in current region" msgstr "当前区域无可询价接口" -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\main_frame.py:239 +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\main_frame.py:301 msgid "Incorrect form parameter: " msgstr "无效的表单参数: " -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\main_frame.py:252 +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\main_frame.py:312 msgid "No available url for placing order in current region" msgstr "当前区域无可下单接口" @@ -208,32 +200,32 @@ msgstr "罗程加价" msgid "SMT" msgstr "SMT" -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\summary_panel.py:22 -msgid "CN" +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\summary_panel.py:20 +msgid "Mainland China" msgstr "中国大陆" -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\summary_panel.py:23 -msgid "JP" -msgstr "日本" +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\summary_panel.py:21 +msgid "Worldwide (English)" +msgstr "全球(英语)" -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\summary_panel.py:24 -msgid "EU/USA" -msgstr "欧美" +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\summary_panel.py:22 +msgid "Worldwide (Japanese)" +msgstr "全球(日语)" -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\summary_panel.py:41 +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\summary_panel.py:42 msgid "Build Time" msgstr "交期" -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\summary_panel.py:48 +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\summary_panel.py:49 msgid "Qty" msgstr "数量" -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\summary_panel.py:55 -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\summary_panel.py:76 +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\summary_panel.py:56 +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\summary_panel.py:77 msgid "Price" msgstr "价格" -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\summary_panel.py:69 +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\summary_panel.py:70 msgid "Item" msgstr "项目" @@ -242,34 +234,58 @@ msgid "Preference" msgstr "偏好设置" #: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\ui_summary_panel.py:31 -msgid "Shipping address" -msgstr "订购区域" +msgid "Website" +msgstr "下单站点" -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\ui_summary_panel.py:53 +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\ui_summary_panel.py:54 msgid "Cost detail" msgstr "价格明细" -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\ui_summary_panel.py:61 +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\ui_summary_panel.py:64 msgid "Order Summary" msgstr "订单信息汇总" -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\ui_summary_panel.py:71 +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\ui_summary_panel.py:78 msgid "Update Price" msgstr "更新价格" -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\ui_summary_panel.py:74 +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\gui\summary\ui_summary_panel.py:81 msgid "Add to Cart" msgstr "加入购物车" -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\language\lang_const.py:51 +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\kicad\fabrication_data_generator_thread.py:31 +msgid "Create fabrication data folder" +msgstr "创建制造文件文件夹" + +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\kicad\fabrication_data_generator_thread.py:34 +msgid "Fill zones" +msgstr "填充网格" + +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\kicad\fabrication_data_generator_thread.py:35 +msgid "Generate gerber" +msgstr "生成gerber文件" + +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\kicad\fabrication_data_generator_thread.py:37 +msgid "Generate excellon" +msgstr "生成excellon文件" + +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\kicad\fabrication_data_generator_thread.py:41 +msgid "Zip gerber and excellon file" +msgstr "打包gerber和excellon文件" + +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\kicad\fabrication_data_generator_thread.py:67 +msgid "Sending order request" +msgstr "正在发送订单请求" + +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\language\lang_const.py:47 msgid "Chinese" msgstr "简体中文" -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\language\lang_const.py:51 +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\language\lang_const.py:47 msgid "English" msgstr "英文" -#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\language\lang_const.py:51 +#: C:\Users\yihuo\Documents\KiCad\7.0\scripting\plugins\kicad-amf-plugin\kicad_amf_plugin\language\lang_const.py:47 msgid "Japanese" msgstr "日文" @@ -716,6 +732,52 @@ msgstr "堆叠" msgid "Metallized Sides Count" msgstr "金属化边框数量" +#~ msgid "Shipping address" +#~ msgstr "订购区域" + +#~ msgid "" +#~ "Restart the plugin to apply the new locale ?\n" +#~ "For full translation(including the options), restarting KiCad is required" +#~ msgstr "" +#~ "是否重启插件以应用新的语言设置?\n" +#~ "如果需要完全翻译(包括选项),请重启 KiCad" + +#~ msgid "Tip" +#~ msgstr "提示" + +#~ msgid " is not supported" +#~ msgstr " 不支持" + +#~ msgid "China" +#~ msgstr "中国" + +#~ msgid "Japan" +#~ msgstr "日本" + +#~ msgid "Other countries/areas" +#~ msgstr "其它国家/地区" + +#~ msgid "CN" +#~ msgstr "中国大陆" + +#~ msgid "JP" +#~ msgstr "日本" + +#~ msgid "HQPCB (Chinese)" +#~ msgstr "华秋PCB(中国)" + +#~ msgid "HQ NextPCB (English)" +#~ msgstr "NextPCB(欧美)" + +#~ msgid "HQ NextPCB (Japanese)" +#~ msgstr "NextPCB (日本)" + +#~ msgid "Choose the preferred website for your order" +#~ msgstr "选择一个站点下单" + +#~ msgid "EU/USA" +#~ msgstr "欧美" + #~ msgid "Order Region" #~ msgstr "订购区域" diff --git a/kicad_amf_plugin/order/supported_region.py b/kicad_amf_plugin/order/supported_region.py index 967cdac..6e80081 100644 --- a/kicad_amf_plugin/order/supported_region.py +++ b/kicad_amf_plugin/order/supported_region.py @@ -1,4 +1,4 @@ class SupportedRegion: CHINA_MAINLAND = 0 - JAPAN = 1 - EUROPE_USA = 2 + EUROPE_USA = 1 + JAPAN = 2 diff --git a/kicad_amf_plugin/settings/setting_manager.py b/kicad_amf_plugin/settings/setting_manager.py index 43030f2..5fdb769 100644 --- a/kicad_amf_plugin/settings/setting_manager.py +++ b/kicad_amf_plugin/settings/setting_manager.py @@ -17,10 +17,14 @@ HEIGHT = "height" -SASH_POS = "sash_pos" +MAIN_WINDOW_SASH_POS = "main_window_sash_pos" +SPLITTER_DETAIL_SUMMARY = "splitter_detail_summary" -DEFAULT_WIDTH = 660 + +DEFAULT_WIDTH = 800 + +DEFAULT_HEIGHT = 814 PRICE_UNIT = {0: "¥", 1: "$"} @@ -37,7 +41,7 @@ def __init__(self) -> None: self.app: wx.App = None sp = wx.StandardPaths.Get() config_loc = sp.GetUserConfigDir() - config_loc = os.path.join(config_loc, APP_NAME) + config_loc = os.path.join(config_loc, f".{APP_NAME}") if not os.path.exists(config_loc): os.mkdir(config_loc) @@ -51,8 +55,6 @@ def __init__(self) -> None: if not self.app_conf.HasEntry(LANGUAGE): self.set_language(KiCadSetting.read_lang_setting()) self.app_conf.Flush() - if not self.app_conf.HasEntry(WIDTH) or not self.app_conf.HasEntry(HEIGHT): - self.set_window_size((DEFAULT_WIDTH, 700)) if not self.app_conf.HasEntry(ORDER_REGION): location = "China" try: @@ -70,7 +72,7 @@ def register_app(self, app: wx.App): self.app = app def set_language(self, now: int): - old = self.language + old = self.get_language if old == now: return self.app_conf.WriteInt(key=LANGUAGE, value=now) @@ -80,15 +82,14 @@ def set_language(self, now: int): self.app_conf.Flush() wx.PostEvent(self.app, evt) - def get_sash_position(self): - return self.app_conf.ReadInt(SASH_POS, DEFAULT_WIDTH * 4 / 7) + def get_mainwindow_sash_position(self): + return self.app_conf.ReadInt(MAIN_WINDOW_SASH_POS, int(DEFAULT_WIDTH * 4 / 7)) - def set_sash_pos(self, pos: int): - self.app_conf.WriteInt(SASH_POS, pos) + def set_mainwindow_sash_pos(self, pos: int): + self.app_conf.WriteInt(MAIN_WINDOW_SASH_POS, int(pos)) self.app_conf.Flush() - @property - def language(self): + def get_language(self) -> int: return self.app_conf.ReadInt(LANGUAGE) def set_order_region(self, region: int): @@ -103,7 +104,7 @@ def get_price_unit(self, translated=False): sym = "¥" if not self.order_region else "$" if not translated: return sym - if self.language == wx.LANGUAGE_CHINESE_SIMPLIFIED: + if self.get_language() == wx.LANGUAGE_CHINESE_SIMPLIFIED: return TRANSLATED_PRICE_UNIT[sym] return sym @@ -120,7 +121,17 @@ def set_window_size(self, s: "tuple[int,int]"): self.app_conf.Flush() def get_window_size(self): - return wx.Size(self.app_conf.ReadInt(WIDTH), self.app_conf.ReadInt(HEIGHT)) + return wx.Size( + self.app_conf.ReadInt(WIDTH, DEFAULT_WIDTH), + self.app_conf.ReadInt(HEIGHT, DEFAULT_HEIGHT), + ) + + def set_summary_detail_sash_pos(self, pos: int): + self.app_conf.WriteInt(key=SPLITTER_DETAIL_SUMMARY, value=int(pos)) + self.app_conf.Flush() + + def get_summary_detail_sash_pos(self): + return self.app_conf.ReadInt(SPLITTER_DETAIL_SUMMARY, 432) SETTING_MANAGER = _SettingManager()