def decimal_to_dms(decimal): """Convert decimal degrees into degrees, minutes, seconds.""" remainder, degrees = split_float(abs(decimal)) remainder, minutes = split_float(remainder * 60) return [ Rational(degrees, 1), Rational(minutes, 1), float_to_rational(remainder * 60) ]
def decimal_to_dms(decimal): """Convert decimal degrees into degrees, minutes, seconds. >>> decimal_to_dms(50.445891) [Fraction(50, 1), Fraction(26, 1), Fraction(113019, 2500)] >>> decimal_to_dms(-125.976893) [Fraction(125, 1), Fraction(58, 1), Fraction(92037, 2500)] """ remainder, degrees = split_float(abs(decimal)) remainder, minutes = split_float(remainder * 60) return [Fraction(n) for n in (degrees, minutes, remainder * 60)]
def display_offset(offset, value, add, subtract): """Display minutes and seconds in the offset GtkScale. >>> display_offset(None, 10, 'Add %d, %d', 'Subtract %d, %d') 'Add 0, 10' >>> display_offset(None, 100, 'Add %d, %d', 'Subtract %d, %d') 'Add 1, 40' >>> display_offset(None, -100, 'Add %d, %d', 'Subtract %d, %d') 'Subtract 1, 40' """ seconds, minutes = split_float(abs(value) / 60) return (subtract if value < 0 else add) % (minutes, int(seconds * 60))
def timezone_handler(self, *ignore): """Set the timezone to the chosen zone and update all photos.""" environ['TZ'] = '' if self.timezone_method == 'lookup': # Note that this will gracefully fallback on system timezone # if no timezone has actually been found yet. environ['TZ'] = self.found_timezone elif self.timezone_method == 'offset': minutes, hours = split_float(-float(self.utc_offset)) environ['TZ'] = 'UTC{:+}:{:02}'.format( int(hours), int(abs(minutes) * 60)) elif self.timezone_method == 'custom' and \ self.timezone_region and self.timezone_city: environ['TZ'] = '/'.join( [self.timezone_region, self.timezone_city]) tzset() self.offset_handler()
def timezone_handler(self, *ignore): """Set the timezone to the chosen zone and update all photos.""" environ['TZ'] = '' if self.timezone_method == 'lookup': # Note that this will gracefully fallback on system timezone # if no timezone has actually been found yet. environ['TZ'] = self.found_timezone elif self.timezone_method == 'offset': minutes, hours = split_float(-float(self.utc_offset)) environ['TZ'] = 'UTC{:+}:{:02}'.format(int(hours), int(abs(minutes) * 60)) elif self.timezone_method == 'custom' and \ self.timezone_region and self.timezone_city: environ['TZ'] = '/'.join( [self.timezone_region, self.timezone_city]) tzset() self.offset_handler()
def display_offset(offset, value, add, subtract): """Display the offset spinbutton as M:SS.""" seconds, minutes = split_float(abs(value) / 60) return (subtract if value < 0 else add) % (minutes, int(seconds * 60))