Example #1
0
class Add( QMainWindow ):
	def __init__( self, parent = None ):
		QWidget.__init__( self, parent)
		self.parent = parent

		self.ui = Ui_AddDive()
		self.ui.setupUi( self )
		
		self.ui.IDate.setDateTime( QDateTime.currentDateTime() )
		try:
			if db.query( "SELECT MAX( number ) FROM dive").fetchall()[0][0] == None:
				number = 1
			else:
				number = db.query( "SELECT MAX( number ) FROM dive").fetchall()[0][0]+1
			self.ui.INumber.setText( str( number ) )
		except sqlite3.Error, e:
			QMessageBox.critical( self, "Error", str( e ).capitalize() )
		
		QObject.connect( self.ui.Add, SIGNAL( "clicked()"), self.add )
		QObject.connect( self.ui.Cancel, SIGNAL( "clicked()"), self.close )
		
		self.show()
Example #2
0
	def __init__( self, parent = None ):
		QWidget.__init__( self, parent)
		self.parent = parent

		self.ui = Ui_AddDive()
		self.ui.setupUi( self )
		
		self.ui.IDate.setDateTime( QDateTime.currentDateTime() )
		try:
			if db.query( "SELECT MAX( number ) FROM dive").fetchall()[0][0] == None:
				number = 1
			else:
				number = db.query( "SELECT MAX( number ) FROM dive").fetchall()[0][0]+1
			self.ui.INumber.setText( str( number ) )
		except sqlite3.Error, e:
			QMessageBox.critical( self, "Error", str( e ).capitalize() )
Example #3
0
	def __init__( self, parent = None ):
		QWidget.__init__( self, parent )
		self.parent = parent
		
		self.ui = Ui_AddDive()
		self.ui.setupUi( self )
		
		#Connect buttons
		QObject.connect( self.ui.Add, SIGNAL( "clicked()"), self.edit )
		QObject.connect( self.ui.Cancel, SIGNAL( "clicked()"), self.close )
		
		#Edit the add window to edit stuff
		self.ui.Add.setText( "Edit" )
		self.setWindowTitle( "Edit dive" )
		
		if not hasattr( self.parent, "dive"):
			QMessageBox.critical( self, "Error", "Please select a dive first." )
			self.close()
			return
			
		#Set Values
		self.ui.INumber.setText( str( self.parent.dive['number'] ) )
		self.ui.ILocation.setText( str( self.parent.dive['location'] ) )
			
		self.ui.IDate.setDateTime( QDateTime( QDate( int( self.parent.dive['divedate'].split("-")[0]), int( self.parent.dive['divedate'].split("-")[1]), int( self.parent.dive['divedate'].split("-")[1])), QTime(0, 0, 0) ) )
		if self.parent.dive['time_in'] != 0:
			self.ui.ITimeIn.setTime( QTime( int( self.parent.dive['time_in'].split(":")[0] ), int( self.parent.dive['time_in'].split(":")[1] ), 0 ) )
		else:
			self.ui.ITimeIn.setTime( QTime( 0, 0, 0 ) )
		if self.parent.dive['time_out'] != 0:
			self.ui.ITimeOut.setTime( QTime( int( self.parent.dive['time_out'].split(":")[0] ), int( self.parent.dive['time_out'].split(":")[1] ), 0 ) )
		else:
			self.ui.ITimeOut.setTime( QTime( 0, 0, 0 ) )
			
		self.ui.IBarIn.setValue( self.parent.dive['bar_in'] )
		self.ui.IBarOut.setValue( self.parent.dive['bar_out'] )
		self.ui.ITemperature.setValue( self.parent.dive['temperature'] )
		self.ui.ISight.setValue( self.parent.dive['sight'] )
		self.ui.ILead.setValue( self.parent.dive['lead'] )
		self.ui.IDepth.setValue( self.parent.dive['depth'] )
		self.ui.ITime.setText( str( self.parent.dive['time'] ) )
		self.ui.INotes.setPlainText( str( self.parent.dive['notes'] ) )
		
		self.show()
