"""Subclass of Progress, which is generated by wxFormBuilder."""

import wx
import wxx
from activity.git.ui import ui as ui
import app.resources as rc
from git import RemoteProgress

class commm(RemoteProgress):

    def __init__(self, dialog):
        self.dialog = dialog
        super(commm, self).__init__()

    def update(self, op_code, cur_count, max_count=None, message=''):
        self.dialog.update(self, op_code, cur_count, max_count, message)


# Implementing Progress
class ProgressDialog(ui.Progress):
    """
    This dialogs shows the progress of the
    current git operation.

    """
    @wxx.SetInfo(__doc__)
    def __init__(self, parent):
        """Initialize the dialog"""
        super(ProgressDialog, self).__init__(parent)
        self.m_sdbSizer12OK.Enable(False)

    def link(self):
        """create a logger"""
        self._link = commm(self)
        return self._link

    def update(self, op_code, cur_count, max_count=None, message=''):
        """Update info from operation"""
        s = '{op_code}:[{cur_count} ({percent})] {message}\r'.format(
            op_code=op_code,
            cur_count=cur_count,
            percent=cur_count / (max_count or 100.0),
            message=message or "NO MESSAGE")
        self.m_text.AppendText(s)
        wx.YieldIfNeeded()

    def Finished(self):
        """Enables closing the dialog"""
        self.m_sdbSizer12OK.Enable(True)
        del self._link

    def OnOK(self, event):
        """Closes the dialog"""
        self.Destroy()

