<commit_before>import random
import os

from gii.core         import *
from gii.qt.dialogs   import requestString, alertMessage, requestConfirm
from gii.qt.helpers   import setClipboardText
from gii.SearchView   import requestSearchView, registerSearchEnumerator

from AssetEditor      import AssetEditorModule, getAssetSelectionManager
from gii.SceneEditor  import SceneEditorModule, getSceneSelectionManager

from PyQt4            import QtCore, QtGui, uic
from PyQt4.QtCore     import Qt

from AssetBrowserWidgets import *


##----------------------------------------------------------------##
def _getModulePath( path ):
	import os.path
	return os.path.dirname( __file__ ) + '/' + path


##----------------------------------------------------------------##
class AssetBrowser( SceneEditorModule ):
	name       = 'asset_browser'
	dependency = ['qt', 'asset_editor']

	def onLoad(self):

		self.newCreateNodePath = None
		self.currentContextTargetNode = None
		self.thumbnailSize = ( 80, 80 )
		self.updatingSelection = False

		self.window = self.requestDockWindow('AssetBrowser',
				title='Asset Browser',
				dock='left',
				minSize=(200,200)
			)

		ui = self.window.addWidgetFromFile(
			_getModulePath('AssetBrowser.ui')
		)

		#
		self.treeFilter = AssetTreeFilter(
				self.window
			)
		self.treeView  = 	AssetBrowserTreeView(
			sorting   = True,
			multiple_selection = True,
			drag_mode = 'internal',
			folder_only = True
		)
		
		self.treeView.parentModule = self
		self.treeView.setContextMenuPolicy( QtCore.Qt.CustomContextMenu)
		self.treeView.customContextMenuRequested.connect( self.onTreeViewContextMenu)
		#

		treeLayout = QtGui.QVBoxLayout( ui.containerTree )
		treeLayout.setSpacing( 0 )
		treeLayout.setMargin( 0 )
		
		treeLayout.addWidget( self.treeFilter )
		treeLayout.addWidget( self.treeView )

		
		##
		self.listView  = AssetBrowserListWidget()
		self.tagFilter = AssetBrowserTagFilterWidget()
		self.statusBar = AssetBrowserStatusBar()

		self.listView .parentModule = self
		self.tagFilter.parentModule = self
		self.statusBar.parentModule = self

		self.listView.setContextMenuPolicy( QtCore.Qt.CustomContextMenu)
		self.listView.customContextMenuRequested.connect( self.onListViewContextMenu )

		listLayout = QtGui.QVBoxLayout( ui.containerRight )
		listLayout.setSpacing( 0 )
		listLayout.setMargin( 0 )

		listLayout.addWidget( self.tagFilter )
		listLayout.addWidget( self.listView )
		listLayout.addWidget( self.statusBar )

		##
		self.currentFolders = []
		

		#
		signals.connect( 'module.loaded',        self.onModuleLoaded )		
		signals.connect( 'asset.deploy.changed', self.onAssetDeployChanged )

		self.creatorMenu=self.addMenu(
			'asset_create_context',
			{ 'label':'Create' }
		)
		self.addMenuItem(
			'main/asset/asset_create', dict( label = 'Create', shortcut ='Ctrl+N' )
		)
		self.addMenuItem(
			'main/find/find_asset',   dict( label = 'Find Asset', shortcut = 'ctrl+T' )
		)
		self.addMenuItem(
			'main/find/open_asset',   dict( label = 'Open Asset', shortcut = 'ctrl+O' )
		)

		self.assetContextMenu=self.addMenu('asset_context')
		self.assetContextMenu.addChild([
				{'name':'show_in_browser', 'label':'Show File'},
				{'name':'open_in_system', 'label':'Open In System'},
				{'name':'copy_node_path', 'label':'Copy Asset Path'},
				'----',
				{'name':'clone', 'label':'Clone'},
				'----',
				{'name':'reimport', 'label':'Reimport'},
				'----',
				{'name':'deploy_set', 'label':'Set Deploy'},
				{'name':'deploy_unset', 'label':'Unset Deploy'},
				{'name':'deploy_disallow', 'label':'Disallow Deploy'},
				'----',
				{'name':'create', 'label':'Create', 'link':self.creatorMenu},
			])

		signals.connect( 'selection.changed', self.onSelectionChanged )
		registerSearchEnumerator( assetCreatorSearchEnumerator  )

	def onStart( self ):
		assetLib = self.getAssetLibrary()
		assetLib.scheduleScanProject()
		signals.connect( 'asset.register',   self.onAssetRegister )
		signals.connect( 'asset.unregister', self.onAssetUnregister )
		signals.connect( 'asset.moved',      self.onAssetMoved )
		signals.connect( 'asset.modified',   self.onAssetModified )

		self.treeView.rebuild()

		initialSelection = self.getConfig( 'current_selection', None )
		if initialSelection:
			nodes = [ assetLib.getAssetNode( path ) for path in initialSelection ]
			self.treeView.selectNode( nodes )

	def onStop( self ):
		self.setConfig( 'current_selection', [ node.getPath() for node in self.currentFolders ] )
		self.treeView.saveTreeStates()

	def onSetFocus( self ):
		self.getMainWindow().raise_()
		self.treeView.setFocus()
		self.window.raise_()

	def onUnload(self):
		#persist expand state
		# self.treeView.saveTreeStates()

		pass

	def onModuleLoaded(self):				
		for creator in self.getAssetLibrary().assetCreators:
			self.loadAssetCreator(creator)

	def setAssetIcon(self, assetType, iconName):
		self.assetIconMap[assetType] = iconName

	def locateAsset( self, asset, **options ):
		if isinstance( asset, ( str, unicode ) ): #path
			asset = self.getAssetLibrary().getAssetNode( asset )
		if not asset: return
		self.listView.setFocus( Qt.MouseFocusReason)
		self.selectAsset( asset, goto = True )<commit_msg>persist asset browser splitter sizes<commit_after>import random
