@@ -53,6 +53,7 @@ def __init__(self, settingsWidgetType, jobTypes=JobTypes.JobTypes, parent=None,
5353 super (CueSubmitWidget , self ).__init__ (parent )
5454 self .skipDataChangedEvent = False
5555 self .settings = QtCore .QSettings ('opencue' , 'cuesubmit' )
56+ self .clearMessageShown = False
5657 self .jobTypes = jobTypes
5758 self .primaryWidgetType = settingsWidgetType
5859 self .primaryWidgetArgs = {'args' : args , 'kwargs' : kwargs }
@@ -93,7 +94,7 @@ def __init__(self, settingsWidgetType, jobTypes=JobTypes.JobTypes, parent=None,
9394 self .jobNameInput = Widgets .CueLabelLineEdit (
9495 'Job Name:' ,
9596 tooltip = 'Job names must be unique, have more than 3 characters, and contain no spaces.' ,
96- completers = self .settings . value ('submit/jobName' ),
97+ completers = self .getFilteredHistorySetting ('submit/jobName' ),
9798 validators = [Validators .matchNoSpecialCharactersOnly , Validators .moreThan3Chars ,
9899 Validators .matchNoSpaces ]
99100 )
@@ -106,14 +107,14 @@ def __init__(self, settingsWidgetType, jobTypes=JobTypes.JobTypes, parent=None,
106107 self .shotInput = Widgets .CueLabelLineEdit (
107108 'Shot:' ,
108109 tooltip = 'Name of the shot associated with this submission.' ,
109- completers = self .settings . value ('submit/shotName' ),
110+ completers = self .getFilteredHistorySetting ('submit/shotName' ),
110111 validators = [Validators .matchNoSpecialCharactersOnly ]
111112 )
112113 self .layerNameInput = Widgets .CueLabelLineEdit (
113114 'Layer Name:' ,
114115 tooltip = 'Name for this layer of the job. Should be more than 3 characters, '
115116 'and contain no spaces.' ,
116- completers = self .settings . value ('submit/layerName' ),
117+ completers = self .getFilteredHistorySetting ('submit/layerName' ),
117118 validators = [Validators .matchNoSpecialCharactersOnly , Validators .moreThan3Chars ,
118119 Validators .matchNoSpaces ]
119120 )
@@ -324,6 +325,66 @@ def validate(self, jobData):
324325 'Please ensure all layers have a command to run.' )
325326 return True
326327
328+ def updateCompleters (self ):
329+ """Update the line edit completers after submission."""
330+ self .jobNameInput .lineEdit .completerStrings = self .getFilteredHistorySetting ('submit/jobName' )
331+ self .shotInput .lineEdit .completerStrings = self .getFilteredHistorySetting ('submit/shotName' )
332+ self .layerNameInput .lineEdit .completerStrings = self .getFilteredHistorySetting ('submit/layerName' )
333+
334+
335+ def getFilteredHistorySetting (self , setting ):
336+ """Return a list of strings for the provided setting.
337+ Filtering out any None objects.
338+ @type setting: str
339+ @param setting: name of setting to get
340+ @rtype: list<str>
341+ @return: A list of strings of setting values.
342+ """
343+ try :
344+ return [str (value ) for value in self .getHistorySetting (setting ) if value is not None ]
345+ except Exception :
346+ self .errorReadingSettings ()
347+ return []
348+
349+ def errorReadingSettings (self ):
350+ """Display an error message and clear the QSettings object."""
351+ if not self .clearMessageShown :
352+ Widgets .messageBox (
353+ "Previous submission history cannot be read from the QSettings."
354+ "Clearing submission history." ,
355+ title = "Cannot Read History" ,
356+ parent = self ).show ()
357+ self .clearMessageShown = True
358+ self .settings .clear ()
359+
360+ def getHistorySetting (self , setting ):
361+ """Return a list of strings for the provided setting.
362+ @type setting: str
363+ @param setting: name of setting to get
364+ @rtype: list<str>
365+ @return: A list of strings of setting values.
366+ """
367+ size = self .settings .beginReadArray ('history' )
368+ previousValues = []
369+ for settingIndex in range (size ):
370+ self .settings .setArrayIndex (settingIndex )
371+ previousValues .append (self .settings .value (setting ))
372+ self .settings .endArray ()
373+ return previousValues
374+
375+ def writeHistorySetting (self , setting , values ):
376+ """Update the QSettings object for the provided setting with values.
377+ @type setting: str
378+ @param setting: name of settings to set
379+ @type values: list<str>
380+ @param values: values to set as settings
381+ """
382+ self .settings .beginWriteArray ('history' )
383+ for settingIndex , savedValue in enumerate (values ):
384+ self .settings .setArrayIndex (settingIndex )
385+ self .settings .setValue (setting , savedValue )
386+ self .settings .endArray ()
387+
327388 def updateSettingItem (self , setting , value , maxSettings = 10 ):
328389 """Update the QSettings list entry for the provided setting.
329390 Keep around a history of the last `maxSettings` number of entries.
@@ -334,17 +395,22 @@ def updateSettingItem(self, setting, value, maxSettings=10):
334395 @type maxSettings: int
335396 @param maxSettings: maximum number of items to keep a history of
336397 """
337- if not value :
338- return
339- values = self .settings .value (setting , [])
340- if value in values :
341- index = values .index (value )
342- else :
343- index = - 1
344- if len (values ) == maxSettings or index != - 1 :
345- values .pop (index )
346- values .insert (0 , value )
347- self .settings .setValue (setting , values )
398+ try :
399+ if not value :
400+ return
401+ values = self .getHistorySetting (setting )
402+
403+ if value in values :
404+ index = values .index (value )
405+ else :
406+ index = - 1
407+ if len (values ) == maxSettings or index != - 1 :
408+ values .pop (index )
409+ values .insert (0 , value )
410+
411+ self .writeHistorySetting (setting , values )
412+ except Exception :
413+ self .errorReadingSettings ()
348414
349415 def saveSettings (self , jobData ):
350416 """Update the QSettings with the values from the form.
@@ -361,7 +427,9 @@ def submit(self):
361427 jobData = self .getJobData ()
362428 if not self .validate (jobData ):
363429 return
430+ self .clearMessageShown = False
364431 self .saveSettings (jobData )
432+ self .updateCompleters ()
365433 try :
366434 jobs = Submission .submitJob (jobData )
367435 except opencue .exception .CueException , e :
0 commit comments