| 505 | |
| 506 | |
| 507 | class FittingsTreeView(wx.Panel): |
| 508 | def __init__(self, parent): |
| 509 | wx.Panel.__init__(self, parent, id=wx.ID_ANY) |
| 510 | self.parent = parent |
| 511 | pmainSizer = wx.BoxSizer(wx.VERTICAL) |
| 512 | |
| 513 | tree = self.fittingsTreeCtrl = wx.TreeCtrl(self, wx.ID_ANY, style=wx.TR_DEFAULT_STYLE | wx.TR_HIDE_ROOT) |
| 514 | pmainSizer.Add(tree, 1, wx.EXPAND | wx.ALL, 0) |
| 515 | |
| 516 | self.root = tree.AddRoot("Fits") |
| 517 | self.populateSkillTree(None) |
| 518 | |
| 519 | self.Bind(wx.EVT_TREE_SEL_CHANGED, self.displayFit) |
| 520 | |
| 521 | self.SetSizer(pmainSizer) |
| 522 | |
| 523 | self.Layout() |
| 524 | |
| 525 | def populateSkillTree(self, data): |
| 526 | if data is None: |
| 527 | return |
| 528 | root = self.root |
| 529 | tree = self.fittingsTreeCtrl |
| 530 | tree.DeleteChildren(root) |
| 531 | |
| 532 | sEsi = Esi.getInstance() |
| 533 | |
| 534 | dict = {} |
| 535 | fits = data |
| 536 | for fit in fits: |
| 537 | if fit['fitting_id'] in sEsi.fittings_deleted: |
| 538 | continue |
| 539 | ship = getItem(fit['ship_type_id']) |
| 540 | if ship is None: |
| 541 | pyfalog.debug('Cannot find ship type id: {}'.format(fit['ship_type_id'])) |
| 542 | continue |
| 543 | if ship.name not in dict: |
| 544 | dict[ship.name] = [] |
| 545 | dict[ship.name].append(fit) |
| 546 | |
| 547 | for name, fits in dict.items(): |
| 548 | shipID = tree.AppendItem(root, name) |
| 549 | for fit in fits: |
| 550 | fitId = tree.AppendItem(shipID, fit['name']) |
| 551 | tree.SetItemData(fitId, json.dumps(fit)) |
| 552 | |
| 553 | tree.SortChildren(root) |
| 554 | |
| 555 | def displayFit(self, event): |
| 556 | selection = self.fittingsTreeCtrl.GetSelection() |
| 557 | data = self.fittingsTreeCtrl.GetItemData(selection) |
| 558 | |
| 559 | if data is None: |
| 560 | event.Skip() |
| 561 | return |
| 562 | |
| 563 | fit = json.loads(data) |
| 564 | list = [] |