X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3e7c608160fd38549a11508d35b24b663ac36416..58dbf9d0a22bc3a7d6d90a5fb1d53d2c6a479eaa:/wxPython/wx/lib/calendar.py diff --git a/wxPython/wx/lib/calendar.py b/wxPython/wx/lib/calendar.py index 4cb46b1b3f..bc26550a67 100644 --- a/wxPython/wx/lib/calendar.py +++ b/wxPython/wx/lib/calendar.py @@ -64,6 +64,23 @@ # Use the cursor keys to navigate through the ages. :) # The Home key function as go to today # o select day is now a filled rect instead of just an outline +# +# 15/04/2005 - Joe "shmengie" Brown joebrown@podiatryfl.com +# o Adjusted spin control size/placement (On Windows ctrls were overlapping). +# o Set Ok/Cancel buttons to wx.ID_OK & wx.ID_CANCEL to provide default dialog +# behaviour. +# o If no date has been clicked clicked, OnOk set the result to calend's date, +# important if keyboard only navigation is used. +# +# 12/10/2006 - Walter Barnes walter_barnes05@yahoo.com +# o Fixed CalDraw to properly render months that start on a Sunday. +# +# 21/10/2006 - Walter Barnes walter_barnes05@yahoo.com +# o Fixed a bug in Calendar: Shift and Control key status was only recorded for +# left-down events. +# o Added handlers for wxEVT_MIDDLE_DOWN and wxEVT_MIDDLE_DCLICK to generate +# EVT_CALENDAR for these mouse events. + import wx @@ -281,6 +298,9 @@ class CalDraw: else: start_pos = dow + if start_pos > 6: + start_pos = 0 + self.st_pos = start_pos self.cal_days = [] @@ -292,7 +312,7 @@ class CalDraw: self.cal_days.append(str(i)) i = i + 1 - self.end_pos = dow + dim + self.end_pos = start_pos + dim - 1 return start_pos @@ -303,6 +323,9 @@ class CalDraw: self.SetColor(COLOR_WEEKEND_BACKGROUND, MakeColor(backgrd)) date = 6 - int(self.dow) # start day of first saturday + if date == 0: #...unless we start on Sunday + self.cal_sel[1] = (self.GetColor(COLOR_WEEKEND_FONT), self.GetColor(COLOR_WEEKEND_BACKGROUND)) + date = 7 while date <= self.dim: self.cal_sel[date] = (self.GetColor(COLOR_WEEKEND_FONT), self.GetColor(COLOR_WEEKEND_BACKGROUND)) # Saturday @@ -359,7 +382,7 @@ class CalDraw: tw,th = DC.GetTextExtent(month) adjust = self.cx_st + (self.sizew-tw)/2 - DC.DrawText(month, (adjust, self.cy_st + th)) + DC.DrawText(month, adjust, self.cy_st + th) year = str(self.year) tw,th = DC.GetTextExtent(year) @@ -369,7 +392,7 @@ class CalDraw: f = wx.Font(sizef, self.font, wx.NORMAL, self.bold) DC.SetFont(f) - DC.DrawText(year, (self.cx_st + adjust, self.cy_st + th)) + DC.DrawText(year, self.cx_st + adjust, self.cy_st + th) def DrawWeek(self, DC): # draw the week days # increase by 1 to include all gridlines @@ -431,7 +454,7 @@ class CalDraw: else: pen = wx.Pen(MakeColor(self.GetColor(COLOR_BACKGROUND)), 1, wx.SOLID) DC.SetPen(pen) - DC.DrawRectangle( pointXY, pointWH) + DC.DrawRectanglePointSize( pointXY, pointWH) old_pen = DC.GetPen() @@ -440,12 +463,12 @@ class CalDraw: # draw the horizontal hilight startPoint = wx.Point(x + 1 , y + 1) endPoint = wx.Point(x + width - 1, y + 1) - DC.DrawLine(startPoint, endPoint ) + DC.DrawLinePoint(startPoint, endPoint ) # draw the vertical hilight startPoint = wx.Point(x + 1 , y + 1) endPoint = wx.Point(x + 1, y + height - 2) - DC.DrawLine(startPoint, endPoint ) + DC.DrawLinePoint(startPoint, endPoint ) pen = wx.Pen(MakeColor(self.colors[COLOR_3D_DARK]), 1, wx.SOLID) DC.SetPen(pen) @@ -453,19 +476,19 @@ class CalDraw: # draw the horizontal lowlight startPoint = wx.Point(x + 1, y + height - 2) endPoint = wx.Point(x + width - 1, y + height - 2) - DC.DrawLine(startPoint, endPoint ) + DC.DrawLinePoint(startPoint, endPoint ) # draw the vertical lowlight startPoint = wx.Point(x + width - 2 , y + 2) endPoint = wx.Point(x + width - 2, y + height - 2) - DC.DrawLine(startPoint, endPoint ) + DC.DrawLinePoint(startPoint, endPoint ) pen = wx.Pen(MakeColor(self.colors[COLOR_FONT]), 1, wx.SOLID) DC.SetPen(pen) point = (x+diffx, y+diffy) - DC.DrawText(day, point) + DC.DrawTextPoint(day, point) cnt_x = cnt_x + 1 def _CalcFontSize(self, DC, f): @@ -536,7 +559,7 @@ class CalDraw: adj_v = adj_v + self.num_indent_vert - DC.DrawText(text, (x+adj_h, y+adj_v)) + DC.DrawTextPoint(text, (x+adj_h, y+adj_v)) def DrawDayText(self, DC, key): f = wx.Font(10, self.font, wx.NORMAL, self.bold) # initial font setting @@ -589,7 +612,7 @@ class CalDraw: nkey = key + self.st_pos -1 rect = self.rg[nkey] - DC.DrawRectangle((rect.x, rect.y), (rect.width, rect.height)) + DC.DrawRectangleRect(rect) # calculate and draw the grid lines def DrawGrid(self, DC): @@ -611,7 +634,7 @@ class CalDraw: x1 = x1 + self.restW if self.hide_grid is False: - DC.DrawLine((x1, y1), (x1, y2)) + DC.DrawLinePoint((x1, y1), (x1, y2)) self.gridx.append(x1) @@ -626,7 +649,7 @@ class CalDraw: y1 = y1 + self.restH if self.hide_grid is False: - DC.DrawLine((x1, y1), (x2, y1)) + DC.DrawLinePoint((x1, y1), (x2, y1)) self.gridy.append(y1) @@ -690,6 +713,8 @@ class Calendar( wx.PyControl ): self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDEvent) self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightEvent) self.Bind(wx.EVT_RIGHT_DCLICK, self.OnRightDEvent) + self.Bind(wx.EVT_MIDDLE_DOWN, self.OnMiddleEvent) + self.Bind(wx.EVT_MIDDLE_DCLICK, self.OnMiddleDEvent) self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus) self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus) self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown) @@ -727,6 +752,8 @@ class Calendar( wx.PyControl ): def ProcessClick(self, event): self.x, self.y = event.GetX(), event.GetY() + self.shiftkey = event.ShiftDown() + self.ctrlkey = event.ControlDown() key = self.GetDayHit(self.x, self.y) self.SelectDay(key) @@ -734,8 +761,6 @@ class Calendar( wx.PyControl ): def OnLeftEvent(self, event): self.click = 'LEFT' - self.shiftkey = event.ShiftDown() - self.ctrlkey = event.ControlDown() self.ProcessClick(event) def OnLeftDEvent(self, event): @@ -750,6 +775,14 @@ class Calendar( wx.PyControl ): self.click = 'DRIGHT' self.ProcessClick(event) + def OnMiddleEvent(self, event): + self.click = 'MIDDLE' + self.ProcessClick(event) + + def OnMiddleDEvent(self, event): + self.click = 'DMIDDLE' + self.ProcessClick(event) + def OnSetFocus(self, event): self.hasFocus = True self.DrawFocusIndicator(True) @@ -763,7 +796,7 @@ class Calendar( wx.PyControl ): event.Skip() return - key_code = event.KeyCode() + key_code = event.GetKeyCode() if key_code == wx.WXK_TAB: forward = not event.ShiftDown() @@ -846,6 +879,7 @@ class Calendar( wx.PyControl ): def SetDayValue(self, day): self.set_day = day + self.day = day def SetMonth(self, month): if month >= 1 and month <= 12: @@ -1019,7 +1053,7 @@ class Calendar( wx.PyControl ): DC.SetPen(wx.TRANSPARENT_PEN) rect = self.rg[key] - DC.DrawRectangle((rect.x+1, rect.y+1), (rect.width-2, rect.height-2)) + DC.DrawRectangle(rect.x+1, rect.y+1, rect.width-2, rect.height-2) self.caldraw.DrawDayText(DC,key) @@ -1041,7 +1075,7 @@ class Calendar( wx.PyControl ): DC.SetPen(wx.Pen(MakeColor(self.GetColor(COLOR_GRID_LINES)), width)) rect = self.rg[key] - DC.DrawRectangle((rect.x, rect.y), (rect.width, rect.height)) + DC.DrawRectangleRect(rect) DC.EndDrawing() @@ -1072,10 +1106,8 @@ class Calendar( wx.PyControl ): self.DrawRect(self.sel_key, bgcolor,cfont, sel_size) self.DrawRect(key, self.GetColor(COLOR_HIGHLIGHT_BACKGROUND), self.GetColor(COLOR_HIGHLIGHT_FONT), sel_size) - # store last used by self.sel_key = key - self.select_day = None def ClearDsp(self): self.Clear() @@ -1102,7 +1134,8 @@ class Calendar( wx.PyControl ): class CalenDlg(wx.Dialog): def __init__(self, parent, month=None, day = None, year=None): wx.Dialog.__init__(self, parent, -1, "Event Calendar", wx.DefaultPosition, (280, 360)) - + self.result = None + # set the calendar and attributes self.calend = Calendar(self, -1, (20, 60), (240, 200)) @@ -1128,7 +1161,7 @@ class CalenDlg(wx.Dialog): # alternate spin button to control the month h = self.date.GetSize().height - self.m_spin = wx.SpinButton(self, -1, (130, 20), (h*2, h), wx.SP_VERTICAL) + self.m_spin = wx.SpinButton(self, -1, (115, 20), (h*1.5, h), wx.SP_VERTICAL) self.m_spin.SetRange(1, 12) self.m_spin.SetValue(start_month) self.Bind(wx.EVT_SPIN, self.OnMonthSpin, self.m_spin) @@ -1137,7 +1170,7 @@ class CalenDlg(wx.Dialog): self.dtext = wx.TextCtrl(self, -1, str(start_year), (160, 20), (60, -1)) h = self.dtext.GetSize().height - self.y_spin = wx.SpinButton(self, -1, (220, 20), (h*2, h), wx.SP_VERTICAL) + self.y_spin = wx.SpinButton(self, -1, (225, 20), (h*1.5, h), wx.SP_VERTICAL) self.y_spin.SetRange(1980, 2010) self.y_spin.SetValue(start_year) @@ -1148,13 +1181,14 @@ class CalenDlg(wx.Dialog): y_pos = 280 but_size = (60, 25) - btn = wx.Button(self, -1, ' Ok ', (x_pos, y_pos), but_size) + btn = wx.Button(self, wx.ID_OK, ' Ok ', (x_pos, y_pos), but_size) self.Bind(wx.EVT_BUTTON, self.OnOk, btn) - btn = wx.Button(self, -1, ' Close ', (x_pos + 120, y_pos), but_size) + btn = wx.Button(self, wx.ID_CANCEL, ' Close ', (x_pos + 120, y_pos), but_size) self.Bind(wx.EVT_BUTTON, self.OnCancel, btn) - def OnOk(self, event): + def OnOk(self, evt): + self.result = ['None', str(self.calend.day), Month[self.calend.month], str(self.calend.year)] self.EndModal(wx.ID_OK) def OnCancel(self, event):