<s> from PyQt4 import QtCore , QtGui <EOL> import string <EOL> try : <EOL> from opentumblrqt . gui . photo_ui import Photo_widget <EOL> from opentumblrqt . tumblr import Api , TumblrError <EOL> except ImportError : <EOL> from gui . photo_ui import Photo_widget <EOL> from tumblr import Api , TumblrError <EOL> class Photo ( Photo_widget ) : <EOL> def __init__ ( self , parent = None ) : <EOL> super ( Photo_widget , self ) . __init__ ( parent ) <EOL> self . setupUi ( self ) <EOL> self . api = parent . api <EOL> self . connect ( self . bt_cancel , QtCore . SIGNAL ( "<STR_LIT>" ) , self . OnCancel ) <EOL> self . connect ( self . bt_post , QtCore . SIGNAL ( "<STR_LIT>" ) , self . OnPost ) <EOL> self . connect ( self . bt_browse , QtCore . SIGNAL ( "<STR_LIT>" ) , self . OnBrowse ) <EOL> self . connect ( self . lb_useurl , QtCore . SIGNAL ( "<STR_LIT>" ) , self . OnUseUrl ) <EOL> def OnCancel ( self ) : <EOL> self . hide ( ) <EOL> def OnPost ( self ) : <EOL> self . source = unicode ( self . le_imageurl . text ( ) ) . encode ( '<STR_LIT:utf-8>' ) <EOL> if not self . source : <EOL> self . source = None <EOL> self . data = unicode ( self . le_file . text ( ) ) . encode ( '<STR_LIT:utf-8>' ) <EOL> if not self . data : <EOL> self . data = None <EOL> if self . te_caption . te_post . toPlainText ( ) . isEmpty ( ) : <EOL> self . caption = '<STR_LIT>' <EOL> else : <EOL> self . caption = unicode ( self . te_caption . te_post . toPlainText ( ) ) . encode ( '<STR_LIT:utf-8>' ) <EOL> if self . le_link . text ( ) . isEmpty ( ) : <EOL> self . click = '<STR_LIT>' <EOL> else : <EOL> self . click = unicode ( self . le_link . text ( ) ) . encode ( '<STR_LIT:utf-8>' ) <EOL> if self . advanced . te_tags . document ( ) . isEmpty ( ) : <EOL> self . tags = '<STR_LIT>' <EOL> else : <EOL> self . tags = unicode ( self . advanced . te_tags . toPlainText ( ) ) . encode ( '<STR_LIT:utf-8>' ) <EOL> self . tags = string . replace ( self . tags , '<STR_LIT:U+0020>' , '<STR_LIT:U+002C>' ) <EOL> self . date = self . advanced . le_date . text ( ) <EOL> if self . advanced . cb_publish . currentText ( ) == '<STR_LIT>' : <EOL> self . private = <NUM_LIT:1> <EOL> else : <EOL> self . private = <NUM_LIT:0> <EOL> if self . source or self . data : <EOL> self . api = Api ( self . api . name , self . api . email , self . api . password , self . private , self . date , self . tags ) <EOL> try : <EOL> self . post = self . api . write_photo ( self . source , self . data , self . caption , self . click ) <EOL> except : <EOL> print "<STR_LIT>" <EOL> self . close ( ) <EOL> else : <EOL> QtGui . QMessageBox . warning ( self , "<STR_LIT>" , "<STR_LIT>" , QtGui . QMessageBox . Ok ) <EOL> def OnBrowse ( self ) : <EOL> ImageDialog = QtGui . QFileDialog ( self ) <EOL> filename = ImageDialog . getOpenFileName ( self , "<STR_LIT>" , QtCore . QDir . homePath ( ) , "<STR_LIT>" ) <EOL> self . le_file . setText ( filename ) <EOL> def OnUseUrl ( self , text ) : <EOL> self . le_file . setText ( "<STR_LIT>" ) <EOL> self . le_file . setVisible ( False ) <EOL> self . bt_browse . setVisible ( False ) <EOL> self . le_imageurl . setVisible ( True ) <EOL> self . lb_photo . setText ( "<STR_LIT>" ) <EOL> self . lb_useurl . setVisible ( False ) <EOL> self . le_imageurl . setFocus ( ) <EOL> def closeEvent ( self , event ) : <EOL> event . ignore ( ) <EOL> self . hide ( ) </s>
