Move export logic from mainframe to export dialog, and introducing ui blocking for price optimization

This commit is contained in:
Ryan Holmes
2019-03-19 11:33:32 -04:00
parent 72a602b5b0
commit 25bbf3dc03
4 changed files with 18840 additions and 57 deletions

View File

@@ -26,6 +26,10 @@ import wx
from service.port.eft import EFT_OPTIONS
from service.port.multibuy import MULTIBUY_OPTIONS
from service.settings import SettingsProvider
from service.port import EfsPort, Port
from service.const import PortMultiBuyOptions
from eos.db import getFit
from gui.utils.clipboard import toClipboard
class CopySelectDialog(wx.Dialog):
@@ -39,6 +43,17 @@ class CopySelectDialog(wx.Dialog):
def __init__(self, parent):
wx.Dialog.__init__(self, parent, id=wx.ID_ANY, title="Select a format", size=(-1, -1),
style=wx.DEFAULT_DIALOG_STYLE)
self.CopySelectDict = {
CopySelectDialog.copyFormatEft : self.exportEft,
CopySelectDialog.copyFormatXml : self.exportXml,
CopySelectDialog.copyFormatDna : self.exportDna,
CopySelectDialog.copyFormatEsi : self.exportEsi,
CopySelectDialog.copyFormatMultiBuy: self.exportMultiBuy,
CopySelectDialog.copyFormatEfs : self.exportEfs
}
self.mainFrame = parent
mainSizer = wx.BoxSizer(wx.VERTICAL)
self.copyFormats = OrderedDict((
@@ -99,6 +114,29 @@ class CopySelectDialog(wx.Dialog):
self.Fit()
self.Center()
def Validate(self):
selected = self.GetSelected()
options = self.GetOptions()
settings = SettingsProvider.getInstance().getSettings("pyfaExport")
settings["format"] = selected
settings["options"] = options
self.waitDialog = None
def cb(text):
if self.waitDialog:
del self.waitDialog
q toClipboard(text)
self.EndModal(wx.ID_OK)
export_options = options.get(selected)
if selected == CopySelectDialog.copyFormatMultiBuy and export_options.get(PortMultiBuyOptions.OPTIMIZE_PRICES, False):
self.waitDialog = wx.BusyInfo("Optimizing Prices", parent=self)
self.CopySelectDict[selected](export_options, callback=cb)
return False
def Selected(self, event):
obj = event.GetEventObject()
formatName = obj.GetLabel()
@@ -119,3 +157,27 @@ class CopySelectDialog(wx.Dialog):
for formatId in self.options:
options[formatId] = {optId: ch.IsChecked() for optId, ch in self.options[formatId].items()}
return options
def exportEft(self, options, callback):
fit = getFit(self.mainFrame.getActiveFit())
Port.exportEft(fit, options, callback)
def exportDna(self, options, callback):
fit = getFit(self.mainFrame.getActiveFit())
Port.exportDna(fit, callback)
def exportEsi(self, options, callback):
fit = getFit(self.mainFrame.getActiveFit())
Port.exportESI(fit, callback)
def exportXml(self, options, callback):
fit = getFit(self.mainFrame.getActiveFit())
Port.exportXml(None, fit, callback)
def exportMultiBuy(self, options, callback):
fit = getFit(self.mainFrame.getActiveFit())
Port.exportMultiBuy(fit, options, callback)
def exportEfs(self, options, callback):
fit = getFit(self.mainFrame.getActiveFit())
EfsPort.exportEfs(fit, 0, callback)

View File

@@ -37,7 +37,6 @@ import config
import gui.globalEvents as GE
from eos.config import gamedata_date, gamedata_version
from eos.db.saveddata.loadDefaultDatabaseValues import DefaultDatabaseValues
from eos.db.saveddata.queries import getFit as db_getFit
# import this to access override setting
from eos.modifiedAttributeDict import ModifiedAttributeDict
from gui import graphFrame
@@ -64,11 +63,11 @@ from gui.setEditor import ImplantSetEditorDlg
from gui.shipBrowser import ShipBrowser
from gui.statsPane import StatsPane
from gui.updateDialog import UpdateDialog
from gui.utils.clipboard import fromClipboard, toClipboard
from gui.utils.clipboard import fromClipboard
from service.character import Character
from service.esi import Esi
from service.fit import Fit
from service.port import EfsPort, IPortUser, Port
from service.port import IPortUser, Port
from service.price import Price
from service.settings import HTMLExportSettings, SettingsProvider
from service.update import Update
@@ -708,30 +707,6 @@ class MainFrame(wx.Frame):
else:
self.marketBrowser.search.Focus()
def exportEft(self, options, callback):
fit = db_getFit(self.getActiveFit())
Port.exportEft(fit, options, callback)
def exportDna(self, options, callback):
fit = db_getFit(self.getActiveFit())
Port.exportDna(fit, callback)
def exportEsi(self, options, callback):
fit = db_getFit(self.getActiveFit())
Port.exportESI(fit, callback)
def exportXml(self, options, callback):
fit = db_getFit(self.getActiveFit())
Port.exportXml(None, fit, callback)
def exportMultiBuy(self, options, callback):
fit = db_getFit(self.getActiveFit())
Port.exportMultiBuy(fit, options, callback)
def exportEfs(self, options, callback):
fit = db_getFit(self.getActiveFit())
EfsPort.exportEfs(fit, 0, callback)
def importFromClipboard(self, event):
clipboard = fromClipboard()
activeFit = self.getActiveFit()
@@ -748,36 +723,8 @@ class MainFrame(wx.Frame):
self._openAfterImport(importData)
def exportToClipboard(self, event):
CopySelectDict = {CopySelectDialog.copyFormatEft: self.exportEft,
CopySelectDialog.copyFormatXml: self.exportXml,
CopySelectDialog.copyFormatDna: self.exportDna,
CopySelectDialog.copyFormatEsi: self.exportEsi,
CopySelectDialog.copyFormatMultiBuy: self.exportMultiBuy,
CopySelectDialog.copyFormatEfs: self.exportEfs}
dlg = CopySelectDialog(self)
btnPressed = dlg.ShowModal()
def killDialog():
try:
dlg.Destroy()
except RuntimeError:
pyfalog.error("Tried to destroy an object that doesn't exist in <exportToClipboard>.")
if btnPressed == wx.ID_OK:
selected = dlg.GetSelected()
options = dlg.GetOptions()
settings = SettingsProvider.getInstance().getSettings("pyfaExport")
settings["format"] = selected
settings["options"] = options
def cb(text):
toClipboard(text)
killDialog()
CopySelectDict[selected](options.get(selected), callback=cb)
else:
killDialog()
with CopySelectDialog(self) as dlg:
dlg.ShowModal()
def exportSkillsNeeded(self, event):
""" Exports skills needed for active fit and active character """