import os

from gii.core         import *
from gii.qt.dialogs   import requestString, alertMessage, requestConfirm
from gii.qt.helpers   import setClipboardText
from gii.SearchView   import requestSearchView, registerSearchEnumerator

from AssetEditor      import AssetEditorModule, getAssetSelectionManager
from gii.SceneEditor  import SceneEditorModule, getSceneSelectionManager

from PyQt4            import QtCore, QtGui, uic
from PyQt4.QtCore     import Qt

from AssetBrowserWidgets import *


##----------------------------------------------------------------##
def _getModulePath( path ):
	import os.path
	return os.path.dirname( __file__ ) + '/' + path


##----------------------------------------------------------------##
class AssetBrowser( SceneEditorModule ):
	name       = 'asset_browser'
	dependency = ['qt', 'asset_editor']

	def onLoad(self):

		self.newCreateNodePath = None
		self.currentContextTargetNode = None
		self.thumbnailSize = ( 80, 80 )
		self.updatingSelection = False

		self.window = self.requestDockWindow('AssetBrowser',
				title='Asset Browser',
				dock='left',
				minSize=(200,200)
			)

		ui = self.window.addWidgetFromFile(
			_getModulePath('AssetBrowser.ui')
		)

		self.splitter = ui.splitter

		#
		self.treeFilter = AssetTreeFilter(
				self.window
			)
		self.treeView  = 	AssetBrowserTreeView(
			sorting   = True,
			multiple_selection = True,
			drag_mode = 'internal',
			folder_only = True
		)
		
		self.treeView.parentModule = self
		self.treeView.setContextMenuPolicy( QtCore.Qt.CustomContextMenu)
		self.treeView.customContextMenuRequested.connect( self.onTreeViewContextMenu)
		#

		treeLayout = QtGui.QVBoxLayout( ui.containerTree )
		treeLayout.setSpacing( 0 )
		treeLayout.setMargin( 0 )
		
		treeLayout.addWidget( self.treeFilter )
		treeLayout.addWidget( self.treeView )

		
		##
		self.listView  = AssetBrowserListWidget()
		self.tagFilter = AssetBrowserTagFilterWidget()
		self.statusBar = AssetBrowserStatusBar()

		self.listView .parentModule = self
		self.tagFilter.parentModule = self
		self.statusBar.parentModule = self

		self.listView.setContextMenuPolicy( QtCore.Qt.CustomContextMenu)
		self.listView.customContextMenuRequested.connect( self.onListViewContextMenu )

		listLayout = QtGui.QVBoxLayout( ui.containerRight )
		listLayout.setSpacing( 0 )
		listLayout.setMargin( 0 )

		listLayout.addWidget( self.tagFilter )
		listLayout.addWidget( self.listView )
		listLayout.addWidget( self.statusBar )

		##
		self.currentFolders = []
		

		#
		signals.connect( 'module.loaded',        self.onModuleLoaded )		
		signals.connect( 'asset.deploy.changed', self.onAssetDeployChanged )

		self.creatorMenu=self.addMenu(
			'asset_create_context',
			{ 'label':'Create' }
		)
		self.addMenuItem(
			'main/asset/asset_create', dict( label = 'Create', shortcut ='Ctrl+N' )
		)
		self.addMenuItem(
			'main/find/find_asset',   dict( label = 'Find Asset', shortcut = 'ctrl+T' )
		)
		self.addMenuItem(
			'main/find/open_asset',   dict( label = 'Open Asset', shortcut = 'ctrl+O' )
		)

		self.assetContextMenu=self.addMenu('asset_context')
		self.assetContextMenu.addChild([
				{'name':'show_in_browser', 'label':'Show File'},
				{'name':'open_in_system', 'label':'Open In System'},
				{'name':'copy_node_path', 'label':'Copy Asset Path'},
				'----',
				{'name':'clone', 'label':'Clone'},
				'----',
				{'name':'reimport', 'label':'Reimport'},
				'----',
				{'name':'deploy_set', 'label':'Set Deploy'},
				{'name':'deploy_unset', 'label':'Unset Deploy'},
				{'name':'deploy_disallow', 'label':'Disallow Deploy'},
				'----',
				{'name':'create', 'label':'Create', 'link':self.creatorMenu},
			])

		signals.connect( 'selection.changed', self.onSelectionChanged )
		registerSearchEnumerator( assetCreatorSearchEnumerator  )

	def onStart( self ):
		assetLib = self.getAssetLibrary()
		assetLib.scheduleScanProject()
		signals.connect( 'asset.register',   self.onAssetRegister )
		signals.connect( 'asset.unregister', self.onAssetUnregister )
		signals.connect( 'asset.moved',      self.onAssetMoved )
		signals.connect( 'asset.modified',   self.onAssetModified )

		self.treeView.rebuild()

		initialSelection = self.getConfig( 'current_selection', None )
		if initialSelection:
			nodes = [ assetLib.getAssetNode( path ) for path in initialSelection ]
			self.treeView.selectNode( nodes )

		splitterSizes = self.getConfig( 'splitter_sizes', None )
		if splitterSizes:
			self.splitter.setSizes( splitterSizes )

	def onStop( self ):
		self.setConfig( 'current_selection', [ node.getPath() for node in self.currentFolders ] )
		self.setConfig( 'splitter_sizes', self.splitter.sizes() )
		self.treeView.saveTreeStates()

	def onSetFocus( self ):
		self.getMainWindow().raise_()
		self.treeView.setFocus()
		self.window.raise_()

	def onUnload(self):
		#persist expand state
		# self.treeView.saveTreeStates()

		pass

	def onModuleLoaded(self):				
		for creator in self.getAssetLibrary().assetCreators:
			self.loadAssetCreator(creator)

	def setAssetIcon(self, assetType, iconName):
		self.assetIconMap[assetType] = iconName

	def locateAsset( self, asset, **options ):
		if isinstance( asset, ( str, unicode ) ): #path
			asset = self.getAssetLibrary().getAssetNode( asset )
		if not asset: return
		self.listView.setFocus( Qt.MouseFocusReason)
		self.selectAsset( asset, goto = True )
{'fraction_non_alphanumeric': 0.14861935727075676, 'fraction_numerical': 0.0030157383846951278, 'mean_word_length': 3.7502238137869295, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1062737', 'n_tokens_mistral': 3808, 'n_tokens_neox': 3303, 'n_words': 625}