hydrus/include/ClientGUIPages.py

216 lines
7.0 KiB
Python
Raw Normal View History

2013-02-19 00:11:43 +00:00
import HydrusConstants as HC
import ClientConstants as CC
import ClientGUICommon
import ClientGUIDialogs
import ClientGUIManagement
import ClientGUIMedia
import ClientGUICanvas
2015-03-25 22:04:19 +00:00
import ClientDownloading
2015-05-20 21:31:40 +00:00
import HydrusData
2015-06-24 22:10:14 +00:00
import HydrusSerialisable
2015-03-18 21:46:29 +00:00
import HydrusThreading
2013-11-27 18:27:11 +00:00
import inspect
2013-02-19 00:11:43 +00:00
import os
2013-11-27 18:27:11 +00:00
import sys
2013-02-19 00:11:43 +00:00
import time
import traceback
import wx
2015-03-25 22:04:19 +00:00
import HydrusGlobals
2013-02-19 00:11:43 +00:00
2015-06-24 22:10:14 +00:00
class Page( wx.SplitterWindow ):
2013-02-19 00:11:43 +00:00
2015-06-24 22:10:14 +00:00
def __init__( self, parent, management_controller, initial_media_results ):
wx.SplitterWindow.__init__( self, parent )
2013-02-19 00:11:43 +00:00
2015-07-01 22:02:07 +00:00
self._page_key = HydrusData.GenerateKey()
2013-02-19 00:11:43 +00:00
2015-06-24 22:10:14 +00:00
self._management_controller = management_controller
self._management_controller.SetKey( 'page', self._page_key )
2015-03-04 22:44:32 +00:00
2013-02-19 00:11:43 +00:00
self._pretty_status = ''
2015-06-24 22:10:14 +00:00
self.SetMinimumPaneSize( 120 )
self.SetSashGravity( 0.0 )
2013-02-19 00:11:43 +00:00
2015-06-24 22:10:14 +00:00
self.Bind( wx.EVT_SPLITTER_DCLICK, self.EventUnsplit )
2013-02-19 00:11:43 +00:00
2015-06-24 22:10:14 +00:00
self._search_preview_split = wx.SplitterWindow( self, style=wx.SP_NOBORDER )
2013-02-19 00:11:43 +00:00
2015-06-24 22:10:14 +00:00
self._search_preview_split.SetMinimumPaneSize( 180 )
self._search_preview_split.SetSashGravity( 1.0 )
2013-02-19 00:11:43 +00:00
2015-06-24 22:10:14 +00:00
self._search_preview_split.Bind( wx.EVT_SPLITTER_DCLICK, self.EventPreviewUnsplit )
2013-02-19 00:11:43 +00:00
2015-06-24 22:10:14 +00:00
self._management_panel = ClientGUIManagement.CreateManagementPanel( self._search_preview_split, self, self._management_controller )
2013-09-11 21:28:19 +00:00
2015-06-24 22:10:14 +00:00
file_service_key = self._management_controller.GetKey( 'file_service' )
2013-09-11 21:28:19 +00:00
2015-07-15 20:28:26 +00:00
self._preview_panel = ClientGUICanvas.CanvasPanel( self._search_preview_split, self._page_key )
2013-02-19 00:11:43 +00:00
2015-06-24 22:10:14 +00:00
self._media_panel = ClientGUIMedia.MediaPanelThumbnails( self, self._page_key, file_service_key, initial_media_results )
self.SplitVertically( self._search_preview_split, self._media_panel, HC.options[ 'hpos' ] )
wx.CallAfter( self._search_preview_split.SplitHorizontally, self._management_panel, self._preview_panel, HC.options[ 'vpos' ] )
2015-09-16 18:11:00 +00:00
HydrusGlobals.client_controller.sub( self, 'SetPrettyStatus', 'new_page_status' )
HydrusGlobals.client_controller.sub( self, 'SwapMediaPanel', 'swap_media_panel' )
2013-02-19 00:11:43 +00:00
2015-06-24 22:10:14 +00:00
def CleanBeforeDestroy( self ): self._management_panel.CleanBeforeDestroy()
2013-02-19 00:11:43 +00:00
2015-06-24 22:10:14 +00:00
def EventPreviewUnsplit( self, event ): self._search_preview_split.Unsplit( self._preview_panel )
2013-02-19 00:11:43 +00:00
2015-06-24 22:10:14 +00:00
def EventUnsplit( self, event ): self.Unsplit( self._search_preview_split )
2013-02-19 00:11:43 +00:00
2015-06-24 22:10:14 +00:00
def GetManagementController( self ):
2014-01-22 21:11:22 +00:00
2015-06-24 22:10:14 +00:00
return self._management_controller
2014-01-22 21:11:22 +00:00
2013-02-19 00:11:43 +00:00
2015-06-24 22:10:14 +00:00
# used by autocomplete
def GetMedia( self ):
2013-02-19 00:11:43 +00:00
2015-06-24 22:10:14 +00:00
return self._media_panel.GetSortedMedia()
2013-02-19 00:11:43 +00:00
2015-06-24 22:10:14 +00:00
2015-09-16 18:11:00 +00:00
def GetPageKey( self ):
return self._page_key
2015-06-24 22:10:14 +00:00
def GetPrettyStatus( self ):
2013-02-19 00:11:43 +00:00
2015-06-24 22:10:14 +00:00
return self._pretty_status
2013-02-19 00:11:43 +00:00
def GetSashPositions( self ):
if self.IsSplit(): x = self.GetSashPosition()
2013-08-14 20:21:49 +00:00
else: x = HC.options[ 'hpos' ]
2013-02-19 00:11:43 +00:00
if self._search_preview_split.IsSplit(): y = -1 * self._preview_panel.GetSize()[1]
2013-08-14 20:21:49 +00:00
else: y = HC.options[ 'vpos' ]
2013-02-19 00:11:43 +00:00
return ( x, y )
2015-09-16 18:11:00 +00:00
def PageHidden( self ): HydrusGlobals.client_controller.pub( 'page_hidden', self._page_key )
2013-02-19 00:11:43 +00:00
2015-09-16 18:11:00 +00:00
def PageShown( self ): HydrusGlobals.client_controller.pub( 'page_shown', self._page_key )
2013-02-19 00:11:43 +00:00
2015-10-07 21:56:22 +00:00
def PrepareToHide( self ):
2013-02-19 00:11:43 +00:00
2015-09-16 18:11:00 +00:00
HydrusGlobals.client_controller.pub( 'set_focus', self._page_key, None )
2013-02-19 00:11:43 +00:00
2015-09-16 18:11:00 +00:00
def RefreshQuery( self ): HydrusGlobals.client_controller.pub( 'refresh_query', self._page_key )
2013-02-19 00:11:43 +00:00
def ShowHideSplit( self ):
if self.IsSplit():
self.Unsplit( self._search_preview_split )
else:
2013-08-14 20:21:49 +00:00
self.SplitVertically( self._search_preview_split, self._media_panel, HC.options[ 'hpos' ] )
2013-02-19 00:11:43 +00:00
2013-08-14 20:21:49 +00:00
self._search_preview_split.SplitHorizontally( self._management_panel, self._preview_panel, HC.options[ 'vpos' ] )
2013-02-19 00:11:43 +00:00
def SetMediaFocus( self ): self._media_panel.SetFocus()
2015-06-24 22:10:14 +00:00
def SetPrettyStatus( self, page_key, status ):
if page_key == self._page_key:
self._pretty_status = status
2015-09-16 18:11:00 +00:00
HydrusGlobals.client_controller.pub( 'refresh_status' )
2015-06-24 22:10:14 +00:00
2015-09-16 18:11:00 +00:00
def SetSearchFocus( self ): HydrusGlobals.client_controller.pub( 'set_search_focus', self._page_key )
2015-06-24 22:10:14 +00:00
2015-09-16 18:11:00 +00:00
def SetSynchronisedWait( self ): HydrusGlobals.client_controller.pub( 'synchronised_wait_switch', self._page_key )
2015-06-24 22:10:14 +00:00
2013-02-19 00:11:43 +00:00
def SwapMediaPanel( self, page_key, new_panel ):
if page_key == self._page_key:
self._preview_panel.SetMedia( None )
self.ReplaceWindow( self._media_panel, new_panel )
2015-05-20 21:31:40 +00:00
self._media_panel.Hide()
# If this is a CallAfter, OS X segfaults on refresh jej
wx.CallLater( 500, self._media_panel.Destroy )
2013-02-19 00:11:43 +00:00
self._media_panel = new_panel
2015-09-02 23:16:09 +00:00
def TestAbleToClose( self ):
self._management_panel.TestAbleToClose()
2013-02-19 00:11:43 +00:00
2015-06-24 22:10:14 +00:00
class GUISession( HydrusSerialisable.SerialisableBaseNamed ):
2013-12-04 22:44:16 +00:00
2015-06-24 22:10:14 +00:00
SERIALISABLE_TYPE = HydrusSerialisable.SERIALISABLE_TYPE_GUI_SESSION
SERIALISABLE_VERSION = 1
2013-02-19 00:11:43 +00:00
2015-06-24 22:10:14 +00:00
def __init__( self, name ):
2013-12-11 22:09:25 +00:00
2015-06-24 22:10:14 +00:00
HydrusSerialisable.SerialisableBaseNamed.__init__( self, name )
2013-12-11 22:09:25 +00:00
2015-06-24 22:10:14 +00:00
self._pages = []
2013-12-11 22:09:25 +00:00
2013-02-19 00:11:43 +00:00
2015-06-24 22:10:14 +00:00
def _GetSerialisableInfo( self ):
2015-03-25 22:04:19 +00:00
2015-06-24 22:10:14 +00:00
serialisable_info = []
2013-02-19 00:11:43 +00:00
2015-06-24 22:10:14 +00:00
for ( page_name, management_controller, hashes ) in self._pages:
2015-10-14 21:02:25 +00:00
serialisable_management_controller = management_controller.GetSerialisableTuple()
2015-06-24 22:10:14 +00:00
serialisable_hashes = [ hash.encode( 'hex' ) for hash in hashes ]
serialisable_info.append( ( page_name, serialisable_management_controller, serialisable_hashes ) )
2013-09-04 16:48:44 +00:00
2015-06-24 22:10:14 +00:00
return serialisable_info
2013-09-04 16:48:44 +00:00
2013-02-19 00:11:43 +00:00
2015-06-24 22:10:14 +00:00
def _InitialiseFromSerialisableInfo( self, serialisable_info ):
2013-03-27 20:02:51 +00:00
2015-06-24 22:10:14 +00:00
for ( page_name, serialisable_management_controller, serialisable_hashes ) in serialisable_info:
2014-01-22 21:11:22 +00:00
2015-06-24 22:10:14 +00:00
management_controller = HydrusSerialisable.CreateFromSerialisableTuple( serialisable_management_controller )
2014-01-22 21:11:22 +00:00
2015-06-24 22:10:14 +00:00
hashes = [ hash.decode( 'hex' ) for hash in serialisable_hashes ]
self._pages.append( ( page_name, management_controller, hashes ) )
2014-01-22 21:11:22 +00:00
2013-04-24 21:23:53 +00:00
2013-02-19 00:11:43 +00:00
2015-06-24 22:10:14 +00:00
def AddPage( self, page_name, management_controller, hashes ):
2013-11-27 18:27:11 +00:00
2015-06-24 22:10:14 +00:00
self._pages.append( ( page_name, management_controller, hashes ) )
2013-11-27 18:27:11 +00:00
2015-06-24 22:10:14 +00:00
def IteratePages( self ):
2013-02-19 00:11:43 +00:00
2015-06-24 22:10:14 +00:00
for page_tuple in self._pages:
yield page_tuple
2013-02-19 00:11:43 +00:00
2015-06-24 22:10:14 +00:00
HydrusSerialisable.SERIALISABLE_TYPES_TO_OBJECT_TYPES[ HydrusSerialisable.SERIALISABLE_TYPE_GUI_SESSION ] = GUISession