def addClicked(self, button): fcd = gtk.FileChooserDialog( buttons=( toStr(_('_OK')), gtk.RESPONSE_OK, toStr(_('_Cancel')), gtk.RESPONSE_CANCEL, ), title=_('Add File'), ) fcd.set_local_only(True) fcd.connect('response', lambda w, e: fcd.hide()) if fcd.run() == gtk.RESPONSE_OK: from shutil import copy fpath = fcd.get_filename() fname = split(fpath)[-1] dstDir = self.event.filesDir ## os.makedirs(dstDir, exist_ok=True)## only on new pythons FIXME try: os.makedirs(dstDir) except: myRaise() copy(fpath, join(dstDir, fname)) self.event.files.append(fname) self.newFiles.append(fname) self.showFile(fname)
def importEvent(gevent, group): #open('/tmp/gevent.js', 'a').write('%s\n\n'%pformat(gevent)) icsData = [ ('DTSTART', encodeIcsStartEnd(gevent['start'])), ('DTEND', encodeIcsStartEnd(gevent['end'])), ] ## recurring = False if 'recurrence' in gevent: recurring = True for recStr in gevent['recurrence']: key, value = recStr.upper().split(':') ## multi line? FIXME icsData.append((key, value)) try: eventType = gevent['extendedProperties']['shared']['starcal_type'] except KeyError: if recurring: eventType = 'custom' else: eventType = 'task' ## event = group.createEvent(eventType) event.mode = DATE_GREG ## FIXME if not event.setIcsData(dict(icsData)): return event.summary = toStr(gevent['summary']) event.description = toStr(gevent.get('description', '')) if 'reminders' in gevent: try: minutes = gevent['reminders']['overrides']['minutes'] except KeyError: myRaise() ## FIXME else: self.notifyBefore = (minutes, 60) return event
def duplicateGroupTitle(group): title = toStr(group.title) titleList = [toStr(g.title) for g in eventGroups] parts = title.split('#') try: index = int(parts[-1]) title = '#'.join(parts[:-1]) except: #myRaise() index = 1 index += 1 while True: newTitle = title + '#%d' % index if newTitle not in titleList: group.title = newTitle return index += 1
def duplicateGroupTitle(group): title = toStr(group.title) titleList = [toStr(g.title) for g in eventGroups] parts = title.split('#') try: index = int(parts[-1]) title = '#'.join(parts[:-1]) except: #myRaise() index = 1 index += 1 while True: newTitle = title + '#%d'%index if newTitle not in titleList: group.title = newTitle return index += 1
def tr(s, *a, **ka): if isinstance(s, (int, long, float)): s = numEncode(s, *a, **ka) else: s = transObj.gettext(toStr(s)).decode('utf-8') if ui_is_qt: s = s.replace(u'_', u'&') if a: s = s % a if ka: s = s % ka return s
def tr(s, *a, **ka): if isinstance(s, (int, long)): s = numEncode(s, *a, **ka) else: s = transObj.gettext(toStr(s)).decode('utf-8') if ui_is_qt: s = s.replace(u'_', u'&') if a: s = s % a if ka: s = s % ka return s
def addClicked(self, button): fcd = gtk.FileChooserDialog( buttons=( toStr(_('_OK')), gtk.RESPONSE_OK, toStr(_('_Cancel')), gtk.RESPONSE_CANCEL, ), title=_('Add File'), ) fcd.connect('response', lambda w, e: fcd.hide()) if fcd.run() == gtk.RESPONSE_OK: fpath = fcd.get_filename() fname = split(fpath)[-1] dstDir = self.event.filesDir ## os.makedirs(dstDir, exist_ok=True)## only on new pythons FIXME try: os.makedirs(dstDir) except: myRaise() shutil.copy(fpath, join(dstDir, fname)) self.event.files.append(fname) self.newFiles.append(fname) self.showFile(fname)
def importEvent(gevent, group): if gevent['status'] != 'confirmed':## FIXME return open('/tmp/gevent.js', 'a').write('%s\n\n'%pformat(gevent)) icsData = [ ('DTSTART', encodeIcsStartEnd(gevent['start'])), ('DTEND', encodeIcsStartEnd(gevent['end'])), ] ## recurring = False if 'recurrence' in gevent: key, value = gevent['recurrence'].upper().split(':')## multi line? FIXME icsData.append((key, value)) recurring = True try: eventType = gevent['extendedProperties']['shared']['starcal_type'] except KeyError: if recurring: eventType = 'custom' else: eventType = 'task' ## event = group.createEvent(eventType) event.mode = DATE_GREG ## FIXME if not event.setIcsDict(dict(icsData)): return event.summary = toStr(gevent['summary']) event.description = toStr(gevent.get('description', '')) if 'reminders' in gevent: try: minutes = gevent['reminders']['overrides']['minutes'] except: pass## FIXME else: self.notifyBefore = (minutes, 60) return event
def copy(self, item): start = self.get_property('selection-bound') end = self.get_property('cursor-position') self.clipboard.set_text(toStr(toUnicode(self.get_text())[start:end]))
def copy(self, item, label): bound = label.get_property('selection-bound') cursor = label.get_property('cursor-position') start = min(bound, cursor) end = max(bound, cursor) setClipboard(toStr(toUnicode(label.get_text())[start:end]))
def setClipboard(text, clipboard=None): if not clipboard: clipboard = gtk.clipboard_get(gdk.SELECTION_CLIPBOARD) text = toStr(text) clipboard.set_text(text)
def copy(self, item, label): bound = label.get_property('selection-bound') cursor = label.get_property('cursor-position') start = min(bound, cursor) end = max(bound, cursor) self.clipboard.set_text(toStr(toUnicode(label.get_text())[start:end]))
def exportToHtml(fpath, monthsStatus, title=''): ##################### Options: format = ((2, 'SUB'), (0, None), (1, 'SUB')) ## (dateMode, htmlTag) sizeMap = lambda size: size*0.25 - 0.5 ## ??????????????? sep = ' ' pluginsTextSep = ' <B>ـ</B> ' pluginsTextPerLine = True ## description of each day in one line ##################### dates = ui.shownCals ##################### bgColor = rgbToHtml(*ui.bgColor) inactiveColor = rgbToHtml(*colorComposite(ui.inactiveColor, ui.bgColor)) borderColor= rgbToHtml(*colorComposite(ui.borderColor, ui.bgColor)) borderTextColor = rgbToHtml(*ui.borderTextColor) holidayColor = rgbToHtml(*ui.holidayColor) colors = [rgbToHtml(*x['color']) for x in dates] if rtl: DIR = 'RTL' else: DIR = 'LRT' text = '''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=utf-8"> <TITLE>%s</TITLE> </HEAD> <BODY LANG="%s" DIR="%s" BGCOLOR="%s">\n'''%(title, core.langSh, DIR, bgColor) for status in monthsStatus: mDesc = getMonthDesc(status).split('\n') text += ' <P>\n' for i in xrange(len(dates)): if dates[i]['enable']: text += ' <FONT COLOR="%s">%s</FONT>\n <BR>\n'%(colors[i], mDesc[i]) text += ' </P>\n' text += ''' <TABLE WIDTH=100%% BGCOLOR="%s" BORDER=%s BORDERCOLOR="#000000" CELLPADDING=4 CELLSPACING=0> <TR VALIGN=TOP>\n'''\ %(bgColor, int(ui.mcalGrid)) text += ''' <TD WIDTH=9%% BGCOLOR="%s"> <P ALIGN=CENTER></P> </TD>\n'''%borderColor## what text???????? for j in xrange(7): text += ''' <TD WIDTH=13%% BGCOLOR="%s"> <P ALIGN=CENTER> <FONT COLOR="%s"><B>%s</B></FONT> </P> </TD>\n'''%(borderColor, borderTextColor, core.getWeekDayN(j)) pluginsText = '<P><FONT COLOR="%s">\n'%colors[0] text += ' </TR>\n' for i in xrange(6): text += ''' <TR VALIGN=TOP> <TD WIDTH=9%% BGCOLOR="%s"> <P ALIGN=CENTER> <FONT COLOR="%s"><B>%s</B></FONT> </P> </TD>\n'''%(borderColor, borderTextColor, _(status.weekNum[i])) for j in xrange(7): cell = status[i][j] text += ' <TD WIDTH=13%>\n <P DIR="LTR" ALIGN=CENTER>\n' for (ind, tag) in format: if not dates[ind]['enable']: continue mode = dates[ind]['mode'] day = _(cell.dates[mode][2], mode)## , 2 font = dates[ind]['font'] face = font[0] if font[1]: face += ' Bold' if font[2]: face += ' Underline' size = str(sizeMap(font[3])) if cell.month != status.month: if ind==0: text += ' ' if tag: text += '<%s>'%tag text += '<FONT COLOR="%s" FACE="%s" SIZE="%s">%s</FONT>'%( inactiveColor, face, size, day, ) if tag: text += '</%s>'%tag text += '\n' break else: continue text += ' ' if tag: text += '<%s>'%tag if ind==0 and cell.holiday: color = holidayColor else: color = colors[ind] text += '<FONT COLOR="%s" FACE="%s" SIZE="%s">%s</FONT>'%(color, face, size, day) if tag: text += '</%s>'%tag text += '\n' #text += sep##??????????? text += ' </P>\n </TD>\n' if cell.month == status.month: if cell.holiday: color = holidayColor else: color = colors[0] t = cell.pluginsText.replace('\n', pluginsTextSep) if t: pluginsText += '<B><FONT COLOR="%s">%s</FONT>:</B> <SMALL>%s</SMALL>'%( color, _(cell.dates[core.primaryMode][2]), t, ) if pluginsTextPerLine: pluginsText += '<BR>\n' else: pluginsText += ' \n' text += ' </TR>\n' pluginsText += ' </FONT></P>\n' text += ' </TABLE>\n' text = toStr(text) ## needed for windows text += pluginsText text += '\n<P STYLE="border-bottom: 5pt double %s"></P>\n'%colors[0] text += ''' <P> <FONT COLOR="%s">%s <A HREF="%s">%s</A> %s %s</FONT> </P> </BODY> </HTML>'''%( colors[0], toStr(_('Generated by')), core.homePage, core.APP_DESC, toStr(_('version')), core.VERSION, ) open(fpath, 'w').write(text)
def exportToHtml(fpath, monthsStatus, title=''): ##################### Options: format = ((2, 'SUB'), (0, None), (1, 'SUB')) ## (dateMode, htmlTag) sizeMap = lambda size: size * 0.25 - 0.5 ## ??????????????? sep = ' ' pluginsTextSep = ' <B>ـ</B> ' pluginsTextPerLine = True ## description of each day in one line ##################### bgColor = rgbToHtml(*ui.bgColor) inactiveColor = rgbToHtml(*colorComposite(ui.inactiveColor, ui.bgColor)) borderColor = rgbToHtml(*colorComposite(ui.borderColor, ui.bgColor)) borderTextColor = rgbToHtml(*ui.borderTextColor) textColor = rgbToHtml(*ui.textColor) holidayColor = rgbToHtml(*ui.holidayColor) colors = [rgbToHtml(*x['color']) for x in ui.mcalTypeParams] if locale_man.rtl: DIR = 'RTL' else: DIR = 'LRT' text = '''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=utf-8"> <TITLE>%s</TITLE> </HEAD> <BODY LANG="%s" DIR="%s" BGCOLOR="%s">\n''' % (title, locale_man.langSh, DIR, bgColor) for status in monthsStatus: text += ' <P>\n' for i, line in enumerate(getMonthDesc(status).split('\n')): try: color = colors[i] except IndexError: color = textColor text += ' <FONT COLOR="%s">%s</FONT>\n <BR>\n' % ( color, line) text += ' </P>\n' text += ''' <TABLE WIDTH=100%% BGCOLOR="%s" BORDER=%s BORDERCOLOR="#000000" CELLPADDING=4 CELLSPACING=0> <TR VALIGN=TOP>\n'''\ %(bgColor, int(ui.mcalGrid)) text += ''' <TD WIDTH=9%% BGCOLOR="%s"> <P ALIGN=CENTER></P> </TD>\n''' % borderColor ## what text???????? for j in range(7): text += ''' <TD WIDTH=13%% BGCOLOR="%s"> <P ALIGN=CENTER> <FONT COLOR="%s"><B>%s</B></FONT> </P> </TD>\n''' % (borderColor, borderTextColor, core.getWeekDayN(j)) pluginsText = '<P><FONT COLOR="%s">\n' % colors[0] text += ' </TR>\n' for i in range(6): text += ''' <TR VALIGN=TOP> <TD WIDTH=9%% BGCOLOR="%s"> <P ALIGN=CENTER> <FONT COLOR="%s"><B>%s</B></FONT> </P> </TD>\n''' % (borderColor, borderTextColor, _(status.weekNum[i])) for j in range(7): cell = status[i][j] text += ' <TD WIDTH=13%>\n <P DIR="LTR" ALIGN=CENTER>\n' for (ind, tag) in format: try: mode = calTypes.active[ind] except IndexError: continue try: params = ui.mcalTypeParams[ind] except IndexError: continue day = _(cell.dates[mode][2], mode) ## , 2 font = params['font'] face = font[0] if font[1]: face += ' Bold' if font[2]: face += ' Underline' size = str(sizeMap(font[3])) if cell.month != status.month: if ind == 0: text += ' ' if tag: text += '<%s>' % tag text += '<FONT COLOR="%s" FACE="%s" SIZE="%s">%s</FONT>' % ( inactiveColor, face, size, day, ) if tag: text += '</%s>' % tag text += '\n' break else: continue text += ' ' if tag: text += '<%s>' % tag if ind == 0 and cell.holiday: color = holidayColor else: color = colors[ind] text += '<FONT COLOR="%s" FACE="%s" SIZE="%s">%s</FONT>' % ( color, face, size, day) if tag: text += '</%s>' % tag text += '\n' #text += sep##??????????? text += ' </P>\n </TD>\n' if cell.month == status.month: if cell.holiday: color = holidayColor else: color = colors[0] t = cell.pluginsText.replace('\n', pluginsTextSep) if t: pluginsText += '<B><FONT COLOR="%s">%s</FONT>:</B> <SMALL>%s</SMALL>' % ( color, _(cell.dates[calTypes.primary][2]), t, ) if pluginsTextPerLine: pluginsText += '<BR>\n' else: pluginsText += ' \n' text += ' </TR>\n' pluginsText += ' </FONT></P>\n' text += ' </TABLE>\n' text = toStr(text) ## needed for windows text += pluginsText text += '\n<P STYLE="border-bottom: 5pt double %s"></P>\n' % colors[0] text += ''' <P> <FONT COLOR="%s">%s <A HREF="%s">%s</A> %s %s</FONT> </P> </BODY> </HTML>''' % ( colors[0], toStr(_('Generated by')), core.homePage, core.APP_DESC, toStr(_('version')), core.VERSION, ) open(fpath, 'w').write(text)