Updated market broswer search box to be inline with ship browser navigation panel (almost)
This commit is contained in:
268
gui/PFSearchBox.py
Normal file
268
gui/PFSearchBox.py
Normal file
@@ -0,0 +1,268 @@
|
||||
import wx
|
||||
import gui.utils.colorUtils as colorUtils
|
||||
import gui.utils.drawUtils as drawUtils
|
||||
from gui import bitmapLoader
|
||||
|
||||
|
||||
SearchButton, EVT_SEARCH_BTN = wx.lib.newevent.NewEvent()
|
||||
CancelButton, EVT_CANCEL_BTN = wx.lib.newevent.NewEvent()
|
||||
TextEnter, EVT_TEXT_ENTER = wx.lib.newevent.NewEvent()
|
||||
TextTyped, EVT_TEXT = wx.lib.newevent.NewEvent()
|
||||
|
||||
class PFSearchBox(wx.Window):
|
||||
def __init__(self, parent, id = wx.ID_ANY, value = "", pos = wx.DefaultPosition, size = wx.Size(-1,24), style = 0):
|
||||
wx.Window.__init__(self, parent, id, pos, size, style = 0)
|
||||
|
||||
self.isSearchButtonVisible = False
|
||||
self.isCancelButtonVisible = False
|
||||
|
||||
self.descriptiveText = "Search"
|
||||
|
||||
self.searchBitmap = None
|
||||
self.cancelBitmap = None
|
||||
self.bkBitmap = None
|
||||
|
||||
self.resized = True
|
||||
|
||||
self.searchButtonX = 0
|
||||
self.searchButtonY = 0
|
||||
self.searchButtonPressed = False
|
||||
|
||||
self.cancelButtonX = 0
|
||||
self.cancelButtonY = 0
|
||||
self.cancelButtonPressed = False
|
||||
|
||||
self.editX = 0
|
||||
self.editY = 0
|
||||
|
||||
|
||||
self.padding = 2
|
||||
|
||||
self.EditBox = wx.TextCtrl(self, wx.ID_ANY, "", wx.DefaultPosition, (-1,-1), wx.TE_PROCESS_ENTER)
|
||||
|
||||
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
||||
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBk)
|
||||
self.Bind(wx.EVT_SIZE, self.OnSize)
|
||||
|
||||
self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
|
||||
self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
|
||||
|
||||
# self.EditBox.ChangeValue(self.descriptiveText)
|
||||
|
||||
self.EditBox.Bind(wx.EVT_SET_FOCUS, self.OnEditSetFocus)
|
||||
self.EditBox.Bind(wx.EVT_KILL_FOCUS, self.OnEditKillFocus)
|
||||
|
||||
self.EditBox.Bind(wx.EVT_TEXT, self.OnText)
|
||||
self.EditBox.Bind(wx.EVT_TEXT_ENTER, self.OnTextEnter)
|
||||
|
||||
self.SetMinSize(size)
|
||||
|
||||
def OnText(self, event):
|
||||
wx.PostEvent(self, TextTyped())
|
||||
|
||||
def OnTextEnter(self, event):
|
||||
wx.PostEvent(self, TextEnter())
|
||||
|
||||
def OnEditSetFocus(self, event):
|
||||
# value = self.EditBox.GetValue()
|
||||
# if value == self.descriptiveText:
|
||||
# self.EditBox.ChangeValue("")
|
||||
pass
|
||||
|
||||
def OnEditKillFocus(self, event):
|
||||
if self.EditBox.GetValue() == "":
|
||||
self.Clear()
|
||||
|
||||
def Clear(self):
|
||||
self.EditBox.Clear()
|
||||
# self.EditBox.ChangeValue(self.descriptiveText)
|
||||
|
||||
def SetValue(self, value):
|
||||
self.EditBox.SetValue(value)
|
||||
|
||||
def ChangeValue(self, value):
|
||||
self.EditBox.ChangeValue(value)
|
||||
|
||||
def GetValue(self):
|
||||
return self.EditBox.GetValue()
|
||||
|
||||
def GetLineText(self, lineno):
|
||||
return self.EditBox.GetLineText(lineno)
|
||||
|
||||
def HitTest(self, target, position, area):
|
||||
x, y = target
|
||||
px, py = position
|
||||
aX, aY = area
|
||||
if (px > x and px < x + aX) and (py > y and py < y + aY):
|
||||
return True
|
||||
return False
|
||||
|
||||
def GetButtonsPos(self):
|
||||
btnpos = []
|
||||
btnpos.append( (self.searchButtonX, self.searchButtonY) )
|
||||
btnpos.append( (self.cancelButtonX, self.cancelButtonY) )
|
||||
return btnpos
|
||||
|
||||
def GetButtonsSize(self):
|
||||
btnsize = []
|
||||
|
||||
if self.searchBitmap:
|
||||
sw = self.searchBitmap.GetWidth()
|
||||
sh = self.searchBitmap.GetHeight()
|
||||
else:
|
||||
sw = 0
|
||||
sh = 0
|
||||
|
||||
if self.cancelBitmap:
|
||||
cw = self.cancelBitmap.GetWidth()
|
||||
ch = self.cancelBitmap.GetHeight()
|
||||
else:
|
||||
cw = 0
|
||||
ch = 0
|
||||
|
||||
btnsize.append( (sw,sh))
|
||||
btnsize.append( (cw,ch))
|
||||
return btnsize
|
||||
|
||||
def OnLeftDown(self, event):
|
||||
btnpos = self.GetButtonsPos()
|
||||
btnsize = self.GetButtonsSize()
|
||||
|
||||
self.CaptureMouse()
|
||||
for btn in xrange(2):
|
||||
if self.HitTest(btnpos[btn], event.GetPosition(), btnsize[btn]):
|
||||
if btn == 0:
|
||||
if not self.searchButtonPressed:
|
||||
self.searchButtonPressed = True
|
||||
self.Refresh()
|
||||
if btn == 1:
|
||||
if not self.cancelButtonPressed:
|
||||
self.cancelButtonPressed = True
|
||||
self.Refresh()
|
||||
|
||||
def OnLeftUp(self, event):
|
||||
btnpos = self.GetButtonsPos()
|
||||
btnsize = self.GetButtonsSize()
|
||||
|
||||
if self.HasCapture():
|
||||
self.ReleaseMouse()
|
||||
|
||||
for btn in xrange(2):
|
||||
if self.HitTest(btnpos[btn], event.GetPosition(), btnsize[btn]):
|
||||
if btn == 0:
|
||||
if self.searchButtonPressed:
|
||||
self.searchButtonPressed = False
|
||||
self.Refresh()
|
||||
self.SetFocus()
|
||||
wx.PostEvent(self, SearchButton())
|
||||
if btn == 1:
|
||||
if self.cancelButtonPressed:
|
||||
self.cancelButtonPressed = False
|
||||
self.Refresh()
|
||||
self.SetFocus()
|
||||
wx.PostEvent(self, CancelButton())
|
||||
else:
|
||||
if btn == 0:
|
||||
if self.searchButtonPressed:
|
||||
self.searchButtonPressed = False
|
||||
self.Refresh()
|
||||
if btn == 1:
|
||||
if self.cancelButtonPressed:
|
||||
self.cancelButtonPressed = False
|
||||
self.Refresh()
|
||||
|
||||
def OnSize(self, event):
|
||||
self.resized = True
|
||||
self.Refresh()
|
||||
|
||||
def OnEraseBk(self, event):
|
||||
pass
|
||||
|
||||
def UpdateElementsPos(self, dc):
|
||||
rect = self.GetRect()
|
||||
|
||||
if self.searchBitmap and self.isSearchButtonVisible:
|
||||
sw = self.searchBitmap.GetWidth()
|
||||
sh = self.searchBitmap.GetHeight()
|
||||
else:
|
||||
sw = 0
|
||||
sh = 0
|
||||
|
||||
if self.cancelBitmap and self.isCancelButtonVisible:
|
||||
cw = self.cancelBitmap.GetWidth()
|
||||
ch = self.cancelBitmap.GetHeight()
|
||||
else:
|
||||
cw = 0
|
||||
ch = 0
|
||||
|
||||
cwidth = rect.width
|
||||
cheight = rect.height
|
||||
|
||||
self.searchButtonX = self.padding
|
||||
self.searchButtonY = (cheight - sh) / 2
|
||||
self.cancelButtonX = cwidth - self.padding - cw
|
||||
self.cancelButtonY = (cheight - ch) / 2
|
||||
|
||||
self.editX = self.searchButtonX + self.padding + sw
|
||||
|
||||
editWidth, editHeight = self.EditBox.GetSize()
|
||||
|
||||
self.editY = (cheight - editHeight)/2
|
||||
self.EditBox.SetPosition((self.editX, self.editY))
|
||||
self.EditBox.SetSize( (self.cancelButtonX - self.padding - self.editX, -1))
|
||||
|
||||
def OnPaint(self, event):
|
||||
dc = wx.BufferedPaintDC(self)
|
||||
|
||||
bkColor = wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW)
|
||||
|
||||
rect = self.GetRect()
|
||||
|
||||
if self.resized:
|
||||
self.bkBitmap = drawUtils.RenderGradientBar(bkColor, rect.width, rect.height, 0.1, 0.1, 0.2, 2)
|
||||
self.UpdateElementsPos(dc)
|
||||
self.resized = False
|
||||
|
||||
dc.DrawBitmap(self.bkBitmap, 0, 0)
|
||||
|
||||
if self.isSearchButtonVisible:
|
||||
if self.searchBitmap:
|
||||
if self.searchButtonPressed:
|
||||
spad = 1
|
||||
else:
|
||||
spad = 0
|
||||
|
||||
dc.DrawBitmap(self.searchBitmap, self.searchButtonX + spad, self.searchButtonY + spad)
|
||||
|
||||
if self.isCancelButtonVisible:
|
||||
if self.cancelBitmap:
|
||||
if self.cancelButtonPressed:
|
||||
cpad = 1
|
||||
else:
|
||||
cpad = 0
|
||||
dc.DrawBitmap(self.cancelBitmap, self.cancelButtonX + cpad, self.cancelButtonY + cpad)
|
||||
|
||||
def SetSearchBitmap(self, bitmap):
|
||||
self.searchBitmap = bitmap
|
||||
|
||||
def SetCancelBitmap(self, bitmap):
|
||||
self.cancelBitmap = bitmap
|
||||
|
||||
def IsSearchButtonVisible(self):
|
||||
return self.isSearchButtonVisible
|
||||
|
||||
def IsCancelButtonVisible(self):
|
||||
return self.isCancelButtonVisible
|
||||
|
||||
def ShowSearchButton(self, show = True):
|
||||
self.isSearchButtonVisible = show
|
||||
|
||||
def ShowCancelButton(self, show = True):
|
||||
self.isCancelButtonVisible = show
|
||||
|
||||
def SetDescriptiveText(self, text):
|
||||
self.descriptiveText = text
|
||||
|
||||
def GetDescriptiveText(self):
|
||||
return self.descriptiveText
|
||||
|
||||
@@ -22,7 +22,9 @@ import service
|
||||
import gui.display as d
|
||||
from gui.cachingImageList import CachingImageList
|
||||
from gui.contextMenu import ContextMenu
|
||||
import gui.PFSearchBox as SBox
|
||||
|
||||
from gui import bitmapLoader
|
||||
|
||||
ItemSelected, ITEM_SELECTED = wx.lib.newevent.NewEvent()
|
||||
|
||||
@@ -32,19 +34,9 @@ class MarketBrowser(wx.Panel):
|
||||
vbox = wx.BoxSizer(wx.VERTICAL)
|
||||
self.SetSizer(vbox)
|
||||
|
||||
# Add a search button on top
|
||||
|
||||
# Add a WHOLE panel for ONE SINGLE search button
|
||||
# We have to be able to give the search more size, which can't be done in another way.
|
||||
# (That I found)
|
||||
p = wx.Panel(self)
|
||||
sizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
p.SetSizer(sizer)
|
||||
|
||||
vbox.Add(p, 0, wx.EXPAND)
|
||||
self.search = SearchBox(p)
|
||||
sizer.Add(self.search, 1, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 2)
|
||||
p.SetMinSize((wx.SIZE_AUTO_WIDTH, 33))
|
||||
# Add a search box on top
|
||||
self.search = SearchBox(self)
|
||||
vbox.Add(self.search, 0, wx.EXPAND)
|
||||
|
||||
self.splitter = wx.SplitterWindow(self, style = wx.SP_LIVE_UPDATE)
|
||||
vbox.Add(self.splitter, 1, wx.EXPAND)
|
||||
@@ -107,10 +99,15 @@ class MarketBrowser(wx.Panel):
|
||||
def jump(self, item):
|
||||
self.marketView.jump(item)
|
||||
|
||||
class SearchBox(wx.SearchCtrl):
|
||||
class SearchBox(SBox.PFSearchBox):
|
||||
def __init__(self, parent):
|
||||
wx.SearchCtrl.__init__(self, parent, wx.ID_ANY, style=wx.TE_PROCESS_ENTER)
|
||||
self.ShowCancelButton(True)
|
||||
SBox.PFSearchBox.__init__(self, parent)
|
||||
cancelBitmap = bitmapLoader.getBitmap("fit_delete_small","icons")
|
||||
searchBitmap = bitmapLoader.getBitmap("fsearch_small","icons")
|
||||
self.SetSearchBitmap(searchBitmap)
|
||||
self.SetCancelBitmap(cancelBitmap)
|
||||
self.ShowSearchButton()
|
||||
self.ShowCancelButton()
|
||||
|
||||
class MarketTree(wx.TreeCtrl):
|
||||
def __init__(self, parent, marketBrowser):
|
||||
@@ -211,10 +208,10 @@ class ItemView(d.Display):
|
||||
self.marketView = marketBrowser.marketView
|
||||
|
||||
# Make sure our search actually does interesting stuff
|
||||
self.marketBrowser.search.Bind(wx.EVT_TEXT_ENTER, self.scheduleSearch)
|
||||
self.marketBrowser.search.Bind(wx.EVT_SEARCHCTRL_SEARCH_BTN, self.scheduleSearch)
|
||||
self.marketBrowser.search.Bind(wx.EVT_SEARCHCTRL_CANCEL_BTN, self.clearSearch)
|
||||
self.marketBrowser.search.Bind(wx.EVT_TEXT, self.scheduleSearch)
|
||||
self.marketBrowser.search.Bind(SBox.EVT_TEXT_ENTER, self.scheduleSearch)
|
||||
self.marketBrowser.search.Bind(SBox.EVT_SEARCH_BTN, self.scheduleSearch)
|
||||
self.marketBrowser.search.Bind(SBox.EVT_CANCEL_BTN, self.clearSearch)
|
||||
self.marketBrowser.search.Bind(SBox.EVT_TEXT, self.scheduleSearch)
|
||||
|
||||
# Make sure WE do interesting stuff too
|
||||
self.Bind(wx.EVT_CONTEXT_MENU, self.contextMenu)
|
||||
|
||||
Reference in New Issue
Block a user