1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
|
#!/usr/bin/env python3
# coding: koi8-r
# ====================================================
# Cycle - calendar for women
# Distributed under GNU Public License
# Author: Oleg S. Gints (altgo@users.sourceforge.net)
# Home page: http://cycle.sourceforge.net
# ===================================================
import builtins
import gettext
from set_dir import *
from dialogs import *
from save_load import *
from cal_year import *
import wx.lib.colourdb
import wx.html
import wx
import os
import sys
import gettext
import locale
#from prn import *
lang_find = False
if not '__WXMSW__' in wx.PlatformInfo:
for lang_env_var in ('LANGUAGE', 'LC_ALL', 'LC_CTYPE', 'LANG'):
if lang_find:
break
if lang_env_var in os.environ:
env_language = os.environ[lang_env_var]
for s_lang in env_language.split(':'): # if set more languages
os.environ[lang_env_var] = s_lang
try:
dl = locale.getdefaultlocale()
lang = [dl[0][0:2]]
l = gettext.translation('cycle', msg_dir, lang)
if wx.USE_UNICODE:
builtins.__dict__['_'] = lambda s: l.ugettext(s)
else:
builtins.__dict__['_'] = lambda s: l.ugettext(
s).encode(dl[1])
_('try decode this string')
lang_find = True
break # language was found
except:
pass
else: # for MS Windows
try:
dl = locale.getdefaultlocale()
lang = [dl[0][0:2]]
l = gettext.translation('cycle', msg_dir, lang)
if wx.USE_UNICODE:
builtins.__dict__['_'] = lambda s: l.ugettext(s)
else:
builtins.__dict__['_'] = lambda s: l.ugettext(s).encode(dl[1])
_('try decode this string')
lang_find = True
except:
pass
if not lang_find:
builtins.__dict__['_'] = lambda s: s
lang = [""]
class MyFrame(wx.Frame):
def __init__(self, parent, ID, title):
wx.Frame.__init__(self, parent, ID, title,
wx.DefaultPosition, wx.Size(800, 600))
# self.printer = wx.HtmlEasyPrinting()
icon = wx.Icon(os.path.join(
icons_dir, 'mini/cycle.xpm'), wx.BITMAP_TYPE_XPM)
self.SetIcon(icon)
Val.frame = self
self.CreateStatusBar()
self.MakeToolMenu() # toolbar
self.cal = Cal_Year(self)
self.OnCurrent(self)
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
def OnCloseWindow(self, event):
Save_Cycle(cycle.name, cycle.passwd, cycle.file)
self.Destroy()
def TimeToQuit(self, event):
self.Close(True)
def MakeToolMenu(self):
tb = self.CreateToolBar(wx.TB_HORIZONTAL | wx.NO_BORDER)
tb.SetToolBitmapSize(wx.Size(24, 24))
qDec=SetToolPath(self, tb, 10, os.path.join(
bitmaps_dir, 'dec.png'), _('Dec Year'))
self.Bind(wx.EVT_TOOL, self.OnDecYear, qDec)
qCurr=SetToolPath(self, tb, 20, os.path.join(
bitmaps_dir, 'curr.png'), _('Current Year'))
self.Bind(wx.EVT_TOOL, self.OnCurrent, qCurr)
qInc=SetToolPath(self, tb, 30, os.path.join(
bitmaps_dir, 'inc.png'), _('Inc Year'))
self.Bind(wx.EVT_TOOL, self.OnIncYear, qInc)
tb.SetToolSeparation(50)
tb.AddSeparator()
qLeg=SetToolPath(self, tb, 40, os.path.join(
bitmaps_dir, 'legend.png'), _('Legend'))
self.Bind(wx.EVT_TOOL, self.Legend, qLeg)
qExp=SetToolPath(self, tb, 45, os.path.join(
bitmaps_dir, 'export.png'), _('Export to iCal'))
self.Bind(wx.EVT_TOOL, self.Export, qExp)
qSett=SetToolPath(self, tb, 50, os.path.join(
bitmaps_dir, 'set.png'), _('Settings'))
self.Bind(wx.EVT_TOOL, self.Settings, qSett)
qHelp=SetToolPath(self, tb, 55, os.path.join(
bitmaps_dir, 'help.png'), _('Help'))
self.Bind(wx.EVT_TOOL, self.Info, qHelp)
# SetToolPath(self, tb, 57, os.path.join(bitmaps_dir,'help.png'), _('Print'))
# wx.EVT_TOOL(self, 57, self.test)
tb.AddSeparator()
qExit=SetToolPath(self, tb, 60, os.path.join(
bitmaps_dir, 'exit.png'), _('Exit'))
self.Bind(wx.EVT_TOOL, self.TimeToQuit, qExit)
tb.Realize()
def test(self, event):
#rpt = report_year(self.cal.year)
# self.printer.PreviewText(rpt)
# self.printer.PreviewFile('2.html')
dlg = Colour_Dlg(self)
dlg.ShowModal()
dlg.Destroy()
def Legend(self, event):
dlg = Legend_Dlg(self)
dlg.ShowModal()
dlg.Destroy()
def Export(self, event):
dlg = wx.FileDialog(self, _("Export to iCal"),
style=wx.FD_SAVE)
if dlg.ShowModal() == wx.ID_OK:
try:
fileobj = file(dlg.GetPath(), "w")
report_year_ical(self.cal.year, fileobj)
except (IOError, OSError) as err:
wx.MessageDialog(
self, str(err), _("Unable to export"), style=wx.OK).ShowModal()
def Settings(self, event):
dlg = Settings_Dlg(self)
if dlg.ShowModal() == wx.ID_OK:
self.cal.Set_Year(wx.DateTime.Today().GetYear())
dlg.Destroy()
def Info(self, event):
global lang
f_name = os.path.join(doc_dir, "README_"+lang[0]+".html")
if not os.path.isfile(f_name):
f_name = os.path.join(doc_dir, "README.html")
f = open(f_name, "r")
msg = f.read()
dlg = Help_Dlg(self, _('Help'), msg)
dlg.ShowModal()
# increment and decrement toolbar controls
def OnIncYear(self, event):
self.cal.Inc_Year()
def OnDecYear(self, event):
self.cal.Dec_Year()
def OnCurrent(self, event):
self.cal.Set_Year(wx.DateTime.Today().GetYear())
# ----------------------------------------------
def SetToolPath(self, tb, id, bmp, title):
global dir_path
# tb.AddSimpleTool(id, wx.Bitmap(os.path.join(dir_path, bmp), wx.BITMAP_TYPE_PNG),
# title, title)
return tb.AddTool(id, "", wx.Bitmap(os.path.join(dir_path, bmp), wx.BITMAP_TYPE_PNG),
wx.NullBitmap, wx.ITEM_NORMAL, title, title)
class MyApp(wx.App):
def OnInit(self):
wx.lib.colourdb.updateColourDB()
ret = first_login()
if ret == 'bad_login':
return True
elif ret == 'not_first':
dlg = Login_Dlg(None)
if dlg.ShowModal() == wx.ID_CANCEL:
dlg.Destroy()
return True
dlg.Destroy()
self.frame_init()
return True
def frame_init(self):
frame = MyFrame(None, -1, "")
frame.Show(True)
self.SetTopWindow(frame)
if __name__ == '__main__':
locale.setlocale(locale.LC_ALL, "")
dir_path = os.getcwd()
app = MyApp(0)
app.MainLoop()
|