Esempio n. 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')
Esempio n. 2
0
 def Export( self ):
     
     width = self._width.value()
     
     payload_description = self._payload_description.text()
     payload_bytes = ClientSerialisable.GetPayloadBytes( self._payload_obj )
     
     title = self._title.text()
     text = self._text.text()
     path = self._filepicker.GetPath()
     
     if path is not None and path != '':
         
         base_dir = os.path.dirname( path )
         
         HG.client_controller.new_options.SetNoneableString( 'last_png_export_dir', base_dir )
         
     
     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')
def ImportFromPNG(win: QW.QWidget,
                  gallery_seed_log: ClientImportGallerySeeds.GallerySeedLog,
                  can_generate_more_pages: bool):

    with QP.FileDialog(win,
                       'select the png with the urls',
                       wildcard='PNG (*.png)') as dlg:

        if dlg.exec() == QW.QDialog.Accepted:

            path = dlg.GetPath()

            try:

                payload_string = ClientSerialisable.LoadStringFromPNG(path)

                urls = GetURLsFromURLsString(payload_string)

                ImportURLs(win, gallery_seed_log, urls,
                           can_generate_more_pages)

            except:

                QW.QMessageBox.critical(win, 'Error', 'Could not import!')

                raise
Esempio n. 4
0
 def _ImportPngs( self, paths ):
     
     for path in paths:
         
         try:
             
             payload = ClientSerialisable.LoadFromPng( path )
             
         except Exception as e:
             
             QW.QMessageBox.critical( self, 'Error', str(e) )
             
             return
             
         
         try:
             
             obj = HydrusSerialisable.CreateFromNetworkBytes( payload )
             
             self._ImportObject( obj )
             
         except:
             
             QW.QMessageBox.critical( self, 'Error', 'I could not understand what was encoded in the file!' )
             
             return
    def _ImportPNGs(self, paths):

        have_shown_load_error = False

        for path in paths:

            try:

                payload = ClientSerialisable.LoadFromPNG(path)

            except Exception as e:

                QW.QMessageBox.critical(self, 'Error', str(e))

                return

            try:

                obj = HydrusSerialisable.CreateFromNetworkBytes(
                    payload, raise_error_on_future_version=True)

                self._ImportObject(obj)

            except HydrusExceptions.SerialisationException as e:

                if not have_shown_load_error:

                    message = str(e)

                    if len(paths) > 1:

                        message += os.linesep * 2
                        message += 'If there are more objects in this import with similar load problems, they will now be skipped silently.'

                    QW.QMessageBox.critical(self, 'Problem loading', str(e))

                    have_shown_load_error = True

            except:

                QW.QMessageBox.critical(
                    self, 'Error',
                    'I could not understand what was encoded in "{}"!'.format(
                        path))

                return
Esempio n. 6
0
 def _ImportFromPng( self ):
     
     with QP.FileDialog( self, 'select the png with the urls', wildcard = 'PNG (*.png)' ) as dlg:
         
         if dlg.exec() == QW.QDialog.Accepted:
             
             path = dlg.GetPath()
             
             payload = ClientSerialisable.LoadFromPng( path )
             
             try:
                 
                 urls = self._GetURLsFromURLsString( payload )
                 
                 self._ImportURLs( urls )
                 
             except:
                 
                 QW.QMessageBox.critical( self, 'Error', 'Could not import!' )
                 
                 raise
    def _ImportFromPNG(self):

        with QP.FileDialog(self,
                           'select the png with the sources',
                           wildcard='PNG (*.png)') as dlg:

            if dlg.exec() == QW.QDialog.Accepted:

                path = dlg.GetPath()

                try:

                    payload_string = ClientSerialisable.LoadStringFromPNG(path)

                    sources = self._GetSourcesFromSourcesString(payload_string)

                    self._ImportSources(sources)

                except:

                    QW.QMessageBox.critical(self, 'Error', 'Could not import!')

                    raise
Esempio n. 8
0
def ImportFromPNG(win: QW.QWidget,
                  file_seed_cache: ClientImportFileSeeds.FileSeedCache):

    with QP.FileDialog(win,
                       'select the png with the sources',
                       wildcard='PNG (*.png)') as dlg:

        if dlg.exec() == QW.QDialog.Accepted:

            path = dlg.GetPath()

            try:

                payload_string = ClientSerialisable.LoadStringFromPNG(path)

                sources = GetSourcesFromSourcesString(payload_string)

                ImportSources(file_seed_cache, sources)

            except:

                QW.QMessageBox.critical(win, 'Error', 'Could not import!')

                raise
Esempio n. 9
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 )