Ejemplo n.º 1
0
 def openChart2Event(self):
     tr = self.tr
     idx = self.dock.tabs.currentIndex()
     path = unicode(
         QFileDialog.getOpenFileName(self, tr('Open chart 2'),
                                     os.path.expanduser(cfg.charts_dir),
                                     tr('Oroboros (*.xml)')))
     if path != '':
         cht = Chart(path)
         app.replaceChart(idx, 1, cht)
Ejemplo n.º 2
0
 def __setitem__(self, idx, cht):
     if idx > 1 or idx < -2:
         raise IndexError('Invalid index %s.' % idx)
     if not isinstance(cht, Chart):
         try:
             cht = Chart(cht)
         except:
             raise TypeError('Invalic chart %s.' % cht)
     list.__setitem__(self, idx, cht)
     self.calc()
Ejemplo n.º 3
0
 def openMultiChartEvent(self):
     """Open oroboros chart file."""
     tr = self.tr
     path = unicode(
         QFileDialog.getOpenFileName(self, tr('Open chart'),
                                     os.path.expanduser(cfg.charts_dir),
                                     tr('Oroboros (*.xml)')))
     if path != '':
         cht = Chart(path)
         app.appendMultiChart(cht)
Ejemplo n.º 4
0
    def append(self, cht):
        """Append a chart.
		
		:type cht: Chart, str or int
		:raise TypeError: invalid chart
		"""
        if not isinstance(cht, Chart):
            try:
                cht = Chart(cht)
            except:
                raise
                raise TypeError('Invalic chart %s.' % cht)
        list.append(self, cht)
        self.calc()
Ejemplo n.º 5
0
    def insert(self, idx, cht):
        """Insert a chart.
		
		:type idx: int
		:type cht: Chart, str or int
		:raise IndexError: invalid index
		:raise TypeError: invalid chart
		"""
        if idx > 1 or idx < -2:
            raise IndexError('Invalid index %s.' % idx)
        if not isinstance(cht, Chart):
            try:
                cht = Chart(cht)
            except:
                raise TypeError('Invalic chart %s.' % cht)
        list.insert(self, idx, cht)
        self.calc()
Ejemplo n.º 6
0
def load(path):
    """Load skif and return chart object (not calculated).
	
	:type path: str
	:rtype: Chart
	"""
    path = os.path.abspath(os.path.expanduser(path))
    f = xmlutils.parse(path)
    data = f.get_child(tag='DATASET')
    # name
    name = data.get_child_text(tag='NAME')
    # datetime
    year = int(data.get_child_attr('Year', tag='DATE'))
    month = int(data.get_child_attr('Month', tag='DATE'))
    day = int(data.get_child_attr('Day', tag='DATE'))
    hm = data.get_child_attr('Hm', tag='DATE')
    hour, minute = [int(x) for x in hm.split(':')]
    datetime = (year, month, day, hour, minute, 0)
    # location
    location = data.get_child_text(tag='PLACE')
    # country
    country = data.get_child_text(tag='COUNTRY')
    # zoneinfo, utcoffset, dst
    zoneinfo = data.get_child_attr('ZoneInfoFile', tag='COUNTRY')
    if zoneinfo == '':  # need utcoffset
        utcoff = data.get_child_attr('Timezone', tag='DATE')
        h, m = [int(x) for x in utcoff.split(':')]
        utcoffset = -(h + (m / 60.0))
    else:
        utcoffset = ''
    if data.get_child_attr('Daylight', tag='DATE') != '0:00':
        dst = True
    else:
        dst = False
    # adjust utc offset
    if utcoffset != '':
        if dst == True:
            utcoffset -= 1
    # geocoords
    lat = data.get_child_attr('Latitude', tag='PLACE')
    latdg, latmn = lat[:-1].split(':')
    latdr = lat[-1]
    latitude = (int(latdg), latdr, int(latmn), 0)
    lon = data.get_child_attr('Longitude', tag='PLACE')
    londg, lonmn = lon[:-1].split(':')
    londr = lon[-1]
    longitude = (int(londg), londr, int(lonmn), 0)
    # comments
    comment = 'Imported from Skylendar.\n'
    comment += 'Chart type: %s\n' % data.get_child_text(tag='TYPE')
    comment += 'Gender: %s\n' % data.get_child_attr('Gender', tag='TYPE')
    comment += 'Keywords: %s\n' % data.get_child_text(tag='KEYWORDS')
    comment += 'Comment: %s' % data.get_child_text(tag='COMMENT')
    # ...
    cht = Chart(set_default=False, do_calc=False)
    cht.set(name=name,
            datetime=datetime,
            location=location,
            country=country,
            zoneinfo=zoneinfo,
            dst=dst,
            utcoffset=utcoffset,
            latitude=latitude,
            longitude=longitude,
            altitude=0,
            comment=comment)
    return cht
