Skip to content

Commit

Permalink
Fix/macos base app (#16)
Browse files Browse the repository at this point in the history
* feat: Update translation

* fix: Adjut the base app for running on mac

Do not custruct a new wx.App for running on mac

* fix: Fix waring on macos

Menu item id cannot be zero on mac

* feat:

* feat: Enable resizing summary panel

Embed summary panel and pcb panel to splitted window

* fix: Let the callee catch the ex instead

Do't catch error in create_kicad_pcb_file

* feat: Ajust to summary panel to best size

Calc the max width of the dataview ctrl

* fix: Remove DisableConsistencyChecks

* fix: Ajust the default width of summary to 300

* fix: Fix the max size

* fix: Fix the max_width in Kicad 6.0 on Ubuntu

* fix: Fix japanese

---------

Co-authored-by: liangtie.qian <yihuo0420@gmail.com>
  • Loading branch information
2 people authored and SYSUeric66 committed Nov 7, 2023
1 parent e2d52d9 commit 538e3f1
Show file tree
Hide file tree
Showing 16 changed files with 682 additions and 488 deletions.
4 changes: 3 additions & 1 deletion __main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
if __name__ == "__main__":
from kicad_amf_plugin.plugin._main import _main

from wx import App
app = App()
_main()
app.MainLoop()
18 changes: 7 additions & 11 deletions kicad_amf_plugin/gui/app_base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from wx.lib.mixins.inspection import InspectionMixin
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
Expand All @@ -21,30 +20,25 @@ def _displayHook(obj):
print(repr(obj))


class BaseApp(wx.App, InspectionMixin):
def __init__(
self, redirect=False, filename=None, useBestVisual=False, clearSigInt=True
):
super().__init__(redirect, filename, useBestVisual, clearSigInt)
class BaseApp(wx.EvtHandler):
def __init__(self):
super().__init__()
self.Bind(EVT_LOCALE_CHANGE, self.on_locale_changed)

def OnInit(self):
self.Init() # InspectionMixin
# work around for Python stealing "_"
sys.displayhook = _displayHook
self.locale = None
wx.Locale.AddCatalogLookupPathPrefix(
os.path.join(PLUGIN_ROOT, "language", "locale")
)
from kicad_amf_plugin.settings.setting_manager import SETTING_MANAGER

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:
wx.MessageBox(_("Unsupported layer count!"))
return False
self.startup_dialog()
return True

def on_locale_changed(self, evt):
Expand All @@ -68,6 +62,7 @@ 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
Expand All @@ -77,6 +72,7 @@ def update_language(self, lang: int):
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):
Expand Down
29 changes: 26 additions & 3 deletions kicad_amf_plugin/gui/summary/summary_panel.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from kicad_amf_plugin.order.supported_region import SupportedRegion
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 .price_summary_model import PriceSummaryModel


import wx.dataview as dv
from kicad_amf_plugin.settings.setting_manager import SETTING_MANAGER
from kicad_amf_plugin.gui.event.pcb_fabrication_evt_list import (
Expand All @@ -14,15 +17,22 @@
)


OrderRegionSettings = (
EditDisplayRole(SupportedRegion.CHINA_MAINLAND, _("CN")),
EditDisplayRole(SupportedRegion.JAPAN, _("JP")),
EditDisplayRole(SupportedRegion.EUROPE_USA, _("EU/USA")),
)


class SummaryPanel(UiSummaryPanel):
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.radio_box_order_region.Bind(wx.EVT_RADIOBOX, self.on_region_changed)
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)

def init_ui(self):
self.list_order_summary.AppendTextColumn(
Expand Down Expand Up @@ -70,7 +80,20 @@ def init_ui(self):

self.model_price_summary = PriceSummaryModel()
self.list_price_detail.AssociateModel(self.model_price_summary)
self.radio_box_order_region.SetSelection(SETTING_MANAGER.order_region)
self.choice_order_region.AppendItems(
[i.DisplayRole for i in OrderRegionSettings]
)
self.choice_order_region.SetSelection(SETTING_MANAGER.order_region)

max_width = 300
for view in self.list_order_summary, self.list_price_detail:
sum = 0
for i in range(0, view.GetColumnCount()):
sum = sum + view.GetColumn(i).GetWidth()
max_width = max(max_width, sum)
sum = 0

self.SetMinSize(wx.Size(max_width + 30, -1))

def update_price_detail(self, price: "dict"):
self.model_price_summary.update_price(price)
Expand Down Expand Up @@ -110,7 +133,7 @@ def clear_content(self):
i.clear_content()

def on_region_changed(self, evt):
SETTING_MANAGER.set_order_region(self.radio_box_order_region.GetSelection())
SETTING_MANAGER.set_order_region(self.choice_order_region.GetCurrentSelection())
self.clear_content()
ev = OrderRegionChanged(-1)
wx.PostEvent(self.Parent, ev)
135 changes: 126 additions & 9 deletions kicad_amf_plugin/gui/summary/ui_summary_panel.fbp
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,72 @@
<property name="orient">wxHORIZONTAL</property>
<property name="parent">1</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="0">
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALIGN_CENTER|wxALL</property>
<property name="proportion">0</property>
<object class="wxStaticText" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Shipping address</property>
<property name="markup">0</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_staticText1</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<property name="wrap">-1</property>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag"></property>
<property name="flag">wxALIGN_CENTER|wxALL</property>
<property name="proportion">0</property>
<object class="wxRadioBox" expanded="0">
<object class="wxChoice" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
Expand All @@ -96,7 +157,7 @@
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="choices">&quot;CN&quot; &quot;JP&quot; &quot;EU/USA&quot;</property>
<property name="choices"></property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
Expand All @@ -111,16 +172,14 @@
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Order Region</property>
<property name="majorDimension">1</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">radio_box_order_region</property>
<property name="name">choice_order_region</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
Expand All @@ -131,7 +190,7 @@
<property name="selection">0</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style">wxRA_SPECIFY_ROWS</property>
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
Expand All @@ -154,6 +213,64 @@
<property name="width">0</property>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND | wxALL</property>
<property name="proportion">0</property>
<object class="wxStaticLine" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_staticline1</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style">wxLI_VERTICAL</property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
</object>
</object>
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxALL</property>
Expand Down Expand Up @@ -195,7 +312,7 @@
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="minimum_size">-1,-1</property>
<property name="moveable">1</property>
<property name="name">btn_set_language</property>
<property name="pane_border">1</property>
Expand Down
Loading

0 comments on commit 538e3f1

Please sign in to comment.