<s> from PyQt4 import QtCore , QtGui <EOL> import sys , urllib2 <EOL> try : <EOL> from opentumblrqt . gui . main_ui import Main_widget <EOL> from opentumblrqt . tumblr import Api , TumblrAuthError <EOL> from opentumblrqt . dashboard import Dashboard <EOL> from opentumblrqt . gui . TumblrTray import TumblrTray <EOL> except ImportError : <EOL> from gui . main_ui import Main_widget <EOL> from tumblr import Api , TumblrAuthError <EOL> from dashboard import Dashboard <EOL> from gui . TumblrTray import TumblrTray <EOL> errors = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> class Cliente_Opentumblr ( Main_widget ) : <EOL> def __init__ ( self , parent = None ) : <EOL> super ( Main_widget , self ) . __init__ ( parent ) <EOL> self . setupUi ( ) <EOL> self . connect ( self . bt_login , QtCore . SIGNAL ( '<STR_LIT>' ) , self . OnAuthTumblr ) <EOL> self . rememberme . setCheckState ( QtCore . Qt . Unchecked ) <EOL> if ( QtCore . QFile ( ) . exists ( QtCore . QDir ( ) . homePath ( ) + '<STR_LIT>' ) ) : <EOL> file = open ( QtCore . QDir ( ) . homePath ( ) + '<STR_LIT>' , '<STR_LIT:r>' ) <EOL> self . le_mail . setText ( file . readline ( ) ) <EOL> self . le_url . setText ( file . readline ( ) ) <EOL> def OnAuthTumblr ( self ) : <EOL> self . User = self . le_mail . text ( ) . trimmed ( ) <EOL> self . Password = self . le_password . text ( ) <EOL> self . Blog = self . le_url . text ( ) . trimmed ( ) <EOL> self . error = None <EOL> if not self . User . isEmpty ( ) | self . Password . isEmpty ( ) | self . Blog . isEmpty ( ) : <EOL> self . api = Api ( self . Blog , self . User , self . Password ) <EOL> try : <EOL> self . auth = self . api . auth_check ( ) <EOL> if QtGui . QSystemTrayIcon . isSystemTrayAvailable ( ) : <EOL> self . hide ( ) <EOL> tray = TumblrTray ( self ) <EOL> else : <EOL> dashboard = Dashboard ( self ) <EOL> self . hide ( ) <EOL> dashboard . show ( ) <EOL> if self . rememberme . checkState ( ) == <NUM_LIT:2> : <EOL> file = open ( QtCore . QDir ( ) . homePath ( ) + '<STR_LIT>' , '<STR_LIT:w>' ) <EOL> file . write ( self . le_mail . text ( ) ) <EOL> file . write ( self . le_url . text ( ) ) <EOL> except TumblrAuthError : <EOL> self . error = errors [ '<STR_LIT>' ] <EOL> except urllib2 . HTTPError : <EOL> self . error = errors [ '<STR_LIT>' ] <EOL> except urllib2 . URLError : <EOL> self . error = errors [ '<STR_LIT>' ] <EOL> finally : <EOL> if self . error != None : <EOL> QtGui . QMessageBox . warning ( self , '<STR_LIT>' , '<STR_LIT>' + self . error , QtGui . QMessageBox . Ok ) <EOL> else : <EOL> QtGui . QMessageBox . warning ( self , '<STR_LIT>' , '<STR_LIT>' , QtGui . QMessageBox . Ok ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> app = QtGui . QApplication ( sys . argv ) <EOL> tumblr_client = Cliente_Opentumblr ( ) <EOL> tumblr_client . show ( ) <EOL> app . connect ( app , QtCore . SIGNAL ( '<STR_LIT>' ) , app , QtCore . SLOT ( '<STR_LIT>' ) ) <EOL> sys . exit ( app . exec_ ( ) ) </s>