Ejemplo n.º 7
0
def load(path):
	"""Load an astrolog32 file. Return chart (no positions calculated).
	
	:rtype: Chart
	"""
	path = os.path.abspath(os.path.expanduser(path))
	f = file(path)
	lines = f.read().split('\n')
	f.close()
	for line in [x.strip() for x in lines]:
		if not line.startswith('/'):
			continue
		if line.startswith('/qb'):
			line = line[4:]
			# get date and time, latitude, longitude
			prts = line.split(' ')
			parts = list()
			for i, p in enumerate(prts):
				if p != '':
					parts.append(p)
			# datetime
			mth, d, y, time, stdt, offset, lon, lat = parts
			h, m, s = time.split(':')
			dt = [int(x) for x in (y, mth, d, h, m, s)]
			# longitude
			try:
				londg, rest = lon.split(':')
				lonmn, rest = rest.split("'")
				lonsc, londr = rest[:2], rest[-1]
			except ValueError:
				londg, lonmn, lonsc = lon.split(':')
				lonsc, londr = lonsc[:1], lonsc[-1]
			longitude = (londg, londr, lonmn, lonsc)
			# latitude
			try:
				latdg, rest = lat.split(':')
				latmn, rest = rest.split("'")
				latsc, latdr = rest[:2], rest[-1]
			except ValueError:
				latdg, latmn, latsc = lat.split(':')
				latsc, latdr = latsc[:1], latsc[-1]
			latitude = (latdg, latdr, latmn, latsc)
			# get utc offset
			hoffset, moffset = offset.split(':')
			soffset, hoffset = hoffset[0], int(hoffset[1:])
			moffset = int(moffset) / 60.0
			hoffset += moffset
			if soffset == '+': # a32 inverts utc offsets
				hoffset = -hoffset
			if stdt == 'DT':
				hoffset += 1
				dst = True
			else:
				dst = False
		if line.startswith('/zi'):
			line = line[4:]
			name, location = line[1:-1].split('" "')
	try:
		cht = Chart(set_default=False, do_calc=False)
		cht.name = name
		cht.location = location
		cht.country = '?'
		cht.datetime = dt
		cht.longitude = longitude
		cht.latitude = latitude
		cht.utcoffset = hoffset
		cht.dst = dst
		cht.comment = 'Imported from Astrolog32'
	except:
		raise
	return cht
Ejemplo n.º 8
0
 def hereNowMultiChartEvent(self):
     """Create a default here-now chart."""
     app.appendMultiChart(Chart())
Ejemplo n.º 9
0
def load(path):
    """Load an astrolog32 file. Return chart (no positions calculated).
	
	:rtype: Chart
	"""
    path = os.path.abspath(os.path.expanduser(path))
    f = file(path)
    lines = f.read().split('\n')
    f.close()
    for line in [x.strip() for x in lines]:
        if not line.startswith('/'):
            continue
        if line.startswith('/qb'):
            line = line[4:]
            # get date and time, latitude, longitude
            prts = line.split(' ')
            parts = list()
            for i, p in enumerate(prts):
                if p != '':
                    parts.append(p)
            # datetime
            mth, d, y, time, stdt, offset, lon, lat = parts
            h, m, s = time.split(':')
            dt = [int(x) for x in (y, mth, d, h, m, s)]
            # longitude
            try:
                londg, rest = lon.split(':')
                lonmn, rest = rest.split("'")
                lonsc, londr = rest[:2], rest[-1]
            except ValueError:
                londg, lonmn, lonsc = lon.split(':')
                lonsc, londr = lonsc[:1], lonsc[-1]
            longitude = (londg, londr, lonmn, lonsc)
            # latitude
            try:
                latdg, rest = lat.split(':')
                latmn, rest = rest.split("'")
                latsc, latdr = rest[:2], rest[-1]
            except ValueError:
                latdg, latmn, latsc = lat.split(':')
                latsc, latdr = latsc[:1], latsc[-1]
            latitude = (latdg, latdr, latmn, latsc)
            # get utc offset
            hoffset, moffset = offset.split(':')
            soffset, hoffset = hoffset[0], int(hoffset[1:])
            moffset = int(moffset) / 60.0
            hoffset += moffset
            if soffset == '+':  # a32 inverts utc offsets
                hoffset = -hoffset
            if stdt == 'DT':
                hoffset += 1
                dst = True
            else:
                dst = False
        if line.startswith('/zi'):
            line = line[4:]
            name, location = line[1:-1].split('" "')
    try:
        cht = Chart(set_default=False, do_calc=False)
        cht.name = name
        cht.location = location
        cht.country = '?'
        cht.datetime = dt
        cht.longitude = longitude
        cht.latitude = latitude
        cht.utcoffset = hoffset
        cht.dst = dst
        cht.comment = 'Imported from Astrolog32'
    except:
        raise
    return cht
