def importConfigFrom15(overwrite=True): if not isdir(confDirOld): print 'directory "%s" does not exist'%confDirOld return if not isdir(confDir): os.mkdir(confDir) for fname in ('hijri.conf', 'jalali.conf'): old_path = join(confDirOld, fname) if isfile(old_path): new_path = join(confDir, fname) if overwrite or not isfile(new_path): shutil.copy(old_path, new_path) ''' plugDirOld = join(confDirOld, 'plugins') if isdir(plugDirOld): if not isdir(plugDir): os.mkdir(plugDir) for fname in os.listdir(plugDirOld): old_path = join(plugDirOld, fname) new_path = join(plugDir, fname) if isfile(old_path): try: shutil.copy(old_path, new_path) except: pass elif isdir(old_path): try: shutil.copytree(old_path, new_path) except: pass ''' pref = join(confDirOld, 'pref') if isfile(pref): loadPlug = loadPlugin exec(open(pref).read()) locale_conf = join(confDir, 'locale.conf') if overwrite or not isfile(locale_conf): lang = ['', 'en_US.UTF-8', 'fa_IR.UTF-8', 'ar_IQ.UTF-8'][lang] open(locale_conf, 'w').write('lang=%r'%lang) core_conf = join(confDir, 'core.conf') if overwrite or not isfile(core_conf): open(core_conf, 'w').write(\ ''' holidayWeekDays=%r firstWeekDayAuto=%r firstWeekDay=%r weekNumberModeAuto=%r weekNumberMode=%r'''%(holidayWeekDays, firstWeekDayAuto, firstWeekDay, weekNumberModeAuto, weekNumberMode)) ui_conf = join(confDir, 'ui.conf') if overwrite or not isfile(ui_conf): for item in shownDates: item['font'] = gfontDecode(item['font']) item['color'] = gdkColorToRgb(item['color']) fontCustom = gfontDecode(fontCustom) mcalGridColor = wcalGridColor = gdkColorToRgb(gridColor) + (gridAlpha/257,) bgColor = gdkColorToRgb(bgColor) + (bgColorAlpha/257,) borderColor = gdkColorToRgb(borderColor) + (borderColorAlpha/257,) borderTextColor = gdkColorToRgb(borderTextColor) holidayColor = gdkColorToRgb(holidayColor) inactiveColor = gdkColorToRgb(inactiveColor) + (inactiveColorAlpha/257,) cursorOutColor = gdkColorToRgb(cursorOutColor) cursorBgColor = gdkColorToRgb(cursorBgColor) + (cursorBgAlpha/257,) pluginsTextTray = extradayTray maxDayCacheSize = maxCache*30 maxWeekCacheSize = maxCache*4 text = '' for name in ( 'showMain', 'winTaskbar', 'showDigClockTr', 'mcalGrid', 'mcalGridColor', 'wcalGridColor', 'fontCustom', 'fontCustomEnable', 'bgUseDesk', 'bgColor', 'borderColor', 'cursorOutColor', 'cursorBgColor', 'holidayColor', 'inactiveColor', 'borderTextColor', 'dragIconCell', 'maxDayCacheSize', 'maxWeekCacheSize' 'pluginsTextTray', 'showYmArrows', 'prefPagesOrder', ): text += '%s = %r\n'%(name, eval(name)) open(ui_conf, 'w').write(text) ui_gtk_conf = join(confDir, 'ui-gtk.conf') if overwrite or not isfile(ui_gtk_conf): from scal2.ui_gtk.utils import stock_arrow_repr open(ui_gtk_conf, 'w').write(\ '''dateFormat=%r clockFormat=%r '''%( dateFormat, clockFormat, )) live_conf_old = join(confDirOld, 'live-confg') if isfile(live_conf_old): live_conf = join(confDir, 'ui-live.conf') if overwrite or not isfile(live_conf): exec(open(live_conf_old).read()) text = '' for name in ('winX', 'winY', 'winWidth', 'winKeepAbove', 'winSticky'): text += '%s = %r\n'%(name, eval(name)) open(live_conf, 'w').write(text) if calHeightReq>0: mcalHeight = calHeightReq open(join(confDir, 'ui-customize.conf'), 'w').write('ui.mcalHeight=%s'%mcalHeight)
def apply(self, widget=None): from scal2.ui_gtk.font_utils import gfontDecode ####### FIXME #print('fontDefault = %s'%ui.fontDefault) ui.fontDefault = gfontDecode(ud.settings.get_property('gtk-font-name')) #print('fontDefault = %s'%ui.fontDefault) ############################################## Updating pref variables for opt in self.getAllPrefItems(): opt.updateVar() ###### DB Manager (Plugin Manager) index = [] for row in self.plugTreestore: plugI = row[0] enable = row[1] show_date = row[2] index.append(plugI) plug = core.allPlugList[plugI] if plug.loaded: try: plug.enable = enable plug.show_date = show_date except: core.myRaise(__file__) print(i, core.plugIndex) else: if enable: plug = plugin_man.loadPlugin(plug.path) assert plug.loaded core.allPlugList[plugI] = plug core.plugIndex = index core.updatePlugins() ###### first = self.comboFirstWD.get_active() if first==7: core.firstWeekDayAuto = True try: core.firstWeekDay = core.getLocaleFirstWeekDay() except: pass else: core.firstWeekDayAuto = False core.firstWeekDay = first ###### mode = self.comboWeekYear.get_active() if mode==8: core.weekNumberModeAuto = True core.weekNumberMode = core.getLocaleweekNumberMode() else: core.weekNumberModeAuto = False core.weekNumberMode = mode ###### ui.cellCache.clear() ## Very important, specially when calTypes.primary will be changed ###### ud.updateFormatsBin() #################################################### Saving Preferences for mod in calTypes: mod.save() ##################### Saving locale config text = '' for item in self.localePrefItems: text += item.confStr() open(locale_man.localeConfPath, 'w').write(text) ##################### Saving core config text = '' text += 'version=%r\n\n'%core.VERSION text += 'allPlugList=%s\n\n'%core.getAllPlugListRepr() text += 'plugIndex=%r\n'%core.plugIndex for item in self.corePrefItems: text += item.confStr() for key in ( 'firstWeekDayAuto', 'firstWeekDay', 'weekNumberModeAuto', 'weekNumberMode', 'debugMode', ): value = eval('core.'+key) text += '%s=%r\n'%(key, value) open(core.confPath, 'w').write(text) ##################### Saving ui config text = '' for item in self.uiPrefItems: text += item.confStr() for key in ( #'localTzHist',## FIXME 'showYmArrows', ): value = eval('ui.'+key) text += '%s=%r\n'%(key, value) text += 'prefPagesOrder=%s\n'%repr( tuple( [self.notebook.page_num(page) for page in self.prefPages] ) ) open(ui.confPath, 'w').write(text) ##################### Saving here config text = '' for item in self.gtkPrefItems: text += item.confStr() text += 'adjustTimeCmd=%r\n'%ud.adjustTimeCmd ## FIXME open(ud.confPath, 'w').write(text) ################################################### Updating GUI ud.windowList.onConfigChange() if ui.mainWin: """ if ui.bgUseDesk and ui.bgColor[3]==255: msg = gtk.MessageDialog(buttons=gtk.BUTTONS_OK_CANCEL, message_format=_( 'If you want to have a transparent calendar (and see your desktop),'+\ 'change the opacity of calendar background color!')) if msg.run()==gtk.RESPONSE_OK: self.colorbBg.emit('clicked') msg.destroy() """ if ui.checkNeedRestart(): d = gtk.Dialog(_('Need Restart '+core.APP_DESC), self, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT | gtk.DIALOG_NO_SEPARATOR, (gtk.STOCK_CANCEL, 0)) d.set_keep_above(True) label = gtk.Label(_('Some preferences need for restart %s to apply.'%core.APP_DESC)) label.set_line_wrap(True) pack(d.vbox, label) resBut = d.add_button(_('_Restart'), 1) resBut.set_image(gtk.image_new_from_stock(gtk.STOCK_REFRESH,gtk.ICON_SIZE_BUTTON)) resBut.grab_default() d.vbox.show_all() if d.run()==1: core.restart() else: d.destroy()
windowList = IntegatedWindowList() ########### if rtl: gtk.widget_set_default_direction(gtk.TEXT_DIR_RTL) gtk.window_set_default_icon_from_file(ui.logo) settings = gtk.settings_get_default() ## ui.timeout_initial = settings.get_property('gtk-timeout-initial') ## == 200 FIXME ## ui.timeout_repeat = settings.get_property('gtk-timeout-repeat') ## == 20 too small!! FIXME ui.initFonts(gfontDecode(settings.get_property('gtk-font-name'))) ########### textDirDict = { 'ltr': gtk.TEXT_DIR_LTR, 'rtl': gtk.TEXT_DIR_RTL, 'auto': gtk.TEXT_DIR_NONE, } ############################## #if ui.fontCustomEnable:## FIXME # settings.set_property('gtk-font-name', fontCustom) dateFormat = '%Y/%m/%d'
def getGtkDefaultFont(): fontName = settings.get_property("gtk-font-name") font = gfontDecode(fontName) font[3] = max(5, font[3]) return font
def importConfigFrom15(overwrite=True): if not isdir(confDirOld): print('directory "%s" does not exist' % confDirOld) return if not isdir(confDir): os.mkdir(confDir) for fname in ('hijri.conf', 'jalali.conf'): old_path = join(confDirOld, fname) if isfile(old_path): new_path = join(confDir, fname) if overwrite or not isfile(new_path): shutil.copy(old_path, new_path) ''' plugDirOld = join(confDirOld, 'plugins') if isdir(plugDirOld): if not isdir(plugDir): os.mkdir(plugDir) for fname in os.listdir(plugDirOld): old_path = join(plugDirOld, fname) new_path = join(plugDir, fname) if isfile(old_path): try: shutil.copy(old_path, new_path) except: pass elif isdir(old_path): try: shutil.copytree(old_path, new_path) except: pass ''' pref = join(confDirOld, 'pref') if isfile(pref): loadPlug = loadPlugin exec(open(pref).read()) locale_conf = join(confDir, 'locale.conf') if overwrite or not isfile(locale_conf): lang = ['', 'en_US.UTF-8', 'fa_IR.UTF-8', 'ar_IQ.UTF-8'][lang] open(locale_conf, 'w').write('lang=%r' % lang) core_conf = join(confDir, 'core.conf') if overwrite or not isfile(core_conf): open(core_conf, 'w').write(\ ''' holidayWeekDays=%r firstWeekDayAuto=%r firstWeekDay=%r weekNumberModeAuto=%r weekNumberMode=%r'''%(holidayWeekDays, firstWeekDayAuto, firstWeekDay, weekNumberModeAuto, weekNumberMode)) ui_conf = join(confDir, 'ui.conf') if overwrite or not isfile(ui_conf): for item in shownDates: item['font'] = gfontDecode(item['font']) item['color'] = gdkColorToRgb(item['color']) fontCustom = gfontDecode(fontCustom) mcalGridColor = wcalGridColor = gdkColorToRgb(gridColor) + ( gridAlpha / 257, ) bgColor = gdkColorToRgb(bgColor) + (bgColorAlpha / 257, ) borderColor = gdkColorToRgb(borderColor) + (borderColorAlpha / 257, ) borderTextColor = gdkColorToRgb(borderTextColor) holidayColor = gdkColorToRgb(holidayColor) inactiveColor = gdkColorToRgb(inactiveColor) + ( inactiveColorAlpha / 257, ) cursorOutColor = gdkColorToRgb(cursorOutColor) cursorBgColor = gdkColorToRgb(cursorBgColor) + (cursorBgAlpha / 257, ) pluginsTextStatusIcon = extradayTray maxDayCacheSize = maxCache * 30 maxWeekCacheSize = maxCache * 4 text = '' for name in ( 'showMain', 'winTaskbar', 'showDigClockTr', 'mcalGrid', 'mcalGridColor', 'wcalGridColor', 'fontCustom', 'fontCustomEnable', 'bgUseDesk', 'bgColor', 'borderColor', 'cursorOutColor', 'cursorBgColor', 'holidayColor', 'inactiveColor', 'borderTextColor', 'dragIconCell', 'maxDayCacheSize', 'maxWeekCacheSize' 'pluginsTextStatusIcon', 'showYmArrows', 'prefPagesOrder', ): text += '%s = %r\n' % (name, eval(name)) open(ui_conf, 'w').write(text) ui_gtk_conf = join(confDir, 'ui-gtk.conf') if overwrite or not isfile(ui_gtk_conf): from scal2.ui_gtk.utils import stock_arrow_repr open(ui_gtk_conf, 'w').write(\ '''dateFormat=%r clockFormat=%r '''%( dateFormat, clockFormat, )) live_conf_old = join(confDirOld, 'live-confg') if isfile(live_conf_old): live_conf = join(confDir, 'ui-live.conf') if overwrite or not isfile(live_conf): exec(open(live_conf_old).read()) text = '' for name in ('winX', 'winY', 'winWidth', 'winKeepAbove', 'winSticky'): text += '%s = %r\n' % (name, eval(name)) open(live_conf, 'w').write(text) if calHeightReq > 0: mcalHeight = calHeightReq open(join(confDir, 'ui-customize.conf'), 'w').write('ui.mcalHeight=%s' % mcalHeight)