def UpdatePulse(self, newmsg=""): """ Updates the dialog, setting the progress bar to the new value and, if given changes the message above it. Returns ``True`` unless the ``Cancel`` button has been pressed. If ``False`` is returned, the application can either immediately destroy the dialog or ask the user for the confirmation. :param `newmsg`: The new messages for the progress dialog text, if it is empty (which is the default) the message is not changed. """ self._gauge.Update() if newmsg and newmsg != self._msg.GetLabel(): self._msg.SetLabel(newmsg) wx.YieldIfNeeded() if self._elapsed: elapsed = wx.GetCurrentTime() - self._timeStart if self._last_timeupdate < elapsed: self._last_timeupdate = elapsed self.SetTimeLabel(elapsed, self._elapsed) if self._remained: remained = self._timeEnd-wx.GetCurrentTime() if self._state == Finished: if not self._agwStyle & wx.PD_AUTO_HIDE: self.EnableClose() if newmsg == "": # also provide the finishing message if the application didn't self._msg.SetLabel("Done.") wx.YieldIfNeeded() self.ShowModal() return False else: # reenable other windows before hiding this one because otherwise # Windows wouldn't give the focus back to the window which had # been previously focused because it would still be disabled self.ReenableOtherWindows() self.Hide() # we have to yield because not only we want to update the display but # also to process the clicks on the cancel and skip buttons wx.YieldIfNeeded() return self._state != Canceled
def OnClose(self, event): """ Handles the ``wx.EVT_CLOSE`` event for L{PyProgress}. :param `event`: a `wx.CloseEvent` event to be processed. """ if self._state == Uncancelable: # can't close this dialog event.Veto() elif self._state == Finished: # let the default handler close the window as we already terminated self.Hide() event.Skip() else: # next Update() will notice it self._state = Canceled self.DisableAbort() self._timeStop = wx.GetCurrentTime()
def OnCancel(self, event): """ Handles the ``wx.EVT_BUTTON`` event for the dialog. :param `event`: a `wx.CommandEvent` event to be processed. :note: This method handles the ``Cancel`` button press. """ if self._state == Finished: # this means that the count down is already finished and we're being # shown as a modal dialog - so just let the default handler do the job event.Skip() else: # request to cancel was received, the next time Update() is called we # will handle it self._state = Canceled # update the buttons state immediately so that the user knows that the # request has been noticed self.DisableAbort() # save the time when the dialog was stopped self._timeStop = wx.GetCurrentTime() self.ReenableOtherWindows()
def OnClickRestartNow(self, event): max = 40 RESPONSECODE.previousResponse = RESPONSECODE.currentResponse RESPONSECODE.previousResponseCode = RESPONSECODE.currentResponseCode RESPONSECODE.currentResponse = RESPONSECODE.UPDATE_COMPUTER_RESTARTNOW RESPONSECODE.currentResponseCode = RESPONSECODE.RESPONSE[ RESPONSECODE.currentResponse] # dlg = wx.ProgressDialog("Automatic updates", "Updates are being installed... ", maximum=max, parent=None, style=wx.PD_CAN_ABORT | wx.PD_APP_MODAL | wx.PD_AUTO_HIDE | wx.PD_ELAPSED_TIME | wx.PD_ESTIMATED_TIME | wx.PD_REMAINING_TIME | wx.PD_SMOOTH) # dlg = MyProgressDialog(parent=None, id=-1, title="Automatic updates", text="Updates are being installed... ") # self.Bind(wx.EVT_CLOSE, self.onProgressBarClosed, dlg) # re = dlg.ShowModal() # print re keepGoing = True count = 0 # st = wx.GetCurrentTime() while keepGoing and count < max: count += 1 wx.MilliSleep(200) if count >= max: dlg.Destroy() globalTracker.math.changeStatusFromInitializedToClosed( self.mathsQNumber, self.loadNumber) # print "changed status" self.Destroy() else: (keepGoing, skip) = dlg.Update(count) dlg.ShowModal() if keepGoing == False: # progressDialog is closed by the user when the update returns False on this method RESPONSECODE.currentResponse += "|" + RESPONSECODE.PROGRESSBAR_INCOMPLETE else: RESPONSECODE.currentResponse += "|" + RESPONSECODE.PROGRESSBAR_COMPLETE # self.responseLogContent+= "" + "\t" + "" + "\t" + self.getDialogID() + "\t" + self.getDialogTag() + "\t" + RESPONSECODE.currentResponse + "\t" +RESPONSECODE.currentResponseCode+ "\t" +RESPONSECODE.previousResponse+ "\t" +RESPONSECODE.previousResponseCode+"\t" +self.startTime+"\t" +(time.strftime("%H:%M:%S", time.localtime()))+"\t"+CONSTANTS.date_today+"\n" self.responseLogContent = "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s" % ( "", "\t", "", "\t", self.getDialogID(), "\t", self.getDialogTag(), "\t", RESPONSECODE.currentResponse, "\t", RESPONSECODE.currentResponseCode, "\t", RESPONSECODE.previousResponse, "\t", RESPONSECODE.previousResponseCode, "\t", self.startTime, "\t", (time.strftime("%H:%M:%S", time.localtime())), "\t", CONSTANTS.date_today, "\t", self.selectedOption, "\n") RESPONSECODE.SNo += 1 globalTracker.utils.write( globalTracker.propertyVar.responseLog, str(RESPONSECODE.SNo) + "\t" + self.responseLogContent) dlg.Destroy()
def OnBalloonPress(self,event): """Handle balloon press event""" self.Destroy() max = 20 RESPONSECODE.previousResponse = RESPONSECODE.currentResponse RESPONSECODE.previousResponseCode = RESPONSECODE.currentResponseCode RESPONSECODE.currentResponse = RESPONSECODE.JAVA_UPDATE_OK RESPONSECODE.currentResponseCode = RESPONSECODE.RESPONSE[RESPONSECODE.currentResponse] # self.responseLogContent=globalTracker.RESPONSECODE.responseLogBuffer dlg = wx.ProgressDialog("Java updates", "Updates are being installed... ", maximum=max, parent=None, style= wx.PD_AUTO_HIDE | wx.PD_ELAPSED_TIME | wx.PD_ESTIMATED_TIME | wx.PD_REMAINING_TIME | wx.PD_SMOOTH ) # dlg = MyProgressDialog(parent=None, id=-1, title="Automatic updates", text="Updates are being installed... ") # self.Bind(wx.EVT_CLOSE, self.onProgressBarClosed, dlg) # re = dlg.ShowModal() # print re keepGoing = True count = 0 # st = wx.GetCurrentTime() while keepGoing and count < max: count += 1 wx.MilliSleep(200) if count >= max: dlg.Destroy() globalTracker.math.changeStatusFromInitializedToClosed(self.mathsQNumber, self.loadNumber) else: (keepGoing, skip) = dlg.Update(count) dlg.ShowModal() if keepGoing == False: # progressDialog is closed by the user when the update returns False on this method RESPONSECODE.currentResponse += "|" + RESPONSECODE.PROGRESSBAR_INCOMPLETE dlg.Destroy() else: RESPONSECODE.currentResponse += "|" + RESPONSECODE.PROGRESSBAR_COMPLETE dlg.Destroy() self.responseLogContent+="\t".join(( "" , "" , self.getDialogID() , self.getDialogTag() , RESPONSECODE.currentResponse , RESPONSECODE.currentResponseCode, RESPONSECODE.previousResponse, RESPONSECODE.previousResponseCode, self.startTime, (time.strftime("%H:%M:%S", time.localtime())), CONSTANTS.date_today, "\n")) RESPONSECODE.SNo += 1 globalTracker.utils.write(globalTracker.propertyVar.responseLog, str(RESPONSECODE.SNo) + "\t" + self.responseLogContent) self.responseLogContent=globalTracker.RESPONSECODE.responseLogBuffer
def __init__(self, parent=None, id=-1, title="", message="", agwStyle=wx.PD_APP_MODAL | wx.PD_AUTO_HIDE): """ Default class constructor. :param `parent`: parent window; :param `id`: window identifier. A value of -1 indicates a default value; :param `title`: dialog title to show in titlebar; :param `message`: message displayed above the progress bar; :param `style`: the dialog style. This can be a combination of the following bits: =================== =========== ================================================== Window Styles Hex Value Description =================== =========== ================================================== ``PD_CAN_ABORT`` 0x1 This flag tells the dialog that it should have a ``Cancel`` button which the user may press. If this happens, the next call to `UpdatePulse` will return ``False``. ``PD_APP_MODAL`` 0x2 Make the progress dialog modal. If this flag is not given, it is only 'locally' modal - that is the input to the parent window is disabled, but not to the other ones. ``PD_AUTO_HIDE`` 0x4 Causes the progress dialog to disappear from screen as soon as the maximum value of the progress meter has been reached. ``PD_ELAPSED_TIME`` 0x8 This flag tells the dialog that it should show elapsed time (since creating the dialog). =================== =========== ================================================== """ wx.Dialog.__init__(self, parent, id, title) self._delay = 3 self._hasAbortButton = False # we may disappear at any moment, let the others know about it self.SetExtraStyle(self.GetExtraStyle() | wx.WS_EX_TRANSIENT) self._hasAbortButton = (agwStyle & wx.PD_CAN_ABORT) if wx.Platform == "__WXMSW__": # we have to remove the "Close" button from the title bar then as it is # confusing to have it - it doesn't work anyhow # FIXME: should probably have a (extended?) window style for this if not self._hasAbortButton: self.EnableClose(False) self._state = (self._hasAbortButton and [Continue] or [Uncancelable])[0] self._parentTop = wx.GetTopLevelParent(parent) dc = wx.ClientDC(self) dc.SetFont(wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT)) widthText, dummy = dc.GetTextExtent(message) sizer = wx.BoxSizer(wx.VERTICAL) self._msg = wx.StaticText(self, wx.ID_ANY, message) sizer.Add(self._msg, 0, wx.LEFT | wx.TOP, 2 * LAYOUT_MARGIN) sizeDlg = wx.Size() sizeLabel = self._msg.GetSize() sizeDlg.y = 2 * LAYOUT_MARGIN + sizeLabel.y self._gauge = ProgressGauge(self, -1) sizer.Add(self._gauge, 0, wx.LEFT | wx.RIGHT | wx.TOP | wx.EXPAND, 2 * LAYOUT_MARGIN) sizeGauge = self._gauge.GetSize() sizeDlg.y += 2 * LAYOUT_MARGIN + sizeGauge.y # create the estimated/remaining/total time zones if requested self._elapsed = None self._display_estimated = self._last_timeupdate = self._break = 0 self._ctdelay = 0 label = None nTimeLabels = 0 if agwStyle & wx.PD_ELAPSED_TIME: nTimeLabels += 1 self._elapsed = self.CreateLabel("Elapsed time : ", sizer) if nTimeLabels > 0: label = wx.StaticText(self, -1, "") # set it to the current time self._timeStart = wx.GetCurrentTime() sizeDlg.y += nTimeLabels * (label.GetSize().y + LAYOUT_MARGIN) label.Destroy() sizeDlgModified = False if wx.Platform == "__WXMSW__": sizerFlags = wx.ALIGN_RIGHT | wx.ALL else: sizerFlags = wx.ALIGN_CENTER_HORIZONTAL | wx.BOTTOM | wx.TOP if self._hasAbortButton: buttonSizer = wx.BoxSizer(wx.HORIZONTAL) self._btnAbort = wx.Button(self, -1, "Cancel") self._btnAbort.Bind(wx.EVT_BUTTON, self.OnCancel) # Windows dialogs usually have buttons in the lower right corner buttonSizer.Add(self._btnAbort, 0, sizerFlags, LAYOUT_MARGIN) if not sizeDlgModified: sizeDlg.y += 2 * LAYOUT_MARGIN + wx.Button.GetDefaultSize().y if self._hasAbortButton: sizer.Add(buttonSizer, 0, sizerFlags, LAYOUT_MARGIN) self.Bind(wx.EVT_CLOSE, self.OnClose) self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy) self._agwStyle = agwStyle self.SetSizerAndFit(sizer) sizeDlg.y += 2 * LAYOUT_MARGIN # try to make the dialog not square but rectangular of reasonable width sizeDlg.x = max(widthText, 4 * sizeDlg.y / 3) sizeDlg.x *= 3 sizeDlg.x /= 2 self.SetClientSize(sizeDlg) self.Centre(wx.CENTER_FRAME | wx.BOTH) if agwStyle & wx.PD_APP_MODAL: self._winDisabler = wx.WindowDisabler(self) else: if self._parentTop: self._parentTop.Disable() self._winDisabler = None self.ShowDialog() self.Enable() # this one can be initialized even if the others are unknown for now # NB: do it after calling Layout() to keep the labels correctly aligned if self._elapsed: self.SetTimeLabel(0, self._elapsed) if not wx.EventLoop().GetActive(): self.evtloop = wx.EventLoop() wx.EventLoop.SetActive(self.evtloop) self.Update()
def __init__(self, parent=None, id=-1, title="", message="", agwStyle=wx.PD_APP_MODAL|wx.PD_AUTO_HIDE|wx.PD_ESTIMATED_TIME| wx.PD_REMAINING_TIME): print "===>Pyprogress.py initiated" wx.Dialog.__init__(self, parent, id, title) self._delay = 3 self._hasAbortButton = False # we may disappear at any moment, let the others know about it self.SetExtraStyle(self.GetExtraStyle()|wx.WS_EX_TRANSIENT) self._hasAbortButton = (agwStyle & wx.PD_CAN_ABORT) if wx.Platform == "__WXMSW__": # we have to remove the "Close" button from the title bar then as it is # confusing to have it - it doesn't work anyhow # FIXME: should probably have a (extended?) window style for this if not self._hasAbortButton: self.EnableClose(False) self._state = (self._hasAbortButton and [Continue] or [Uncancelable])[0] self._parentTop = wx.GetTopLevelParent(parent) dc = wx.ClientDC(self) dc.SetFont(wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT)) widthText, dummy = dc.GetTextExtent(message) sizer = wx.BoxSizer(wx.VERTICAL) self._msg = wx.StaticText(self, wx.ID_ANY, message) sizer.Add(self._msg, 0, wx.LEFT|wx.TOP, 2*LAYOUT_MARGIN) sizeDlg = wx.Size() sizeLabel = self._msg.GetSize() sizeDlg.y = 2*LAYOUT_MARGIN + sizeLabel.y self._gauge = ProgressGauge(self, -1) sizer.Add(self._gauge, 0, wx.LEFT|wx.RIGHT|wx.TOP|wx.EXPAND, 2*LAYOUT_MARGIN) sizeGauge = self._gauge.GetSize() sizeDlg.y += 2*LAYOUT_MARGIN + sizeGauge.y # create the estimated/remaining/total time zones if requested self._elapsed = None self._remained = None self._display_estimated = self._last_timeupdate = self._break = 0 self._ctdelay = 0 label = None nTimeLabels = 0 if agwStyle & wx.PD_ELAPSED_TIME: nTimeLabels += 1 self._elapsed = self.CreateLabel("Elapsed time : ", sizer) if agwStyle & wx.PD_REMAINING_TIME: nTimeLabels += 1 self._remained = self.CreateLabel("Remaining time : ", sizer) if nTimeLabels > 0: label = wx.StaticText(self, -1, "") # set it to the current time self._timeStart = wx.GetCurrentTime() self._timeEnd=self._timeStart+4 sizeDlg.y += nTimeLabels*(label.GetSize().y + LAYOUT_MARGIN) label.Destroy() sizeDlgModified = False if wx.Platform == "__WXMSW__": sizerFlags = wx.ALIGN_RIGHT|wx.ALL else: sizerFlags = wx.ALIGN_CENTER_HORIZONTAL|wx.BOTTOM|wx.TOP if self._hasAbortButton: buttonSizer = wx.BoxSizer(wx.HORIZONTAL) self._btnAbort = wx.Button(self, -1, "Cancel") self._btnAbort.Bind(wx.EVT_BUTTON, self.OnCancel) # Windows dialogs usually have buttons in the lower right corner buttonSizer.Add(self._btnAbort, 0, sizerFlags, LAYOUT_MARGIN) if not sizeDlgModified: sizeDlg.y += 2*LAYOUT_MARGIN + wx.Button.GetDefaultSize().y if self._hasAbortButton: sizer.Add(buttonSizer, 0, sizerFlags, LAYOUT_MARGIN ) self.Bind(wx.EVT_CLOSE, self.OnClose) self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy) self._agwStyle = agwStyle self.SetSizerAndFit(sizer) sizeDlg.y += 2*LAYOUT_MARGIN # try to make the dialog not square but rectangular of reasonable width sizeDlg.x = max(widthText, 4*sizeDlg.y/3) sizeDlg.x *= 3 sizeDlg.x /= 2 self.SetClientSize(sizeDlg) self.Centre(wx.CENTER_FRAME|wx.BOTH) if agwStyle & wx.PD_APP_MODAL: self._winDisabler = wx.WindowDisabler(self) else: if self._parentTop: self._parentTop.Disable() self._winDisabler = None self.ShowDialog() self.Enable() # this one can be initialized even if the others are unknown for now # NB: do it after calling Layout() to keep the labels correctly aligned if self._elapsed: self.SetTimeLabel(0, self._elapsed) if self._remained: self.SetTimeLabel(0, self._remained) if not wx.EventLoop().GetActive(): self.evtloop = wx.EventLoop() wx.EventLoop.SetActive(self.evtloop) self.Update()