Пример #1
0
 def Export( self ):
     
     width = self._width.value()
     
     directory = self._directory_picker.GetPath()
     
     last_png_export_dir = directory
     
     if last_png_export_dir is not None and last_png_export_dir != '':
         
         HG.client_controller.new_options.SetNoneableString( 'last_png_export_dir', last_png_export_dir )
         
     
     for obj in self._payload_objs:
         
         ( payload_description, payload_bytes ) = ClientSerialisable.GetPayloadDescriptionAndBytes( obj )
         
         title = obj.GetName()
         text = ''
         path = os.path.join( directory, title )
         
         if not path.endswith( '.png' ):
             
             path += '.png'
             
         
         ClientSerialisable.DumpToPng( width, payload_bytes, title, payload_description, text, path )
         
     
     self._export.setText( 'done!' )
     
     HG.client_controller.CallLaterQtSafe(self._export, 2.0, self._export.setText, 'export')
Пример #2
0
 def __init__( self, parent, payload_obj, title = None, description = None, payload_description = None ):
     
     ClientGUIScrolledPanels.ReviewPanel.__init__( self, parent )
     
     self._payload_obj = payload_obj
     
     self._filepicker = QP.FilePickerCtrl( self, wildcard = 'PNG (*.png)' )
     self._filepicker.SetSaveMode( True )
     
     flp_width = ClientGUIFunctions.ConvertTextToPixelWidth( self._filepicker, 64 )
     
     self._filepicker.setMinimumWidth( flp_width )
     
     self._title = QW.QLineEdit( self )
     
     self._payload_description = QW.QLineEdit( self )
     
     self._text = QW.QLineEdit( self )
     
     self._width = QP.MakeQSpinBox( self, min=100, max=4096 )
     
     self._export = ClientGUICommon.BetterButton( self, 'export', self.Export )
     
     #
     
     if payload_description is None:
         
         ( payload_description, payload_bytes ) = ClientSerialisable.GetPayloadDescriptionAndBytes( self._payload_obj )
         
     else:
         
         payload_bytes = ClientSerialisable.GetPayloadBytes( self._payload_obj )
         
         payload_description += ' - ' + HydrusData.ToHumanBytes( len( payload_bytes ) )
         
     
     self._payload_description.setText( payload_description )
     
     self._payload_description.setEnabled( False )
     
     self._width.setValue( 512 )
     
     last_png_export_dir = HG.client_controller.new_options.GetNoneableString( 'last_png_export_dir' )
     
     if title is not None:
         
         name = title
         
     elif isinstance( self._payload_obj, HydrusSerialisable.SerialisableBaseNamed ):
         
         name = self._payload_obj.GetName()
         
     else:
         
         name = payload_description
         
     
     self._title.setText( name )
     
     if description is not None:
         
         self._text.setText( description )
         
     
     if last_png_export_dir is not None:
         
         filename = name + '.png'
         
         filename = HydrusPaths.SanitizeFilename( filename )
         
         path = os.path.join( last_png_export_dir, filename )
         
         self._filepicker.SetPath( path )
         
     
     self._Update()
     
     #
     
     rows = []
     
     rows.append( ( 'export path: ', self._filepicker ) )
     rows.append( ( 'title: ', self._title ) )
     rows.append( ( 'payload description: ', self._payload_description ) )
     rows.append( ( 'your description (optional): ', self._text ) )
     rows.append( ( 'png width: ', self._width ) )
     rows.append( ( '', self._export ) )
     
     gridbox = ClientGUICommon.WrapInGrid( self, rows )
     
     self.widget().setLayout( gridbox )
     
     self._filepicker.filePickerChanged.connect( self._Update )
     self._title.textChanged.connect( self._Update )