~ubuntu-branches/ubuntu/oneiric/alarm-clock/oneiric

« back to all changes in this revision

Viewing changes to pyalarm.py

  • Committer: Bazaar Package Importer
  • Author(s): Marco Rodrigues
  • Date: 2008-06-17 16:55:35 UTC
  • mto: (7.1.1 sid) (9.1.1 squeeze) (1.2.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20080617165535-rmq267m5kwifv624
Tags: upstream-0.9.6
Import upstream version 0.9.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
        print _("installed on your system.")
26
26
        exit(1)
27
27
 
 
28
import version
 
29
 
28
30
def Error(Text):
29
31
        msgDialog = gtk.MessageDialog(None, 0, gtk.MESSAGE_ERROR, 
30
32
                                  gtk.BUTTONS_CLOSE, _("Error!"))
67
69
locale.setlocale(locale.LC_ALL, '')
68
70
gettext.textdomain('pyalarm')
69
71
gtk.glade.textdomain('pyalarm')
70
 
gettext.bindtextdomain('pyalarm', "/usr/share/locale")
71
 
gtk.glade.bindtextdomain('pyalarm', "/usr/share/locale")
 
72
gettext.bindtextdomain('pyalarm', "%s/locale" % os.path.split(os.getcwd())[0])
 
73
gtk.glade.bindtextdomain('pyalarm', "%s/locale" % os.path.split(os.getcwd())[0])
 
74
gettext.bindtextdomain('pyalarm', )
72
75
 
73
76
 
74
77
 
110
113
                StartGUI().RunMe(Min)
111
114
                gtk.gdk.threads_init()
112
115
                gtk.gdk.threads_enter()
113
 
                gtk.main()
 
116
                try:
 
117
                        gtk.main()
 
118
                except KeyboardInterrupt:
 
119
                        print "Keyboard interrupt, closing."
 
120
                        exit(254)
114
121
                gtk.gdk.threads_leave()
115
122
 
116
123
        def RunMe(self, Min = False):
143
150
                self.ConnectSignals()
144
151
 
145
152
                self.AT = CheckAlarmThread(MainWindowGlade.get_widget('status_bar'), MainWindowGlade,StatusIcon,self.alarm_model, self.row, self.TreeSelection)
146
 
                self.AT.start()
 
153
                try:
 
154
                        self.AT.start()
 
155
                except:
 
156
                        self.QuitApplication()
147
157
 
148
158
                pynotify.init("Alarm-Clock")
149
159
 
789
799
        def StopTheSound(self,obj):
790
800
                        MainWindowGlade.get_widget('stop_sound').set_sensitive(False)
791
801
                        player.set_state(gst.STATE_NULL)
792
 
 
 
802
                        player.set_property("volume", 0)
793
803
 
794
804
 
795
805
        def StatusClicked(self,obj):
850
860
        def ShowAboutDialog(self,obj):
851
861
                self.AboutDialog = gtk.AboutDialog()
852
862
                self.AboutDialog.set_name (_("Alarm Clock"))
853
 
                self.AboutDialog.set_version('0.9.4')
 
863
                self.AboutDialog.set_version(version.get_version())
854
864
                self.AboutDialog.set_copyright(_("(c) 2008 Tomasz Sałaciński\n"
855
865
                "<tsalacinski@gmail.com>\n"
856
866
                "\n"
902
912
                self.fc = file(os.getenv("HOME") + "/.config/Alarm-Clock/configuration", "w")
903
913
                print >> self.fc, [MainWindow.get_position(), MainWindow.get_size()]
904
914
                self.fc.close()
 
915
                player.set_state(gst.STATE_NULL)
905
916
                gtk.main_quit()
906
917
 
907
918
        def ChangeAlarmPrefs(self,obj):
2073
2084
                self.SchedSignals = { "add_exception" : self.AddExceptionDialog,
2074
2085
                                      "remove_exception" : self.RemoveExceptionDialog,
2075
2086
                                      "load_exc_click" : self.LoadExceptionList,
2076
 
                                      "save_exc_click" : self.SaveExceptionList, }
 
2087
                                      "save_exc_click" : self.SaveExceptionList,
 
2088
                                          "SelectAllWeekdays" : self.SelectAllWeekdays,
 
2089
                                          "DeselectAllWeekdays" : self.DeselectAllWeekdays,
 
2090
                                          "SelectAllMonths" : self.SelectAllMoths,
 
2091
                                          "DeselectAllMonths" : self.DeselectAllMonhts, }
2077
2092
 
2078
2093
                self.ScheduleProps.signal_autoconnect(self.SchedSignals)
2079
2094
 
2089
2104
 
2090
2105
                self.SchedulePropsWidget.destroy()
2091
2106
 
 
2107
 
 
2108
 
 
2109
        def SelectAllWeekdays(self, Button):
 
2110
                for x in range(1,8):
 
2111
                        self.Deselect = self.ScheduleProps.get_widget("w%i" % x)
 
2112
                        self.Deselect.set_active(True)
 
2113
 
 
2114
        def DeselectAllWeekdays(self, Button):
 
2115
                for x in range(1,8):
 
2116
                        self.Deselect = self.ScheduleProps.get_widget("w%i" % x)
 
2117
                        self.Deselect.set_active(False)
 
2118
 
 
2119
        def SelectAllMoths(self, Button):
 
2120
                for x in range(1,13):
 
2121
                        self.Deselect = self.ScheduleProps.get_widget("m%i" % x)
 
2122
                        self.Deselect.set_active(True)
 
2123
 
 
2124
        def DeselectAllMonhts(self, Button):
 
2125
                for x in range(1,13):
 
2126
                        self.Deselect = self.ScheduleProps.get_widget("m%i" % x)
 
2127
                        self.Deselect.set_active(False)
 
2128
 
2092
2129
        def AlarmPrefs(self):
2093
2130
                self.AlarmProps = gtk.glade.XML('main.glade', 'alarm_props_dialog')
2094
2131
                self.AlarmPropsWidget = self.AlarmProps.get_widget('alarm_props_dialog')
2917
2954
                self.bus.add_signal_watch()
2918
2955
                self.bus.connect('message', self.on_message2)
2919
2956
                self.time_format = gst.Format(gst.FORMAT_TIME)
 
2957
                self.count = 0
2920
2958
 
2921
2959
                if initvol > outvol:
2922
2960
                        self.voldir = 0
2926
2964
                        self.spac = outvol - initvol
2927
2965
 
2928
2966
 
2929
 
                self.change = self.spac / self.sec / 100
 
2967
                self.change = self.spac / self.sec / 1000
2930
2968
 
2931
2969
                
2932
2970
 
2933
2971
 
2934
2972
        def run(self):
2935
 
                self.volume_current = self.ivol / 100
 
2973
                self.volume_current = self.ivol / 1000
2936
2974
                player.set_property("volume", self.volume_current)
2937
2975
                player.set_state(gst.STATE_PLAYING)
2938
 
                self.count = 0
 
2976
 
2939
2977
                
2940
 
                while True:
 
2978
                while player.get_state()[1] != gst.STATE_NULL:
 
2979
                        isNull = player.get_state()[1]
 
2980
                        if isNull == gst.STATE_NULL:
 
2981
                                gtk.gdk.threads_enter()
 
2982
                                player.set_property("volume", 0)
 
2983
                                self.volume_current = 0
 
2984
                                self.count = 0
 
2985
                                self.b.set_sensitive(False)
 
2986
                                gtk.gdk.threads_leave()
 
2987
                                return
 
2988
 
 
2989
 
2941
2990
                        if self.voldir == 0:
2942
2991
                                self.volume_current = self.volume_current - self.change
2943
2992
                        if self.voldir == 1:
2944
2993
                                self.volume_current = self.volume_current + self.change
2945
 
                        isNull = player.get_state()[1]
2946
 
                        if isNull == gst.STATE_NULL:
2947
 
                                gtk.gdk.threads_enter()
2948
 
                                self.b.set_sensitive(False)
2949
 
                                gtk.gdk.threads_leave()
2950
 
                                break
2951
2994
 
2952
2995
                        player.set_property("volume", self.volume_current)
2953
2996
                        self.count = self.count + 1
2954
 
                        time.sleep(1)
2955
2997
 
 
2998
                        time.sleep(0.1)
2956
2999
 
2957
3000
        def on_message2(self, bus, message):
2958
3001
                t = message.type
2988
3031
                self.CheckOldAlarms()
2989
3032
 
2990
3033
                while True:
2991
 
                        self.a = self.a + 1
2992
 
                        if self.a == 5:
2993
 
                                self.CheckTodayBirthdays()
2994
 
                                self.CheckTodayAlarms()
2995
 
                                self.a = 0
2996
 
 
2997
 
                        time.sleep(0.1)
2998
 
                        self.CheckOldAlarms()
2999
 
 
3000
 
                        self.b = self.b + 1
3001
 
                        if self.b == 300:
3002
 
                                self.CheckEmail()
3003
 
                                self.b = 0
3004
 
 
3005
 
                        time.sleep(0.1)
3006
 
                        self.CheckOldAlarms()
3007
 
 
3008
 
 
3009
 
                        self.File = file(os.getenv("HOME") + "/.config/Alarm-Clock/lock", "w")
3010
 
                        self.File.write("%s/%s/%s %s:%s:%s" % (datetime.datetime.now().year, datetime.datetime.now().month, datetime.datetime.now().day, datetime.datetime.now().hour, datetime.datetime.now().minute, datetime.datetime.now().second))
3011
 
                        self.File.close()
3012
 
 
3013
 
                        time.sleep(0.1)
3014
 
                        self.CheckOldAlarms()
3015
 
 
3016
 
                        gtk.gdk.threads_enter()
3017
 
                        self.status.push(0, time.strftime(_("Current time: %c")))
3018
 
                        gtk.gdk.threads_leave() 
3019
 
                        for tup in self.today:
3020
 
                                if tup[0] == time.localtime().tm_hour and tup[1] == time.localtime().tm_min and time.localtime().tm_sec == 0:
3021
 
                                        self.s = file(os.getenv("HOME") + "/.config/Alarm-Clock/alarms")
3022
 
                                        self.bb = self.s.readlines()
 
3034
                        try:
 
3035
                                self.a = self.a + 1
 
3036
                                if self.a == 5:
 
3037
                                        self.CheckTodayBirthdays()
 
3038
                                        self.CheckTodayAlarms()
 
3039
                                        self.a = 0
 
3040
 
 
3041
                                time.sleep(0.1)
 
3042
                                self.CheckOldAlarms()
 
3043
 
 
3044
                                self.b = self.b + 1
 
3045
                                if self.b == 300:
 
3046
                                        self.CheckEmail()
 
3047
                                        self.b = 0
 
3048
 
 
3049
                                time.sleep(0.1)
 
3050
                                self.CheckOldAlarms()
 
3051
 
 
3052
 
 
3053
                                self.File = file(os.getenv("HOME") + "/.config/Alarm-Clock/lock", "w")
 
3054
                                self.File.write("%s/%s/%s %s:%s:%s" % (datetime.datetime.now().year, datetime.datetime.now().month, datetime.datetime.now().day, datetime.datetime.now().hour, datetime.datetime.now().minute, datetime.datetime.now().second))
 
3055
                                self.File.close()
 
3056
 
 
3057
                                time.sleep(0.1)
 
3058
                                self.CheckOldAlarms()
 
3059
 
 
3060
                                gtk.gdk.threads_enter()
 
3061
                                self.status.push(0, time.strftime(_("Current time: %c")))
 
3062
                                gtk.gdk.threads_leave() 
 
3063
                                for tup in self.today:
 
3064
                                        if tup[0] == time.localtime().tm_hour and tup[1] == time.localtime().tm_min and time.localtime().tm_sec == 0:
 
3065
                                                self.s = file(os.getenv("HOME") + "/.config/Alarm-Clock/alarms")
 
3066
                                                self.bb = self.s.readlines()
 
3067
                                                gtk.gdk.threads_enter()
 
3068
                                                StartGUI().RunAlarm(eval(self.bb[tup[2]]))
 
3069
                                                time.sleep(1)
 
3070
                                                gtk.gdk.threads_leave()
 
3071
                                                continue
 
3072
 
 
3073
                                if time.localtime().tm_hour == 0 and time.localtime().tm_min == 0 and time.localtime().tm_sec < 1 and self.RefreshList == False:
 
3074
                                        self.RefreshList = True
 
3075
 
 
3076
                                if time.localtime().tm_hour == 0 and time.localtime().tm_min == 0 and time.localtime().tm_sec > 1 and self.RefreshList == True:
 
3077
                                        self.RefreshList = False
 
3078
                        
 
3079
                                self.CheckOldAlarms()
 
3080
 
 
3081
                                if self.RefreshList == True:
3023
3082
                                        gtk.gdk.threads_enter()
3024
 
                                        StartGUI().RunAlarm(eval(self.bb[tup[2]]))
 
3083
                                        self.LoadConfigFiles()
3025
3084
                                        gtk.gdk.threads_leave()
3026
 
 
3027
 
                        if time.localtime().tm_hour == 0 and time.localtime().tm_min == 0 and time.localtime().tm_sec < 1 and self.RefreshList == False:
3028
 
                                self.RefreshList = True
3029
 
 
3030
 
                        if time.localtime().tm_hour == 0 and time.localtime().tm_min == 0 and time.localtime().tm_sec > 1 and self.RefreshList == True:
3031
 
                                self.RefreshList = False
3032
 
                        
3033
 
                        self.CheckOldAlarms()
3034
 
 
3035
 
                        if self.RefreshList == True:
3036
 
                                gtk.gdk.threads_enter()
3037
 
                                self.LoadConfigFiles()
3038
 
                                gtk.gdk.threads_leave()
3039
 
 
3040
 
 
3041
 
                        time.sleep(0.1)
3042
 
 
3043
 
 
3044
 
                        self.CheckOldAlarms()
 
3085
                                        self.RefreshList = False
 
3086
 
 
3087
                                time.sleep(0.1)
 
3088
 
 
3089
 
 
3090
                                self.CheckOldAlarms()
 
3091
 
 
3092
                        except:
 
3093
                                pass
3045
3094
 
3046
3095
        def CheckEmail(self):
3047
3096
                try:
3049
3098
                except:
3050
3099
                        return
3051
3100
 
3052
 
 
3053
3101
        def CheckOldAlarms(self):
3054
 
                gtk.gdk.threads_enter()
3055
 
 
3056
 
                self.AlFile = file(os.getenv("HOME") + "/.config/Alarm-Clock/alarms", "r")
3057
 
 
3058
 
                self.x = self.x + 1
3059
 
                if self.x == 4:
3060
 
                        if self.Removed == True:
3061
 
                                self.RefreshList = True
3062
 
                                self.Removed = False
3063
 
                        self.x = 0
3064
 
 
3065
 
                self.Data = self.AlFile.readlines()
3066
 
                self.AlFile.close()
3067
 
                self.Cnt = 0
3068
 
 
3069
 
                for line in self.Data:
3070
 
                        self.OldLine = eval(line)
3071
 
 
3072
 
                        if self.OldLine[2] == 1:
3073
 
                                self.Cnt = self.Cnt + 1
3074
 
                                continue
3075
 
 
3076
 
 
3077
 
 
3078
 
                        self.Date = self.OldLine[3]
3079
 
                        self.Time = self.OldLine[1]
3080
 
 
3081
 
                        self.date_data = re.search('(\d+)/(\d+)/(\d+)', self.Date)
3082
 
                        self.oy = int(self.date_data.group(1))
3083
 
                        self.om = int(self.date_data.group(2)) + 1
3084
 
                        self.od = int(self.date_data.group(3))
3085
 
                        self.time_data = re.search('(\d+):(\d+)', self.Time)
3086
 
                        self.oh = int(self.time_data.group(1))
3087
 
                        self.omin = int(self.time_data.group(2))
3088
 
 
3089
 
                        self.DateOld = datetime.datetime(self.oy,self.om,self.od,self.oh,self.omin,0)
3090
 
 
3091
 
                        self.CurrentDate = datetime.datetime.today()
3092
 
 
3093
 
                        self.Diff = self.CurrentDate - self.DateOld
3094
 
 
3095
 
                        if self.Diff.days > 0:
3096
 
                                self.RemoveOldAlarm(self.Cnt)
3097
 
                                self.Cnt = self.Cnt + 1
3098
 
                                self.Removed = True
3099
 
                                continue
3100
 
 
3101
 
                        if self.Diff.days == 0:
3102
 
                                if self.Diff.seconds > 0:
 
3102
                try:
 
3103
                        gtk.gdk.threads_enter()
 
3104
        
 
3105
                        self.AlFile = file(os.getenv("HOME") + "/.config/Alarm-Clock/alarms", "r")
 
3106
        
 
3107
                        self.x = self.x + 1
 
3108
                        if self.x == 4:
 
3109
                                if self.Removed == True:
 
3110
                                        self.RefreshList = True
 
3111
                                        self.Removed = False
 
3112
                                self.x = 0
 
3113
 
 
3114
                        self.Data = self.AlFile.readlines()
 
3115
                        self.AlFile.close()
 
3116
                        self.Cnt = 0
 
3117
 
 
3118
                        for line in self.Data:
 
3119
                                self.OldLine = eval(line)
 
3120
        
 
3121
                                if self.OldLine[2] == 1:
 
3122
                                        self.Cnt = self.Cnt + 1
 
3123
                                        continue
 
3124
 
 
3125
 
 
3126
 
 
3127
                                self.Date = self.OldLine[3]
 
3128
                                self.Time = self.OldLine[1]
 
3129
 
 
3130
                                self.date_data = re.search('(\d+)/(\d+)/(\d+)', self.Date)
 
3131
                                self.oy = int(self.date_data.group(1))
 
3132
                                self.om = int(self.date_data.group(2)) + 1
 
3133
                                self.od = int(self.date_data.group(3))
 
3134
                                self.time_data = re.search('(\d+):(\d+)', self.Time)
 
3135
                                self.oh = int(self.time_data.group(1))
 
3136
                                self.omin = int(self.time_data.group(2))
 
3137
 
 
3138
                                self.DateOld = datetime.datetime(self.oy,self.om,self.od,self.oh,self.omin,0)
 
3139
 
 
3140
                                self.CurrentDate = datetime.datetime.today()
 
3141
 
 
3142
                                self.Diff = self.CurrentDate - self.DateOld
 
3143
 
 
3144
                                if self.Diff.days > 0:
3103
3145
                                        self.RemoveOldAlarm(self.Cnt)
3104
3146
                                        self.Cnt = self.Cnt + 1
3105
3147
                                        self.Removed = True
3106
3148
                                        continue
 
3149
 
 
3150
                                if self.Diff.days == 0:
 
3151
                                        if self.Diff.seconds > 0:
 
3152
                                                self.RemoveOldAlarm(self.Cnt)
 
3153
                                                self.Cnt = self.Cnt + 1
 
3154
                                                self.Removed = True
 
3155
                                                continue
3107
3156
                        
3108
3157
 
3109
 
                        self.Cnt = self.Cnt + 1                 
3110
 
                gtk.gdk.threads_leave()
 
3158
                                self.Cnt = self.Cnt + 1                 
 
3159
                        gtk.gdk.threads_leave()
 
3160
                except:
 
3161
                        pass
3111
3162
 
3112
3163
        def RemoveOldAlarm(self,no):
3113
3164
                self.row = no