Example #4
0
class Edit( QMainWindow ):
	def __init__( self, parent = None ):
		QWidget.__init__( self, parent )
		self.parent = parent
		
		self.ui = Ui_AddDive()
		self.ui.setupUi( self )
		
		#Connect buttons
		QObject.connect( self.ui.Add, SIGNAL( "clicked()"), self.edit )
		QObject.connect( self.ui.Cancel, SIGNAL( "clicked()"), self.close )
		
		#Edit the add window to edit stuff
		self.ui.Add.setText( "Edit" )
		self.setWindowTitle( "Edit dive" )
		
		if not hasattr( self.parent, "dive"):
			QMessageBox.critical( self, "Error", "Please select a dive first." )
			self.close()
			return
			
		#Set Values
		self.ui.INumber.setText( str( self.parent.dive['number'] ) )
		self.ui.ILocation.setText( str( self.parent.dive['location'] ) )
			
		self.ui.IDate.setDateTime( QDateTime( QDate( int( self.parent.dive['divedate'].split("-")[0]), int( self.parent.dive['divedate'].split("-")[1]), int( self.parent.dive['divedate'].split("-")[1])), QTime(0, 0, 0) ) )
		if self.parent.dive['time_in'] != 0:
			self.ui.ITimeIn.setTime( QTime( int( self.parent.dive['time_in'].split(":")[0] ), int( self.parent.dive['time_in'].split(":")[1] ), 0 ) )
		else:
			self.ui.ITimeIn.setTime( QTime( 0, 0, 0 ) )
		if self.parent.dive['time_out'] != 0:
			self.ui.ITimeOut.setTime( QTime( int( self.parent.dive['time_out'].split(":")[0] ), int( self.parent.dive['time_out'].split(":")[1] ), 0 ) )
		else:
			self.ui.ITimeOut.setTime( QTime( 0, 0, 0 ) )
			
		self.ui.IBarIn.setValue( self.parent.dive['bar_in'] )
		self.ui.IBarOut.setValue( self.parent.dive['bar_out'] )
		self.ui.ITemperature.setValue( self.parent.dive['temperature'] )
		self.ui.ISight.setValue( self.parent.dive['sight'] )
		self.ui.ILead.setValue( self.parent.dive['lead'] )
		self.ui.IDepth.setValue( self.parent.dive['depth'] )
		self.ui.ITime.setText( str( self.parent.dive['time'] ) )
		self.ui.INotes.setPlainText( str( self.parent.dive['notes'] ) )
		
		self.show()
	
	def edit( self ):
		# Set error to None
		error = None
		# Check some requirements
		if self.ui.INumber.displayText() == "":
			error = True
			QMessageBox.critical( self, "Error", "Dive number is required." )
		if self.ui.IDepth.value() == 0.0:
			error = True
			QMessageBox.critical( self, "Error", "Depth is required." )
		if ( self.ui.ITimeIn.time().toString( "HH:mm" ) == "00:00" and self.ui.ITimeOut.time().toString( "HH:mm" ) == "00:00" ) and self.ui.ITime.displayText() == "":
			error = True
			QMessageBox.critical( self, "Error", "Time in/out or dive time is required." )
		if self.ui.ILocation.displayText() == "":
			error = True
			QMessageBox.critical( self, "Error", "Location is required." )
		
		if not error:
			try:
				if self.ui.ITimeIn.time().toString( "HH:mm" ) == "00:00" and self.ui.ITimeOut.time().toString( "HH:mm" ) == "00:00":
					db.query( """UPDATE dive SET number='"""+str(self.ui.INumber.displayText() )+"""', depth='"""+str( float( self.ui.IDepth.value()) )+"""', divedate='"""+str( self.ui.IDate.dateTime().toString( "yyyy-MM-dd") )+"""', time_in='0', time_out='0', time='"""+str( float( self.ui.ITime.displayText() ) )+"""', bar_in='"""+str( self.ui.IBarIn.value() )+"""', bar_out='"""+str( self.ui.IBarOut.value() )+"""', lead='"""+str( self.ui.ILead.value() )+"""', temperature='"""+str( self.ui.ITemperature.value() )+"""', sight ='"""+str( self.ui.ISight.value() )+"""', location='"""+db.escaped( str( self.ui.ILocation.displayText() ) )+"""', notes='"""+db.escaped( str( self.ui.INotes.toPlainText() ) )+"""' WHERE number = """+str( self.parent.dive['number'] ) )
					
					self.parent.updateListDives()
					QMessageBox.information( self, "Succes", "The dive has succesfully been edited" )
					self.close()
				else:
					if self.ui.ITimeOut.time().toString( "HH:mm" ) == "00:00":
						db.query( """UPDATE dive SET number='"""+str(self.ui.INumber.displayText() )+"""', depth='"""+str( float( self.ui.IDepth.value()) )+"""', divedate='"""+str( self.ui.IDate.dateTime().toString( "yyyy-MM-dd") )+"""', time_in='"""+str( self.ui.ITimeIn.time().toString( "HH:mm") )+"""', time_out='24:00', time=round(strftime('%s', '24:00') - strftime('%s', '"""+str( self.ui.ITimeIn.time().toString( "HH:mm") )+"""'))/3600*60, bar_in='"""+str( self.ui.IBarIn.value() )+"""', bar_out='"""+str( self.ui.IBarOut.value() )+"""', lead='"""+str( self.ui.ILead.value() )+"""', temperature='"""+str( self.ui.ITemperature.value() )+"""', sight ='"""+str( self.ui.ISight.value() )+"""', location='"""+db.escaped( str( self.ui.ILocation.displayText() ) )+"""', notes='"""+db.escaped( str( self.ui.INotes.toPlainText() ) )+"""' WHERE number = """+str( self.parent.dive['number'] ) )
						
						self.parent.updateListDives()
						QMessageBox.information( self, "Succes", "The dive has succesfully been edited" )
						self.close()
					else:
						db.query( """UPDATE dive SET number='"""+str(self.ui.INumber.displayText() )+"""', depth='"""+str( float( self.ui.IDepth.value()) )+"""', divedate='"""+str( self.ui.IDate.dateTime().toString( "yyyy-MM-dd") )+"""', time_in='"""+str( self.ui.ITimeIn.time().toString( "HH:mm") )+"""', time_out='"""+str( self.ui.ITimeOut.time().toString( "HH:mm") )+"""', time=round(strftime('%s', '"""+str( self.ui.ITimeOut.time().toString( "HH:mm") )+"""') - strftime('%s', '"""+str( self.ui.ITimeIn.time().toString( "HH:mm") )+"""'))/3600*60, bar_in='"""+str( self.ui.IBarIn.value() )+"""', bar_out='"""+str( self.ui.IBarOut.value() )+"""', lead='"""+str( self.ui.ILead.value() )+"""', temperature='"""+str( self.ui.ITemperature.value() )+"""', sight ='"""+str( self.ui.ISight.value() )+"""', location='"""+db.escaped( str( self.ui.ILocation.displayText() ) )+"""', notes='"""+db.escaped( str( self.ui.INotes.toPlainText() ) )+"""' WHERE number = """+str( self.parent.dive['number'] ) )
					
						self.parent.updateListDives()
						QMessageBox.information( self, "Succes", "The dive has succesfully been edited" )
						self.close()
			except ( sqlite3.Error, ValueError ), e:
				QMessageBox.critical( self, "Error", str( e ).capitalize() )