Ejemplo n.º 10
0
	def __init__(self, idx=-1, num=0, parent=None):
		QDialog.__init__(self, parent)
		self._parent = parent
		tr = self.tr
		idx = int(idx)
		if idx == -1:
			chart = Chart(do_calc=False)
			title = tr('New Chart')
		else:
			try:
				chart = app.desktop.charts[idx][num]
				title = unicode(tr('Edit Chart \xab %(chart)s \xbb')) % {
					'chart': chart._name}
			except IndexError:
				chart = Chart(do_calc=False)
				title = unicode(tr('New SubChart'))
		self._chart = chart
		self._idx = idx
		self._num = num
		self.setWindowTitle(title)
		# set width/height
		self.setMinimumWidth(280)
		self.setMinimumHeight(400)
		self.setSizeGripEnabled(True)
		# layout
		grid = QGridLayout(self)
		self.setLayout(grid)
		# name
		grid.addWidget(QLabel(tr('Name')), 0, 0)
		self.nameEdit = QLineEdit(self)
		grid.addWidget(self.nameEdit, 0, 1)
		# datetime
		lbl = QLabel(tr('DateTime'))
		lbl.setToolTip(tr('Local date & time'))
		grid.addWidget(lbl, 1, 0)
		self.datetimeEdit = QDateTimeEdit(self)
		self.datetimeEdit.setDisplayFormat(tr('yyyy-MM-dd hh:mm:ss',
			'Datetime format'))
		self.datetimeEdit.setButtonSymbols(QAbstractSpinBox.PlusMinus)
		self.datetimeEdit.setCalendarPopup(True)
		self.datetimeEdit.setMinimumDateTime(QDateTime(-5400, 1, 1, 0, 0))
		self.datetimeEdit.setMaximumDateTime(QDateTime(5400, 1, 1, 0, 0))
		grid.addWidget(self.datetimeEdit, 1, 1)
		# calendar
		grid.addWidget(QLabel(tr('Calendar')), 2, 0)
		self.calendarEdit = QComboBox(self)
		self.calendarEdit.addItems([tr('Gregorian'), tr('Julian')])
		self.calendarEdit.setEditable(False)
		grid.addWidget(self.calendarEdit, 2, 1)
		# location
		lbl = QLabel(tr('<a href="http://www.astro.com/atlas">Location</a>'))
		lbl.setOpenExternalLinks(True)
		grid.addWidget(lbl, 3, 0)
		self.locationEdit = QLineEdit(self)
		grid.addWidget(self.locationEdit, 3, 1)
		# country
		grid.addWidget(QLabel(tr('Country')), 4, 0)
		self.countryEdit = QLineEdit(self)
		grid.addWidget(self.countryEdit, 4, 1)
		# latitude
		grid.addWidget(QLabel(tr('Latitude')), 5, 0)
		self.latitudeEdit = LatitudeEdit(chart._latitude, self)
		grid.addLayout(self.latitudeEdit, 5, 1)
		# longitude
		grid.addWidget(QLabel(tr('Longitude')), 6, 0)
		self.longitudeEdit = LongitudeEdit(chart._longitude, self)
		grid.addLayout(self.longitudeEdit, 6, 1)
		# altitude
		grid.addWidget(QLabel(tr('Altitude')), 7, 0)
		geoLayout = QHBoxLayout() ## geolayout
		grid.addLayout(geoLayout, 7, 1)
		self.altitudeEdit = AltitudeEdit(chart._altitude, self)
		geoLayout.addWidget(self.altitudeEdit)
		# query geonames
		geoButton = QToolButton(self)
		geoButton.setIcon(QIcon(os.path.join(_baseDir, 'icons',
			'earth-icon.png')))
		geoButton.setToolTip(tr('Query GeoNames.org'))
		self.connect(geoButton, SIGNAL('clicked()'), self.queryGeoNames)
		geoLayout.addWidget(geoButton)
		# zoneinfo
		lbl = QLabel(tr('<a href="http://en.wikipedia.org/wiki/List_of_zoneinfo_timezones">Zoneinfo</a>'))
		lbl.setToolTip(tr('Posix timezone file (for charts after 1900)'))
		lbl.setOpenExternalLinks(True)
		grid.addWidget(lbl, 8, 0)
		self.zoneinfoEdit = QComboBox(self)
		alltz = pytz.all_timezones[:]
		alltz.insert(0, '')
		self.zoneinfoEdit.addItems(alltz)
		self.zoneinfoEdit.setEditable(False)
		grid.addWidget(self.zoneinfoEdit, 8, 1)
		# dst
		lbl = QLabel(tr('Dst'))
		lbl.setToolTip(tr('Daylight saving time (for ambiguous dates only)'))
		grid.addWidget(lbl, 9, 0)
		self.dstEdit = QComboBox(self)
		self.dstEdit.addItems([tr('Not needed'), tr('Yes'), tr('No')])
		grid.addWidget(self.dstEdit, 9, 1)
		# timezone
		lbl = QLabel(tr('<a href="http://upload.wikimedia.org/wikipedia/en/e/e7/Timezones2008.png">Timezone</a>'))
		lbl.setToolTip(tr('Standard timezone (for local mean time)'))
		lbl.setOpenExternalLinks(True)
		grid.addWidget(lbl, 10, 0)
		self.timezoneEdit = QComboBox(self)
		alltz = [str(x) for x in timezone.all_timezones]
		alltz.insert(0, '')
		self.timezoneEdit.addItems(alltz)
		self.timezoneEdit.setEditable(False)
		grid.addWidget(self.timezoneEdit, 10, 1)
		# utc offset
		lbl = QLabel(tr('Utc offset'))
		lbl.setToolTip(
			tr('Coordinated universal time offset (for charts before 1900)'))
		grid.addWidget(lbl, 11, 0)
		self.utcoffsetEdit = QDoubleSpinBox(self)
		self.utcoffsetEdit.setDecimals(2)
		self.utcoffsetEdit.setMinimum(-25)
		self.utcoffsetEdit.setMaximum(24)
		self.utcoffsetEdit.setSuffix(tr(' h.'))
		self.utcoffsetEdit.setSpecialValueText(tr('Not needed'))
		self.utcoffsetEdit.setButtonSymbols(QAbstractSpinBox.PlusMinus)
		grid.addWidget(self.utcoffsetEdit, 11, 1)
		# comment
		lbl = QLabel(tr('Comment'))
		lbl.setToolTip(tr('Accepts reStructured Text'))
		grid.addWidget(lbl, 12, 0, Qt.AlignTop)
		self.commentEdit = QTextEdit('', self)
		grid.addWidget(self.commentEdit, 12, 1)
		# keywords
		lbl = QLabel(tr('Keywords'))
		lbl.setToolTip(tr('Line-separated "key: word" pairs'))
		grid.addWidget(lbl, 13, 0, Qt.AlignTop)
		self.keywordsEdit = QTextEdit('', self)
		grid.addWidget(self.keywordsEdit, 13, 1)
		# buttons
		buttonsLayout = QHBoxLayout()
		resetButton = QPushButton(tr('Reset'), self)
		self.connect(resetButton, SIGNAL('clicked()'), self.reset)
		buttonsLayout.addWidget(resetButton)
		cancelButton = QPushButton(tr('Cancel'), self)
		self.connect(cancelButton, SIGNAL('clicked()'), self.reject)
		buttonsLayout.addWidget(cancelButton)
		okButton = QPushButton(tr('Ok'), self)
		okButton.setDefault(True)
		self.connect(okButton, SIGNAL('clicked()'), self.accept)
		buttonsLayout.addWidget(okButton)
		grid.addLayout(buttonsLayout, 14, 0, 1, 2)
		# fill entries
		self.reset()