diff --git a/controller/market.py b/controller/market.py index c7f07a4fd..1b7bda38e 100644 --- a/controller/market.py +++ b/controller/market.py @@ -38,7 +38,7 @@ class Market(): items = [] group = eos.db.getMarketGroup(id) - for item in group.items: + for item in group.items: icon = item.icon.iconFile if item.icon else "" items.append((item.ID, item.name, icon)) @@ -59,6 +59,23 @@ class Market(): return children + def getShipRoot(self): + cat = eos.db.getCategory(6) + root = [] + for grp in cat.groups: + if grp.published == 1: + root.append((grp.ID, grp.name)) + + return root + + def getShipList(self, id): + ships = [] + grp = eos.db.getGroup(id) + for item in grp.items: + if item.published == 1: + ships.append((item.ID, item.name, item.race)) + + return ships def getMarketRoot(self): """ Get the root of the market tree. @@ -75,6 +92,6 @@ class Market(): root = [] for id in marketGroups: mg = eos.db.getMarketGroup(id) - root.append((id, mg.name, mg.icon.iconFile)) + root.append((id, mg.name, mg.icon.iconFile if mg.icon else "")) return root diff --git a/gui/fittingView.py b/gui/fittingView.py index 3ea287862..71d199b04 100644 --- a/gui/fittingView.py +++ b/gui/fittingView.py @@ -32,6 +32,8 @@ class FittingView(wx.ListCtrl): self.SetImageList(self.imageList, wx.IMAGE_LIST_SMALL) self.activeColumns = [] self.Bind(wx.EVT_LIST_COL_BEGIN_DRAG, self.resizeChecker) + self.Bind(wx.EVT_LIST_COL_CLICK, self.dragCheck) + self.Bind(wx.EVT_LIST_COL_END_DRAG, self.dragCheck) i = 0 for colName in FittingView.DEFAULT_COLS: col = gui.builtinViewColumns.getColumn(colName)(self, None) @@ -48,3 +50,9 @@ class FittingView(wx.ListCtrl): def resizeChecker(self, event): if self.activeColumns[event.Column].resizable is False: event.Veto() + + def dragCheck(self, event): + print event + + def dragEnd(self, event): + print event diff --git a/gui/mainFrame.py b/gui/mainFrame.py index 15affba33..2645ac23f 100644 --- a/gui/mainFrame.py +++ b/gui/mainFrame.py @@ -23,25 +23,39 @@ from gui.mainToolBar import MainToolBar from gui.marketBrowser import MarketBrowser from gui.fitMultiSwitch import FitMultiSwitch from gui.statsPane import StatsPane +from gui.shipBrowser import ShipBrowser from wx.lib.wordwrap import wordwrap import aboutData class MainFrame(wx.Frame): + __instance = None + @classmethod + def getInstance(cls): + return cls.__instance if cls.__instance is not None else MainFrame() + def __init__(self): wx.Frame.__init__(self, None, wx.ID_ANY, title="pyfa - Python Fitting Assistant") + MainFrame.__instance = self + self.SetMinSize((1000, 700)) - #Add menu - self.SetMenuBar(MainMenuBar()) - self.SetToolBar(MainToolBar(self)) - - #Register menubar events / only quit for now + #Register menubar events / only quit for now self.Bind(wx.EVT_MENU, self.ExitApp, id=wx.ID_EXIT) self.Bind(wx.EVT_MENU, self.ShowAboutBox, id=wx.ID_ABOUT) self.splitter = wx.SplitterWindow(self, style = wx.SP_LIVE_UPDATE) - self.marketBrowser = MarketBrowser(self.splitter) + marketShipBrowserPanel = wx.Panel(self.splitter) + self.marketShipBrowserSizer = wx.BoxSizer(wx.VERTICAL) + marketShipBrowserPanel.SetSizer(self.marketShipBrowserSizer) + + self.marketBrowser = MarketBrowser(marketShipBrowserPanel) + self.marketShipBrowserSizer.Add(self.marketBrowser, 1, wx.EXPAND) + + + self.shipBrowser = ShipBrowser(marketShipBrowserPanel) + self.marketShipBrowserSizer.Add(self.shipBrowser, 1, wx.EXPAND) + statsFitviewPanel = wx.Panel(self.splitter) sizer = wx.BoxSizer(wx.HORIZONTAL) statsFitviewPanel.SetSizer(sizer) @@ -54,10 +68,14 @@ class MainFrame(wx.Frame): sizer.Add(self.fitMultiSwitch, 1, wx.EXPAND) sizer.Add(self.statsPane, 0, wx.EXPAND) - self.splitter.SplitVertically(self.marketBrowser, statsFitviewPanel) + self.splitter.SplitVertically(marketShipBrowserPanel, statsFitviewPanel) self.splitter.SetMinimumPaneSize(10) self.splitter.SetSashPosition(300) + #Add menu + self.SetMenuBar(MainMenuBar()) + self.SetToolBar(MainToolBar(self)) + #Show ourselves self.Show() diff --git a/gui/mainToolBar.py b/gui/mainToolBar.py index 9182a91e7..9921961f4 100644 --- a/gui/mainToolBar.py +++ b/gui/mainToolBar.py @@ -19,12 +19,29 @@ import wx from gui import bitmapLoader +import gui.mainFrame class MainToolBar(wx.ToolBar): def __init__(self, parent): - wx.ToolBar.__init__(self, parent, wx.ID_ANY) + style = wx.TB_HORIZONTAL | wx.NO_BORDER | wx.TB_FLAT + wx.ToolBar.__init__(self, parent, wx.ID_ANY, style=style) - self.AddCheckLabelTool(wx.ID_ANY, "Ship Browser", bitmapLoader.getBitmap("ship_big", "icons")) - self.AddLabelTool(wx.ID_ANY, "Character Editor", bitmapLoader.getBitmap("character_big", "icons")) + self.AddCheckLabelTool(10, "Ship Browser", bitmapLoader.getBitmap("ship_big", "icons"), shortHelp="Ship browser") + self.AddCheckLabelTool(20, "Character Editor", bitmapLoader.getBitmap("character_big", "icons"), shortHelp="Character editor") + self.Bind(wx.EVT_TOOL, self.shipBrowserToggle, id=10) + self.Bind(wx.EVT_TOOL, self.characterEditor, id=20) self.Realize() + + gui.mainFrame.MainFrame.getInstance().shipBrowser.Hide() + + def shipBrowserToggle(self, event): + newState = self.GetToolState(10) + mainFrame = gui.mainFrame.MainFrame.getInstance() + + mainFrame.shipBrowser.Show(newState) + mainFrame.marketBrowser.Show(not newState) + mainFrame.marketShipBrowserSizer.Layout() + + def characterEditor(self, event): + print event diff --git a/gui/marketBrowser.py b/gui/marketBrowser.py index 1e66d9014..c4e3f816c 100644 --- a/gui/marketBrowser.py +++ b/gui/marketBrowser.py @@ -28,7 +28,7 @@ class MarketBrowser(wx.Panel): vbox = wx.BoxSizer(wx.VERTICAL) self.splitter = wx.SplitterWindow(self, style = wx.SP_LIVE_UPDATE) - + vbox.Add(self.splitter, 1, wx.EXPAND) self.SetSizer(vbox) diff --git a/gui/shipBrowser.py b/gui/shipBrowser.py new file mode 100644 index 000000000..46d8a1877 --- /dev/null +++ b/gui/shipBrowser.py @@ -0,0 +1,80 @@ +import wx +import controller +import bitmapLoader + +class ShipBrowser(wx.Panel): + def __init__(self, parent): + wx.Panel.__init__(self, parent) + vbox = wx.BoxSizer(wx.VERTICAL) + + self.splitter = wx.SplitterWindow(self, style = wx.SP_LIVE_UPDATE) + + vbox.Add(self.splitter, 1, wx.EXPAND) + self.SetSizer(vbox) + + self.shipView = ShipView(self.splitter) + + listStyle = wx.LC_REPORT | wx.BORDER_NONE | wx.LC_NO_HEADER | wx.LC_SINGLE_SEL + self.fitView = wx.ListCtrl(self.splitter, style = listStyle) + + self.shipImageList = wx.ImageList(16, 16) + self.shipView.SetImageList(self.shipImageList) + + self.splitter.SplitHorizontally(self.shipView, self.fitView) + self.splitter.SetMinimumPaneSize(250) + + self.shipRoot = self.shipView.AddRoot("Ships") + + iconId = self.shipImageList.Add(bitmapLoader.getBitmap("ship_small", "icons")) + + cMarket = controller.Market.getInstance() + shipRoot = cMarket.getShipRoot() + for id, name in shipRoot: + childId = self.shipView.AppendItem(self.shipRoot, name, iconId, data=wx.TreeItemData(id)) + self.shipView.AppendItem(childId, "dummy") + + self.shipView.SortChildren(self.shipRoot) + + self.raceImageIds = {} + self.races = ["amarr", "caldari", "gallente", "minmatar", "ore", "serpentis", "angel", "blood", "sansha", "guristas"] + for race in self.races: + imageId = self.shipImageList.Add(bitmapLoader.getBitmap("race_%s_small" % race, "icons")) + self.raceImageIds[race] = imageId + + #Bind our lookup method to when the tree gets expanded + self.shipView.Bind(wx.EVT_TREE_ITEM_EXPANDING, self.expandLookup) + self.idRaceMap = {} + self.shipView.races = self.races + self.shipView.idRaceMap = self.idRaceMap + + def expandLookup(self, event): + root = event.Item + child, cookie = self.shipView.GetFirstChild(root) + self.idRaceMap.clear() + if self.shipView.GetItemText(child) == "dummy": + self.shipView.Delete(child) + + cMarket = controller.Market.getInstance() + + for id, name, race in cMarket.getShipList(self.shipView.GetPyData(root)): + iconId = self.raceImageIds[race] if race in self.raceImageIds else -1 + self.idRaceMap[id] = race + self.shipView.AppendItem(root, name, iconId, data=wx.TreeItemData(id)) + + self.shipView.SortChildren(root) + +class ShipView(wx.TreeCtrl): + def __init__(self, parent): + wx.TreeCtrl.__init__(self, parent) + treeStyle = self.GetWindowStyleFlag() + treeStyle |= wx.TR_HIDE_ROOT + self.SetWindowStyleFlag(treeStyle) + + def OnCompareItems(self, treeId1, treeId2): + child, cookie = self.GetFirstChild(treeId1) + if child.IsOk(): + return cmp(self.GetItemText(treeId1), self.GetItemText(treeId2)) + else: + id1 = self.GetPyData(treeId1) + id2 = self.GetPyData(treeId2) + return cmp(self.races.index(self.idRaceMap[id1]), self.races.index(self.idRaceMap[id2])) diff --git a/icons/race_amarr_small.png b/icons/race_amarr_small.png new file mode 100644 index 000000000..2e9f72cff Binary files /dev/null and b/icons/race_amarr_small.png differ diff --git a/icons/race_angel_small.png b/icons/race_angel_small.png new file mode 100644 index 000000000..02facd522 Binary files /dev/null and b/icons/race_angel_small.png differ diff --git a/icons/race_blood_small.png b/icons/race_blood_small.png new file mode 100644 index 000000000..0e7577a82 Binary files /dev/null and b/icons/race_blood_small.png differ diff --git a/icons/race_caldari_small.png b/icons/race_caldari_small.png new file mode 100644 index 000000000..f21c98792 Binary files /dev/null and b/icons/race_caldari_small.png differ diff --git a/icons/race_gallente_small.png b/icons/race_gallente_small.png new file mode 100644 index 000000000..aedc0c957 Binary files /dev/null and b/icons/race_gallente_small.png differ diff --git a/icons/race_guristas_small.png b/icons/race_guristas_small.png new file mode 100644 index 000000000..2eb858f76 Binary files /dev/null and b/icons/race_guristas_small.png differ diff --git a/icons/race_minmatar_small.png b/icons/race_minmatar_small.png new file mode 100644 index 000000000..b551d9437 Binary files /dev/null and b/icons/race_minmatar_small.png differ diff --git a/icons/race_ore_small.png b/icons/race_ore_small.png new file mode 100644 index 000000000..4e560970d Binary files /dev/null and b/icons/race_ore_small.png differ diff --git a/icons/race_sansha_small.png b/icons/race_sansha_small.png new file mode 100644 index 000000000..affed5e58 Binary files /dev/null and b/icons/race_sansha_small.png differ diff --git a/icons/race_serpentis_small.png b/icons/race_serpentis_small.png new file mode 100644 index 000000000..b061c055e Binary files /dev/null and b/icons/race_serpentis_small.png differ