hydrus/include/ClientGUIOptionsPanels.py

153 lines
4.7 KiB
Python
Raw Normal View History

2019-01-09 22:59:03 +00:00
from . import ClientConstants as CC
from . import ClientGUICommon
from . import ClientCaches
from . import ClientDefaults
from . import ClientGUIDialogs
from . import ClientImporting
from . import ClientTags
2015-09-09 22:04:39 +00:00
import collections
2019-01-09 22:59:03 +00:00
from . import HydrusConstants as HC
from . import HydrusData
2017-05-03 21:33:48 +00:00
import os
2015-03-18 21:46:29 +00:00
import wx
2015-05-13 20:22:39 +00:00
import wx.lib.masked.timectrl
2019-01-09 22:59:03 +00:00
from . import HydrusGlobals as HG
2015-03-18 21:46:29 +00:00
class OptionsPanel( wx.Panel ):
2015-08-05 18:42:35 +00:00
def GetOptions( self ): raise NotImplementedError()
def SetOptions( self, options ): raise NotImplementedError()
2017-02-01 21:11:17 +00:00
def GetValue( self ): raise NotImplementedError()
2015-03-18 21:46:29 +00:00
2017-02-01 21:11:17 +00:00
def SetValue( self, info ): raise NotImplementedError()
2015-03-18 21:46:29 +00:00
2015-09-09 22:04:39 +00:00
class OptionsPanelMimes( OptionsPanel ):
def __init__( self, parent, selectable_mimes ):
OptionsPanel.__init__( self, parent )
self._mimes_to_checkboxes = {}
self._mime_groups_to_checkboxes = {}
self._mime_groups_to_values = {}
2016-08-17 20:07:22 +00:00
mime_groups = [ HC.APPLICATIONS, HC.AUDIO, HC.IMAGES, HC.VIDEO ]
2015-09-09 22:04:39 +00:00
mime_groups_to_mimes = collections.defaultdict( list )
for mime in selectable_mimes:
for mime_group in mime_groups:
if mime in mime_group:
mime_groups_to_mimes[ mime_group ].append( mime )
break
2018-01-03 22:37:30 +00:00
gridbox = wx.FlexGridSizer( 2 )
2015-09-09 22:04:39 +00:00
gridbox.AddGrowableCol( 1, 1 )
2016-08-17 20:07:22 +00:00
for mime_group in mime_groups:
mimes = mime_groups_to_mimes[ mime_group ]
2015-09-09 22:04:39 +00:00
mg_checkbox = wx.CheckBox( self, label = HC.mime_string_lookup[ mime_group ] )
mg_checkbox.Bind( wx.EVT_CHECKBOX, self.EventMimeGroupCheckbox )
self._mime_groups_to_checkboxes[ mime_group ] = mg_checkbox
self._mime_groups_to_values[ mime_group ] = mg_checkbox.GetValue()
2018-01-03 22:37:30 +00:00
gridbox.Add( mg_checkbox, CC.FLAGS_VCENTER )
2015-09-09 22:04:39 +00:00
vbox = wx.BoxSizer( wx.VERTICAL )
for mime in mimes:
m_checkbox = wx.CheckBox( self, label = HC.mime_string_lookup[ mime ] )
m_checkbox.Bind( wx.EVT_CHECKBOX, self.EventMimeCheckbox )
self._mimes_to_checkboxes[ mime ] = m_checkbox
2018-01-03 22:37:30 +00:00
vbox.Add( m_checkbox, CC.FLAGS_EXPAND_PERPENDICULAR )
2015-09-09 22:04:39 +00:00
2018-01-03 22:37:30 +00:00
gridbox.Add( vbox, CC.FLAGS_EXPAND_SIZER_BOTH_WAYS )
2015-09-09 22:04:39 +00:00
self.SetSizer( gridbox )
def _UpdateMimeGroupCheckboxes( self ):
2019-01-09 22:59:03 +00:00
for ( mime_group, mg_checkbox ) in list(self._mime_groups_to_checkboxes.items()):
2015-09-09 22:04:39 +00:00
2019-01-09 22:59:03 +00:00
respective_checkbox_values = [ m_checkbox.GetValue() for ( mime, m_checkbox ) in list(self._mimes_to_checkboxes.items()) if mime in mime_group ]
2015-09-09 22:04:39 +00:00
all_true = False not in respective_checkbox_values
mg_checkbox.SetValue( all_true )
self._mime_groups_to_values[ mime_group ] = all_true
def EventMimeCheckbox( self, event ):
self._UpdateMimeGroupCheckboxes()
def EventMimeGroupCheckbox( self, event ):
# this is a commandevent, which won't give up the checkbox object, so we have to do some jiggery pokery
2019-01-09 22:59:03 +00:00
for ( mime_group, mg_checkbox ) in list(self._mime_groups_to_checkboxes.items()):
2015-09-09 22:04:39 +00:00
expected_value = self._mime_groups_to_values[ mime_group ]
actual_value = mg_checkbox.GetValue()
if actual_value != expected_value:
2019-01-09 22:59:03 +00:00
for ( mime, m_checkbox ) in list(self._mimes_to_checkboxes.items()):
2015-09-09 22:04:39 +00:00
if mime in mime_group:
m_checkbox.SetValue( actual_value )
self._mime_groups_to_values[ mime_group ] = actual_value
2017-02-01 21:11:17 +00:00
def GetValue( self ):
2015-09-09 22:04:39 +00:00
2019-01-09 22:59:03 +00:00
mimes = tuple( [ mime for ( mime, checkbox ) in list(self._mimes_to_checkboxes.items()) if checkbox.GetValue() == True ] )
2015-09-09 22:04:39 +00:00
return mimes
2017-02-01 21:11:17 +00:00
def SetValue( self, mimes ):
2015-09-09 22:04:39 +00:00
2019-01-09 22:59:03 +00:00
for ( mime, checkbox ) in list(self._mimes_to_checkboxes.items()):
2015-09-09 22:04:39 +00:00
if mime in mimes:
checkbox.SetValue( True )
else:
checkbox.SetValue( False )
self._UpdateMimeGroupCheckboxes()