Commits

Anonymous committed a95083c

retire unused pythonwin-based dialogs

Comments (0)

Files changed (10)

hgwin/__init__.py

-# placeholder

hgwin/commitdialog.py

-"""
-commitdialog.py - a simple commit dialog for TortoiseHg
-
- Copyright (C) 2007 TK Soh <teekaysoh@gmail.com>
-
-This software may be used and distributed according to the terms
-of the GNU General Public License, incorporated herein by reference.
-"""
-
-import os, tempfile, re
-import win32ui
-import win32con
-from pywin.framework.dlgappcore import AppDialog
-from mercurial import hg, repo, ui, cmdutil, util
-import gpopen
-import thgutil
-
-def get_changes_text(filenames):
-    root = thgutil.find_root(filenames[0])
-    u = ui.ui()
-    try:
-        repo = hg.repository(u, path=root)
-    except repo.RepoError:
-        return None
-    
-    # get file status
-    try:
-        files, matchfn, anypats = cmdutil.matchpats(repo, filenames)
-        modified, added, removed, deleted, unknown, ignored, clean = [
-                n for n in repo.status(files=files, list_clean=False)]
-    except util.Abort, inst:
-        return None
-
-    if not (modified + added + removed):
-        return None
-    
-    edittext = []
-    edittext.append("")
-    edittext.append("HG: user: %s" % u.username())
-    edittext.extend(["HG: changed %s" % f for f in modified])
-    edittext.extend(["HG: removed %s" % f for f in removed])
-    edittext.extend(["HG: Added %s" % f for f in added])
-    edittext.append("")
-
-    return "\n".join(edittext)
-
-class SimpleCommitDialog(AppDialog):
-    def __init__(self, cwd, files=[]):
-        self.title = "hg commit - %s" % cwd
-        self.commitfiles = files
-        AppDialog.__init__(self, win32ui.IDD_LARGE_EDIT)
-
-    def OnInitDialog(self):
-        self.SetWindowText(self.title)
-
-        cancel=self.GetDlgItem(win32con.IDCANCEL)
-        cancel.ShowWindow(win32con.SW_SHOW)
-        
-        okBtn = self.GetDlgItem(win32con.IDOK)
-        okBtn.SetWindowText("Commit")
-
-        self.font = win32ui.CreateFont({'name': "Courier New", 'height': 14})
-        edit = self.GetDlgItem(win32ui.IDC_EDIT1)
-        edit.SetFont(self.font)
-
-        # get the list of changes to present at the editor
-        text = get_changes_text(self.commitfiles)
-        if text:
-            text = text.replace("\n", "\r\n")
-            edit.SetWindowText(text)
-        else:
-            edit.SetWindowText("<<No changes to commit>>")
-            edit.EnableWindow(False)
-            okBtn.EnableWindow(False)
-
-    def OnOK(self):
-        if self._do_commit() == True:
-            AppDialog.OnOK(self)
-        
-    def _do_commit(self):
-        # strip log message of lines with HG: prefix
-        text = self.GetDlgItem(win32ui.IDC_EDIT1).GetWindowText()
-        text = re.sub("(?m)^HG:.*\r\n", "", text)
-        lines = [line.rstrip() for line in text.rstrip().splitlines()]
-        while lines and not lines[0]:
-            del lines[0]
-        if not lines:
-            win32ui.MessageBox("Commit message is empty!", "Mercurial",
-                               win32con.MB_OK | win32con.MB_ICONERROR)
-            return False
-        
-        # save log message to a temp file        
-        text = '\n'.join(lines)
-        logfd, logpath = tempfile.mkstemp(prefix="tortoisehg_ci_log_")
-        os.write(logfd, text)
-        os.close(logfd)
-
-        # commit file with log message        
-        root = thgutil.find_root(self.commitfiles[0])
-        quoted_files = [util.shellquote(s) for s in self.commitfiles]
-        cmdline = "hg --repository %s commit --verbose --logfile %s %s" % (
-                        util.shellquote(root),
-                        util.shellquote(logpath),
-                        " ".join(quoted_files))
-        gpopen.run(cmdline, modal=True)
-        os.unlink(logpath)
-        
-        # refresh overlay icons in commit directories
-        # FIXME: other explorer windows opened on the same repo
-        #        may not get refreshed
-        for f in self.commitfiles:
-            dir = os.path.isdir(f) and f or os.path.dirname(f)
-            thgutil.shell_notify(dir)
-
-        return True
-
-def do_commit(files):
-    """
-    show a simple editor dialog for enter log message,
-    and commit the list of files.
-    """
-
-    # show commit dialog
-    dlg = SimpleCommitDialog(files=files)
-    dlg.CreateWindow()
-    return dlg
-
-if __name__ == "__main__":
-    files = ["D:\\Profiles\\r28629\\My Documents\\Mercurial\\repos\\c1\\"]
-    do_commit(files)

hgwin/gpopen.py

-#
-# Execute a Mercurial (Hg) command and show it's output on an MFC dialog.
-#
-# Copyright (C) 2007 TK Soh <teekaysoh@gmail.com>
-#
-
-import subprocess
-import threading
-import win32ui
-from pywin.framework.dlgappcore import AppDialog
-import win32con
-import win32api
-import win32gui
-import re
-import thgutil
-import os
-
-dlgStatic = 130
-dlgEdit = 129
-dlgButton = 128
-
-dlg_EDIT1 = 1001
-
-class ResizableEditDialog(AppDialog): 
-    def __init__(self, title="hg", tmpl=None):
-        self.title = title
-        if tmpl is None:
-            tmpl = dlg_template()
-        AppDialog.__init__(self, tmpl)
-
-    def OnInitDialog(self): 
-        rc = AppDialog.OnInitDialog(self)
-        self.HookMessage(self.OnSize, win32con.WM_SIZE)
-
-        if self.title:
-            self.SetWindowText(self.title)
-        self.outtext = self.GetDlgItem(dlg_EDIT1)
-        self.outtext.SetReadOnly()
-        self.outtext.LimitText(10000000)    # enough to hald the log output?
- 
-        # set output window to use fixed font
-        self.font = win32ui.CreateFont({'name': "Courier New", 'height': 14})
-        self.outtext.SetFont(self.font);
-
-    def write(self, msg):
-        # convert LF to CRLF for binary output
-        msg = re.sub(r'(?<!\r)\n', r'\r\n', msg)
-        self.outtext.ReplaceSel(msg)
-
-    def OnCreate(self, msg):
-        print "Oncreate: ", msg
-        rect = self.GetClientRect()
-        print "dlg client rect = ", rect
- 
-    def _do_size(self, cx, cy, repaint=1):
-        # resize the textbox.
-        ctrl = self.GetDlgItem(dlg_EDIT1)
-        l, t, r, b = ctrl.GetWindowRect()
-        l, t = self.ScreenToClient( (l,t) )
-        r, b = self.ScreenToClient( (r,b) )
-        ctrl.MoveWindow((l, t, cx-6, cy-40), repaint)
-        
-        # relocate the button.
-        ctrl = self.GetDlgItem(win32con.IDOK)
-        l, t, r, b = ctrl.GetWindowRect()
-        l, t = self.ScreenToClient( (l,t) )
-        r, b = self.ScreenToClient( (r,b) )
-        w = r - l
-        h = b - t
-        ctrl.MoveWindow(( l, cy-4-h, r, cy-4), repaint)
-
-    def OnSize(self, message):
-        hwnd, msg, wparam, lparam, time, point = message        
-        x = win32api.LOWORD(lparam)
-        y = win32api.HIWORD(lparam)
-        self._do_size(x,y)
-        return 1
-
-def dlg_template(w=300, h=300):
-    style = (win32con.DS_MODALFRAME | 
-             win32con.WS_POPUP | 
-             win32con.WS_VISIBLE | 
-             win32con.WS_CAPTION | 
-             win32con.WS_SYSMENU |
-             win32con.WS_THICKFRAME |  # we can resize the dialog window
-             win32con.DS_SETFONT)
-
-    cs = win32con.WS_CHILD | win32con.WS_VISIBLE 
-    s = win32con.WS_TABSTOP | cs 
-      
-    dlg = [["PyWin32", (0, 0, w, h), style, None, (8, "MS Sans Serif")],] 
-    dlg.append([dlgEdit, "", dlg_EDIT1, (3, 3, w-6, h - 23),
-                    s | win32con.SS_LEFT
-                      | win32con.WS_BORDER
-                      | win32con.ES_MULTILINE
-                      | win32con.WS_VSCROLL
-                      | win32con.WS_HSCROLL
-                      | win32con.ES_WANTRETURN
-               ])
-    bw, bh = 50, 15
-    dlg.append([dlgButton, "OK", win32con.IDOK, (3, h -bh -2, bw, bh),
-                    s | win32con.BS_PUSHBUTTON]) 
-
-    return dlg
-
-class PopenDialog(ResizableEditDialog):
-    def __init__(self, cmd, title=None, tmpl=None, notify_list=[]):
-        self.cmdline = cmd
-        ResizableEditDialog.__init__(self, title, tmpl)
-        self.notify_list = notify_list
-
-    def OnInitDialog(self):
-        rc = ResizableEditDialog.OnInitDialog(self)
-        self.ok_btn = self.GetDlgItem(win32con.IDOK)
-        self.thread1 = threading.Thread(target=self.run_program)
-        self.thread1.start()
-
-    def run_program(self):
-        pop = subprocess.Popen(self.cmdline, 
-                               shell=True,
-                               stderr=subprocess.STDOUT,
-                               stdout=subprocess.PIPE,
-                               stdin=subprocess.PIPE)
-
-        bytes = 0
-        print "popen begin"
-        self.ok_btn.EnableWindow(False) # disable OK button
-        try:
-            line = 0
-            blocksize = 1024
-            while pop.poll() == None:
-                if line < 100:
-                    out = pop.stdout.readline()
-                    line += 1
-                else:
-                    out = pop.stdout.read(blocksize)
-                    if blocksize < 1024 * 50:
-                        blocksize *= 2
-                bytes += len(out)
-                self.write(out)
-            out = pop.stdout.read()
-            bytes += len(out)
-            self.write(out)
-        except IOError:
-            pass
-
-        self._do_notify()
-        self.ok_btn.EnableWindow(True) # enable OK button
-        print "popen end: bytes = ", bytes
-
-    def _do_notify(self):
-        if not self.notify_list:
-            return
-        
-        for f in self.notify_list:
-            dir = os.path.isdir(f) and f or os.path.dirname(f)
-            thgutil.shell_notify(dir)
-        
-def run(cmd, modal=False, title='Mercurial'):
-    tmpl = dlg_template(300, 250)
-    gui = PopenDialog(cmd, title, tmpl, notify_list=["c:\\hg\\h1\\f1"])
-    if modal:
-        gui.DoModal()
-    else:
-        gui.CreateWindow()
-    
-if __name__=='__main__':
-    run('hg help -v')

hgwin/gpopen2.py

-#
-# Execute a Mercurial (Hg) command and show it's output on an win32gui dialog.
-#
-# Copyright (C) 2007 TK Soh <teekaysoh@gmail.com>
-#
-import os, sys
-import winxpgui as win32gui
-import win32api
-import win32con
-import struct
-import commctrl
-import subprocess
-import getopt
-import thgutil
-
-# control ID
-IDC_COMMANDTEXT = 1024
-IDC_BUTTON_REFRESH = 1025
-IDC_BUTTON_CLOSE = 1026
-IDC_OUTPUT_EDIT = 1027
-
-g_registeredClass = 0
-
-def setEditFont(hwnd, fontname, height):
-    lf = win32gui.LOGFONT()
-    lf.lfFaceName = fontname
-    lf.lfHeight = height
-    #lf.lfWidth = width
-    #lf.lfPitchAndFamily = win32con.FIXED_PITCH
-    font = win32gui.CreateFontIndirect(lf)
-    win32gui.SendMessage(hwnd, win32con.WM_SETFONT, font, 0)
-    return font
-
-def setEditText(hwnd, text, append=False):
-    text = type(text) == type([]) and text or [text]
-    
-    # Set the current selection range, depending on append flag
-    if append:
-        win32gui.SendMessage(hwnd, win32con.EM_SETSEL, -1, 0)
-    else:
-        win32gui.SendMessage(hwnd, win32con.EM_SETSEL, 0, -1)
-
-    # Send the text
-    win32gui.SendMessage(hwnd,
-                         win32con.EM_REPLACESEL,
-                         True,
-                         os.linesep.join(text))
-
-class PopenWindowBase:
-    def __init__(self):
-        win32gui.InitCommonControls()
-        self.hinst = win32gui.dllhandle
-        self.list_data = {}
-
-    def CreateWindow(self):
-        self._isModal = False
-        self._DoCreate(win32gui.CreateDialogIndirect)
-        
-    def DoModal(self):
-        self._isModal = True
-        return self._DoCreate(win32gui.DialogBoxIndirect)
-
-    def _RegisterWndClass(self):
-        className = "TortoiseHgDialog"
-        global g_registeredClass
-        if not g_registeredClass:
-            message_map = {}
-            wc = win32gui.WNDCLASS()
-            wc.SetDialogProc() # Make it a dialog class.
-            wc.hInstance = self.hinst
-            wc.lpszClassName = className
-            wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
-            wc.hCursor = win32gui.LoadCursor( 0, win32con.IDC_ARROW )
-            wc.hbrBackground = win32con.COLOR_WINDOW + 1
-            wc.lpfnWndProc = message_map # could also specify a wndproc.
-            # C code: wc.cbWndExtra = DLGWINDOWEXTRA + sizeof(HBRUSH) + (sizeof(COLORREF));
-            wc.cbWndExtra = win32con.DLGWINDOWEXTRA + struct.calcsize("Pi")
-            icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
-            icon_path = thgutil.get_icon_path("tortoise", "hg.ico")
-            if icon_path:
-                wc.hIcon = win32gui.LoadImage(self.hinst, icon_path,
-                                              win32con.IMAGE_ICON,
-                                              0,
-                                              0,
-                                              icon_flags)
-            classAtom = win32gui.RegisterClass(wc)
-            g_registeredClass = 1
-        return className
-
-    def _GetDialogTemplate(self, dlgClassName):
-        w = 300
-        h = 250
-        style = (  win32con.WS_THICKFRAME 
-                 | win32con.WS_POPUP 
-                 | win32con.WS_VISIBLE 
-                 | win32con.WS_CAPTION 
-                 | win32con.WS_SYSMENU 
-                 | win32con.DS_SETFONT 
-                 | win32con.WS_MINIMIZEBOX )
-        cs = win32con.WS_CHILD | win32con.WS_VISIBLE
-        title = "Mercurial"
-
-        # Window frame and title
-        dlg = [ [title, (0, 0, w, h), style, None, (8, "MS Sans Serif"),
-                 None, dlgClassName], ]
-
-        # ID label and text box
-        dlg.append([130, "Command:", -1, (5, 5, w - 10, 9), cs | win32con.SS_LEFT])
-        s = cs | win32con.WS_TABSTOP | win32con.WS_BORDER
-        dlg.append(['EDIT', None, IDC_COMMANDTEXT, (5, 15, w - 10, 12), s])
-
-        # Search/Display Buttons
-        # (x positions don't matter here)
-        s = cs | win32con.WS_TABSTOP
-        dlg.append([128, "Refresh", IDC_BUTTON_REFRESH, (5, 35, 50, 14), s])
-        dlg.append([128, "Close", IDC_BUTTON_CLOSE, (100, 35, 50, 14), 
-                    s | win32con.BS_DEFPUSHBUTTON])
-
-        dlg.append(['EDIT', "", IDC_OUTPUT_EDIT, (5, 55, w - 10, h - 60),
-                    cs | win32con.SS_LEFT
-                       | win32con.WS_BORDER
-                       | win32con.ES_MULTILINE
-                       | win32con.WS_VSCROLL
-                       | win32con.WS_HSCROLL
-                       | win32con.ES_WANTRETURN
-                   ])
-        return dlg
-
-    def _DoCreate(self, fn):
-        message_map = {
-            win32con.WM_SIZE: self.OnSize,
-            win32con.WM_COMMAND: self.OnCommand,
-            win32con.WM_NOTIFY: self.OnNotify,
-            win32con.WM_INITDIALOG: self.OnInitDialog,
-            win32con.WM_CLOSE: self.OnClose,
-            win32con.WM_DESTROY: self.OnDestroy,
-        }
-        dlgClassName = self._RegisterWndClass()
-        template = self._GetDialogTemplate(dlgClassName)
-        return fn(self.hinst, template, 0, message_map)
-
-    def OnInitDialog(self, hwnd, msg, wparam, lparam):
-        self.hwnd = hwnd
-        # centre the dialog
-        desktop = win32gui.GetDesktopWindow()
-        l,t,r,b = win32gui.GetWindowRect(self.hwnd)
-        dt_l, dt_t, dt_r, dt_b = win32gui.GetWindowRect(desktop)
-        centre_x, centre_y = win32gui.ClientToScreen( desktop, ( (dt_r-dt_l)/2, (dt_b-dt_t)/2) )
-        win32gui.MoveWindow(hwnd, centre_x-(r/2), centre_y-(b/2), r-l, b-t, 0)
-        l,t,r,b = win32gui.GetClientRect(self.hwnd)
-        self._DoSize(r-l,b-t, 1)
-
-    def _DoSize(self, cx, cy, repaint = 1):
-        # right-justify the textbox.
-        ctrl = win32gui.GetDlgItem(self.hwnd, IDC_COMMANDTEXT)
-        l, t, r, b = win32gui.GetWindowRect(ctrl)
-        l, t = win32gui.ScreenToClient(self.hwnd, (l,t) )
-        r, b = win32gui.ScreenToClient(self.hwnd, (r,b) )
-        win32gui.MoveWindow(ctrl, l, t, cx-l-5, b-t, repaint)
-
-        # The button.
-        ctrl = win32gui.GetDlgItem(self.hwnd, IDC_BUTTON_CLOSE)
-        l, t, r, b = win32gui.GetWindowRect(ctrl)
-        l, t = win32gui.ScreenToClient(self.hwnd, (l,t) )
-        r, b = win32gui.ScreenToClient(self.hwnd, (r,b) )
-        list_y = b + 10
-        w = r - l
-        win32gui.MoveWindow(ctrl, cx - 5 - w, t, w, b-t, repaint)
-
-        # the output textbox
-        ctrl = win32gui.GetDlgItem(self.hwnd, IDC_OUTPUT_EDIT)
-        l, t, r, b = win32gui.GetWindowRect(ctrl)
-        l, t = win32gui.ScreenToClient(self.hwnd, (l,t) )
-        r, b = win32gui.ScreenToClient(self.hwnd, (r,b) )
-        w = r - l
-        win32gui.MoveWindow(ctrl, l, t, cx -l -5, cy -t -5, repaint)
-
-    def OnSize(self, hwnd, msg, wparam, lparam):
-        x = win32api.LOWORD(lparam)
-        y = win32api.HIWORD(lparam)
-        self._DoSize(x,y)
-        return 1
-
-    def OnNotify(self, hwnd, msg, wparam, lparam):
-        format = "iiiiiiiiiii"
-        buf = win32gui.PyMakeBuffer(struct.calcsize(format), lparam)
-        hwndFrom, idFrom, code, iItem, iSubItem, uNewState, uOldState, uChanged, actionx, actiony, lParam \
-                  = struct.unpack(format, buf)
-        # *sigh* - work around a problem with old commctrl modules, which had a
-        # bad value for PY_OU, which therefore cause most "control notification"
-        # messages to be wrong.
-        # Code that needs to work with both pre and post pywin32-204 must do
-        # this too.
-        code += commctrl.PY_0U
-        if code == commctrl.NM_DBLCLK:
-            print "Double click on item", iItem+1
-        return 1
-
-    def OnCommand(self, hwnd, msg, wparam, lparam):
-        id = win32api.LOWORD(wparam)
-        if id == IDC_BUTTON_REFRESH:
-            self.DoRefresh()
-        elif id == IDC_BUTTON_CLOSE:
-            self.DoClose()
-
-    def DoRefresh(self):
-        pass
-
-    def DoClose(self):
-        self._do_close(self.hwnd)
-
-    def _do_close(self, hwnd):
-        if self._isModal:
-            win32gui.EndDialog(hwnd, 0)
-        else:
-            win32gui.DestroyWindow(hwnd)
-    
-    def OnClose(self, hwnd, msg, wparam, lparam):
-        self._do_close(hwnd)
-
-    def OnDestroy(self, hwnd, msg, wparam, lparam):
-        self._do_close(hwnd)
-
-class PopenDialog(PopenWindowBase):
-    def __init__(self, cmdline='', title="popen"):
-        self.cmdline = cmdline
-        self.title = title
-        self.outbuf = ""
-        PopenWindowBase.__init__(self)
-
-    def OnInitDialog(self, hwnd, msg, wparam, lparam):
-        rc = PopenWindowBase.OnInitDialog(self, hwnd, msg, wparam, lparam)
-        self._setup_dialog()
-
-    def _setup_dialog(self):
-        win32gui.SetWindowText(self.hwnd, self.title)
-        ctrl = win32gui.GetDlgItem(self.hwnd, IDC_COMMANDTEXT)
-        cmdline = type(self.cmdline) == type([]) and " ".join(self.cmdline) \
-                                                  or self.cmdline
-        setEditText(ctrl, cmdline)
-        win32gui.SendMessage(ctrl, win32con.EM_SETREADONLY, 1, 0);
-        
-        # condition output text control
-        self.outtext = win32gui.GetDlgItem(self.hwnd, IDC_OUTPUT_EDIT)
-        win32gui.SendMessage(self.outtext, win32con.EM_LIMITTEXT, 100000000, 0);
-        win32gui.SendMessage(self.outtext, win32con.EM_SETREADONLY, 1, 0);
-        self.fixedfont = setEditFont(self.outtext, "Courier New", 15)
-        #win32gui.SetTextColor(self.outtext, win32api.RGB(255,0,0))
-        
-        self._start_thread()
-
-    # We need to arrange to a WM_QUIT message to be sent to our
-    # PumpMessages() loop.
-    def OnDestroy(self, hwnd, msg, wparam, lparam):
-        win32gui.PostQuitMessage(0) # Terminate the app.
-        
-    def _start_thread(self):
-        import threading
-        self.thread1 = threading.Thread(target=self._do_popen)
-        self.thread1.start()
-        
-    def write(self, msg):
-        setEditText(self.outtext, [msg], append=True)
-        
-    def DoRefresh(self):
-        self.outbuf = ""
-        setEditText(self.outtext, [''])
-        self._start_thread()
-        
-    def _do_popen(self):        
-        if not self.cmdline:
-            return
-
-        pop = subprocess.Popen(self.cmdline, 
-                               shell=True,
-                               stderr=subprocess.STDOUT,
-                               stdout=subprocess.PIPE,
-                               stdin=subprocess.PIPE)
-
-        bytes = 0
-        refresh_btn = win32gui.GetDlgItem(self.hwnd, IDC_BUTTON_REFRESH)
-        win32gui.EnableWindow(refresh_btn, False)
-        try:
-            line = 0
-            blocksize = 1024
-            while pop.poll() == None:
-                if line < 100:
-                    out = pop.stdout.readline()
-                    line += 1
-                else:
-                    out = pop.stdout.read(blocksize)
-                    if blocksize < 1024 * 50:
-                        blocksize *= 2
-                bytes += len(out)
-                self.write(out)
-            out = pop.stdout.read()
-            bytes += len(out)
-            self.write(out)
-        except IOError:
-            pass
-
-        win32gui.EnableWindow(refresh_btn, True)
-
-def run(cmdline, title='Hg', modal=False):
-    dlg = PopenDialog(cmdline=cmdline, title=title)
-    if modal:
-        dlg.DoModal()
-    else:
-        dlg.CreateWindow()
-        win32gui.PumpMessages()
-    
-def get_option(args):
-    long_opt_list =  ['command=', 'exepath=', 'listfile=', 'title=',
-                      'root=', 'notify', 'deletelistfile']
-    opts, args = getopt.getopt(args, "c:e:l:ndt:R:", long_opt_list)
-    options = dict({'hgcmd': 'help', 'hgpath': 'hg'} )
-    
-    for o, a in opts:
-        if o in ("-c", "--command"):
-            options['hgcmd'] = a
-        elif o in ("-l", "--listfile"):
-            options['listfile'] = a
-        elif o in ("-e", "--exepath"):
-            options['hgpath'] = a
-        elif o in ("-n", "--notify"):
-            options['notify'] = True
-        elif o in ("-t", "--title"):
-            options['title'] = a
-        elif o in ("-d", "--deletelistfile"):
-            options['rmlistfile'] = True
-        elif o in ("-R", "--root"):
-            options['root'] = a
-
-    return (options, args)
-
-def get_list_from_file(filename):
-    fd = open(filename, "r")
-    lines = [ x.replace("\n", "") for x in fd.readlines() ]
-    fd.close()
-    return lines
-    
-if __name__=='__main__':
-    if len(sys.argv) > 1:
-        try:
-            option, args = get_option(sys.argv[1:])
-        except getopt.GetoptError, inst:
-            print inst
-            sys.exit(1)
-        
-        filelist = []
-        if option.has_key('listfile'):
-            filelist = get_list_from_file(option['listfile'])
-            
-        #cmdline = option['hgpath']
-        cmdline = "hg %s" % option['hgcmd']
-        if option.has_key('root'):
-            cmdline += " --repository %s" % thgutil.shellquote(option['root'])
-        if args:
-            cmdline += " %s" % " ".join([(x) for x in args])
-        if filelist:
-            cmdline += " %s" % " ".join([thgutil.shellquote(x) for x in filelist])
-                    
-        opt = {}
-        if option.has_key('title'):
-            opt['title'] = option['title']
-        elif option.has_key('root'):
-            opt['title'] = "hg %s - %s" % (option['hgcmd'], option['root'])
-        else:
-            opt['title'] = "hg %s" % option['hgcmd']
-
-        run(cmdline, **opt)
-                             
-        if option.has_key('notify'):
-            for f in filelist:
-                dir = os.path.isdir(f) and f or os.path.dirname(f)
-                thgutil.shell_notify(os.path.abspath(dir))
-
-        if option.has_key('rmlistfile'):
-            os.unlink(option['listfile'])
-            
-    # ========== test cases ==========
-    #run(['hg log -v', modal=True])
-    #run(['hg', 'log', '-v'], modal=False)
-    #run(['hg -R C:\hg\h1 log -v'])
-    #run(['hg version'])

hgwin/listdialog.py

-from pywin.mfc import dialog
-import win32ui, win32con, commctrl, win32api
-import win32gui
-
-def enable_list_checkbox(ctrl):
-	hwnd = ctrl.GetSafeHwnd()
-	style = win32gui.SendMessage(hwnd,
-								 commctrl.LVM_GETEXTENDEDLISTVIEWSTYLE,
-								 0,
-								 0)
-	style |= commctrl.LVS_EX_FULLROWSELECT
-	style |= commctrl.LVS_EX_CHECKBOXES
-	win32gui.SendMessage(hwnd, commctrl.LVM_SETEXTENDEDLISTVIEWSTYLE, 0, style)
-
-def _get_list_check(state):
-	return ((state & commctrl.LVIS_STATEIMAGEMASK) >> 12) -1
-
-class ListDialog (dialog.Dialog):
-	
-	def __init__ (self, title, list, resizable=False, checkbox=False):
-		dialog.Dialog.__init__ (self, self._maketemplate(title, resizable))
-		self.HookMessage (self.on_size, win32con.WM_SIZE)
-		self.HookNotify(self.OnListItemChange, commctrl.LVN_ITEMCHANGED)
-		self.HookCommand(self.OnListClick, win32ui.IDC_LIST1)
-		self.items = list
-		self.has_checkbox = checkbox
-		self.checkbox_state = {}
-
-	def _maketemplate(self, title, resizable):
-		style = win32con.WS_DLGFRAME | win32con.WS_SYSMENU | win32con.WS_VISIBLE
-		if resizable: style |= win32con.WS_THICKFRAME
-
-		ls = (
-				win32con.WS_CHILD           |
-				win32con.WS_VISIBLE         |
-				commctrl.LVS_ALIGNLEFT      |
-				commctrl.LVS_REPORT
-			)
-		bs = (
-				win32con.WS_CHILD           |
-				win32con.WS_VISIBLE
-			)
-		
-		return [
-				[title, (0, 0, 200, 200), style, None, (8, "MS Sans Serif")],
-				["SysListView32", None, win32ui.IDC_LIST1, (0, 0, 200, 200), ls], 
-				[128, "OK", win32con.IDOK, (10, 0, 50, 14), bs | win32con.BS_DEFPUSHBUTTON],
-				[128, "Cancel",win32con.IDCANCEL,(0, 0, 50, 14), bs],
-			]
-
-	def FillList(self):
-		size = self.GetWindowRect()
-		width = size[2] - size[0] - (10)
-		itemDetails = (commctrl.LVCFMT_LEFT, width, "Item", 0)
-		self.itemsControl.InsertColumn(0, itemDetails)
-		index = 0
-		for item in self.items:
-			index = self.itemsControl.InsertItem(index+1, str(item), 0)
-	
-	def OnListClick(self, id, code):
-		if code==commctrl.NM_DBLCLK:
-			self.EndDialog(win32con.IDOK)
-		return 1
-	
-	def OnListItemChange(self,std, extra):
-		(hwndFrom, idFrom, code), (itemNotify, sub, newState, oldState, change, point, lparam) = std, extra
-		oldSel = (oldState & commctrl.LVIS_SELECTED)<>0
-		newSel = (newState & commctrl.LVIS_SELECTED)<>0
-		self.checkbox_state[itemNotify] = _get_list_check(newState)
-		if oldSel <> newSel:
-			try:
-				self.selecteditem = itemNotify
-				self.butOK.EnableWindow(1)
-			except win32ui.error:
-				self.selecteditem = None
-	
-	def OnInitDialog (self):
-		rc = dialog.Dialog.OnInitDialog (self)
-		self.itemsControl = self.GetDlgItem(win32ui.IDC_LIST1)
-		self.butOK = self.GetDlgItem(win32con.IDOK)
-		self.butCancel = self.GetDlgItem(win32con.IDCANCEL)
-		
-		self.FillList()		
-		
-		size = self.GetWindowRect()
-		self.LayoutControls(size[2]-size[0], size[3]-size[1])
-		#self.butOK.EnableWindow(0) # wait for first selection
-
-		# checkboxes to list control
-		if self.has_checkbox:
-			enable_list_checkbox(self.itemsControl)
-		
-		return rc
-		
-	def LayoutControls(self, w, h):
-		self.itemsControl.MoveWindow((0,0,w,h-30))
-		self.butCancel.MoveWindow((10, h-24, 60, h-4))
-		self.butOK.MoveWindow((w-60, h-24, w-10, h-4))
-		self.itemsControl.SetColumnWidth(len(self.colHeadings)-1,
-										 commctrl.LVSCW_AUTOSIZE_USEHEADER)
-	
-	def on_size (self, params):
-		lparam = params[3]
-		w = win32api.LOWORD(lparam)
-		h = win32api.HIWORD(lparam)
-		self.LayoutControls(w, h)
-
-	def _GetState(index):
-		if not self.has_checkbox:
-			return None
-		return self.checkbox_state.get(index, 0)
-		
-class ListsDialog(ListDialog):
-	def __init__(self, title, list, colHeadings = ['Item'], resizable=False, checkbox=False):
-		ListDialog.__init__(self, title, list, resizable, checkbox)
-		self.colHeadings = colHeadings
-
-	def FillList(self):
-		index = 0
-		size = self.GetWindowRect()
-		width = size[2] - size[0] - (10) - win32api.GetSystemMetrics(win32con.SM_CXVSCROLL)
-		numCols = len(self.colHeadings)
-
-		for col in self.colHeadings:
-			itemDetails = (commctrl.LVCFMT_LEFT, width/numCols, col, 0)
-			self.itemsControl.InsertColumn(index, itemDetails)
-			index = index + 1
-		index = 0
-		for items in self.items:
-			index = self.itemsControl.InsertItem(index+1, str(items[0]), 0)
-			for itemno in range(1,numCols):
-				item = items[itemno]
-				self.itemsControl.SetItemText(index, itemno, str(item))
-			
-def SelectFromList (title, lst):
-	dlg = ListDialog(title, lst)
-	if dlg.DoModal()==win32con.IDOK:
-		return dlg.selecteditem
-	else:
-		return None
-
-def SelectFromLists (title, lists, headings):
-	dlg = ListsDialog(title, lists, headings)
-	if dlg.DoModal()==win32con.IDOK:
-		return dlg.selecteditem
-	else:
-		return None
-
-def test():
-	#print SelectFromList('Single list',  [1,2,3])
-	print SelectFromLists('Multi-List', [ ('1',1, 'a'), ('2',2, 'b'), ('3',3, 'c' )], ['Col 1', 'Col 2', ''])
-
-def demo():
-	dlg = ListsDialog('Multi-List',
-					  [ ('1',1, 'a'), ('2',2, 'b'), ('3',3, 'c' )],
-					  ['Col 1', 'Col 2', ''],
-					  checkbox=True,
-					  resizable=True)
-	dlg.CreateWindow()
-	
-if __name__=='__main__':	
-	demo()

hgwin/statusdialog.py

-"""
-statusdialog.py - a simple status dialog for TortoiseHg
-
- Copyright (C) 2007 TK Soh <teekaysoh@gmail.com>
-
-This software may be used and distributed according to the terms
-of the GNU General Public License, incorporated herein by reference.
-"""
-import win32ui
-import os
-import commctrl
-import win32con
-from pywin.tools import hierlist
-from mercurial import hg, repo, ui, cmdutil, util
-import thgutil
-
-status_type = [
-        'Modified',
-        'Added',
-        'Removed',
-        'Deleted',
-        'Unknown',
-        'Clean',
-        'Ignored',
-    ]
-
-def get_repo_status(cwd, files=[], list_ignored=False, list_clean=False):
-    root = thgutil.find_root(cwd)
-    u = ui.ui()
-    try:
-        repo = hg.repository(u, path=root)
-    except repo.RepoError:
-        return None
-
-    # get file status
-    try:
-        files, matchfn, anypats = cmdutil.matchpats(repo, pats=files)
-        modified, added, removed, deleted, unknown, ignored, clean = [
-                n for n in repo.status(files=files, list_ignored=list_ignored,
-                                       list_clean=list_clean)]
-    except util.Abort, inst:
-        return None
-
-    return {'Modified': modified,
-            'Added': added,
-            'Removed': removed,
-            'Deleted': deleted,
-            'Unknown': unknown,
-            'Ignored': ignored,
-            'Clean': clean}
-
-class HgStatusList(hierlist.HierList):
-    def __init__(self, cwd, files=[], listBoxID = win32ui.IDC_LIST1):
-        hierlist.HierList.__init__(self, cwd, win32ui.IDB_HIERFOLDERS, listBoxID)
-        self._files = files
-        self.cwd = cwd
-        self.list_clean = False
-        self.list_ignored = False
-        self.status = {}
-
-    def _get_status(self):
-        self.status = get_repo_status(self.cwd, files=self._files,
-                                      list_ignored=self.list_ignored,
-                                      list_clean=self.list_clean)
-        self.Refresh()
-
-    def GetText(self, item):
-        if type(item) == type([]):
-            return item[0]
-        else:
-            return os.path.normpath(item)
-
-    def GetSubList(self, item):
-        if item == self.root:
-            # return group as list of [<groupname>, <list of file>] to
-            # differentiate status group from file in list
-            ret = [[x, self.status[x]] for x in status_type
-                        if self.status.has_key(x) and self.status[x]]
-        elif type(item) == type([]):
-            ret = item[1]   # file list of status
-        else:
-            ret = item
-
-        return ret
-
-    def IsExpandable(self, item):
-        return type(item) == type([])
-
-    def GetSelectedBitmapColumn(self, item):
-        #return self.GetBitmapColumn(item)+6 # Use different color for selection
-        pass
-
-    def OnTreeItemDoubleClick(self,(hwndFrom, idFrom, code), extra):
-        pass
-
-class StatusDialog(hierlist.HierDialog):
-    def __init__(self, title, hierList, bitmapID = win32ui.IDB_HIERFOLDERS,
-                 dlgID = win32ui.IDD_TREE, dll = None,
-                 childListBoxID = win32ui.IDC_LIST1):
-        hierlist.HierDialog.__init__(self, title, hierList, bitmapID,
-                                     self._dialog_template(), dll,
-                                     childListBoxID)
-
-    def OnInitDialog(self):
-        hierlist.HierDialog.OnInitDialog(self)
-
-        self.list_clean = self.GetDlgItem(win32ui.IDC_CHECK1).GetState()
-        self.list_ignored = self.GetDlgItem(win32ui.IDC_CHECK2).GetState()
-
-        # handler for changes on checkbox state
-        self.HookCommand(self.OnNotify, win32ui.IDC_CHECK1)
-        self.HookCommand(self.OnNotify, win32ui.IDC_CHECK2)
-
-        # refresh button
-        self.HookCommand(self._on_refresh, win32ui.IDC_BUTTON1)
-
-        # display repo status
-        self.hierList._get_status()
-
-    def OnNotify(self, id, code):
-        if id == win32ui.IDC_CHECK1:
-            self.hierList.list_clean = self.GetDlgItem(win32ui.IDC_CHECK1).GetCheck()
-            self.hierList._get_status()
-        elif id == win32ui.IDC_CHECK2:
-            self.hierList.list_ignored = self.GetDlgItem(win32ui.IDC_CHECK2).GetCheck()
-            self.hierList._get_status()
-
-    def _on_refresh(self, id, code):
-        self.hierList._get_status()
-
-    # support dialog app
-    def PreDoModal(self):
-        pass
-
-    def _dialog_template(self):
-        # dialog resource reference:
-        #
-        # IDD_TREE DIALOG DISCARDABLE  0, 0, 226, 93
-        # STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
-        # CAPTION "title"
-        # FONT 8, "MS Sans Serif"
-        # BEGIN
-        #     DEFPUSHBUTTON   "OK",IDOK,170,5,50,14
-        #     PUSHBUTTON      "Cancel",IDCANCEL,170,25,50,14
-        #     CONTROL         "Tree1",IDC_LIST1,"SysTreeView32",TVS_HASBUTTONS |
-        #                    TVS_HASLINES | TVS_LINESATROOT | TVS_SHOWSELALWAYS |
-        #                    WS_BORDER | WS_TABSTOP,3,3,160,88
-        # END
-
-        w, h = 250, 150
-        padx, pady = 3, 3
-        bw, bh = 50, 14
-        lw, lh = w-bw-padx*4, h-pady*2
-        bx = lw + padx*2
-        style = (win32con.DS_MODALFRAME |
-                 win32con.WS_POPUP |
-                 win32con.WS_VISIBLE |
-                 win32con.WS_CAPTION |
-                 win32con.WS_SYSMENU |
-                 win32con.DS_CENTER |
-                 win32con.DS_CENTERMOUSE |
-                 #win32con.WS_THICKFRAME |  # we can resize the dialog window
-                 win32con.DS_SETFONT)
-
-        cs = win32con.WS_CHILD | win32con.WS_VISIBLE
-        s = win32con.WS_TABSTOP | cs
-
-        dlg = [["TortoiseHg", (0, 0, w, h), style, None, (8, "MS Sans Serif")],]
-        dlg.append(['SysTreeView32', "Tree1", win32ui.IDC_LIST1, (3,3,lw,lh),
-                        s | win32con.WS_BORDER
-                          | win32con.WS_CHILD
-                          | win32con.WS_VISIBLE
-                          | commctrl.TVS_HASBUTTONS
-                          | commctrl.TVS_HASLINES
-                          | commctrl.TVS_LINESATROOT
-                          | commctrl.TVS_SHOWSELALWAYS
-                   ])
-
-        dlg.append([128 ,"OK", win32con.IDOK, (bx,5,bw,bh),
-                        s | win32con.BS_PUSHBUTTON
-                   ])
-        dlg.append([128,"Refresh", win32ui.IDC_BUTTON1, (bx,25,bw,bh),
-                        s | win32con.BS_PUSHBUTTON
-                   ])
-        dlg.append([128, "show clean", win32ui.IDC_CHECK1, (bx,45,bw,bh),
-                        s | win32con.BS_AUTOCHECKBOX
-                   ])
-        dlg.append([128, "show ignored", win32ui.IDC_CHECK2, (bx,55,bw,bh),
-                        s | win32con.BS_AUTOCHECKBOX
-                   ])
-        return dlg
-
-def status_dialog(root, files=[]):
-    stlist = HgStatusList(root, files)
-    dlg = StatusDialog('hg status - %s' % root, stlist)
-    return dlg
-
-def test(root, files=[]):
-    dlg = status_dialog(root, files)
-    dlg.CreateWindow()
-
-if __name__=='__main__':
-    test("c:\hg\h1")
-    #test("c:\hg\h1", ["c:\hg\h1\mercurial"])

hgwin/tagadddialog.py

-"""
-tagadddialog.py - TortoiseHg dialog to add tag to repository 
-
- Copyright (C) 2007 TK Soh <teekaysoh@gmail.com>
-
-This software may be used and distributed according to the terms
-of the GNU General Public License, incorporated herein by reference.
-"""
-
-import win32ui
-import win32con
-from pywin.framework.dlgappcore import AppDialog
-from mercurial import util
-from mercurial.i18n import _
-from mercurial.node import *
-import gpopen
-import thgutil
-
-dlgStatic = 130
-dlgEdit = 129
-dlgButton = 128 
-
-def error_dialog(msg):
-    win32ui.MessageBox(msg, "hg tag", win32con.MB_OK | win32con.MB_ICONERROR)
-
-def msg_dialog(msg):
-    win32ui.MessageBox(msg, "hg tag", win32con.MB_OK)
-
-def _dlg_template():
-    w, h = 250, 100
-    bw, bh = 40, 12
-    e1w, e1h = 100, 12
-    e2w, e2h = w-10, 24
-    
-    style = (#win32con.DS_MODALFRAME | 
-             win32con.WS_POPUP | 
-             win32con.WS_VISIBLE | 
-             win32con.WS_CAPTION | 
-             win32con.WS_SYSMENU |
-             win32con.DS_CENTER |
-             # win32con.DS_CENTERMOUSE |
-             # win32con.WS_THICKFRAME |  # we can resize the dialog window
-             win32con.DS_SETFONT)
-
-    cs = win32con.WS_CHILD | win32con.WS_VISIBLE 
-    s = win32con.WS_TABSTOP | cs 
-
-    dlg = [["TortoiseHg", (3, 4, w, h), style, None, (8, "MS Sans Serif")],]
-    
-    dlg.append([dlgStatic, "Tag Name:", win32ui.IDC_PROMPT1, (5,9,40,12),
-                    cs | win32con.SS_LEFT
-               ])
-    dlg.append([dlgEdit, "", win32ui.IDC_EDIT1, (50,6,e1w,e1h),
-                    s | win32con.ES_AUTOHSCROLL | win32con.WS_BORDER
-               ])
-    dlg.append([dlgStatic, "Revision:", win32ui.IDC_PROMPT2, (5,26,40,12),
-                    cs | win32con.SS_LEFT
-               ])
-    dlg.append([dlgEdit, "tip", win32ui.IDC_EDIT2, (50,25,e1w,e1h),
-                    s | win32con.ES_AUTOHSCROLL | win32con.WS_BORDER
-               ])
-    dlg.append([dlgButton,"Create local tag", win32ui.IDC_CHECK1, (50,40,100,12),
-                    s | win32con.BS_AUTOCHECKBOX
-               ])
-    #dlg.append([dlgStatic, "Commit Message:", win32ui.IDC_PROMPT3, (5,65,60,10),
-    #                cs | win32con.SS_LEFT
-    #           ])
-    dlg.append([dlgButton,"Use commit message:", win32ui.IDC_CHECK2, (5,h-e2h-5-12,100,12),
-                    s | win32con.BS_AUTOCHECKBOX
-               ])
-    dlg.append([dlgEdit, "", win32ui.IDC_EDIT3, (5,h-e2h-5,e2w,e2h),
-                    s | win32con.SS_LEFT
-                      | win32con.WS_BORDER
-                     # | win32con.ES_MULTILINE
-                     # | win32con.WS_VSCROLL
-                      | win32con.WS_HSCROLL
-                     # | win32con.ES_WANTRETURN
-                      | win32con.ES_READONLY
-               ])
-    dlg.append([dlgButton,"OK", win32con.IDOK, (w-bw-5,5,bw,bh),
-                    s | win32con.BS_PUSHBUTTON
-               ]) 
-    dlg.append([dlgButton,"Cancel", win32con.IDCANCEL, (w-bw-5,20,bw,bh),
-                    s | win32con.BS_PUSHBUTTON
-               ]) 
-    dlg.append([dlgButton,"Tags", win32ui.IDC_BUTTON1, (w-bw-5,35,bw,bh),
-                    s | win32con.BS_PUSHBUTTON
-               ]) 
-    return dlg
-
-class AddTagDialog(AppDialog): 
-    def __init__(self, path, revision="tip", title=None):
-        self.title = title
-        self.path = path
-        self.root = thgutil.find_root(path)
-        tmpl = _dlg_template()
-        AppDialog.__init__(self, tmpl)
-        self.AddDDX(win32ui.IDC_EDIT2, 'revision')
-        self.data['revision']=revision
-                
-    def OnInitDialog(self): 
-        rc = AppDialog.OnInitDialog(self)
-
-        # setup control handlers        
-        self.HookCommand(self.OnNotify, win32ui.IDC_CHECK2)
-        self.HookCommand(self.OnNotify, win32ui.IDC_BUTTON1)
-
-        # set dialog title
-        title = "hg tag - %s" % self.root
-        self.SetWindowText(title)
-
-    def OnOK(self):
-        if self._add_tag() == True:
-            AppDialog.OnOK(self)
-
-    def _add_tag(self):
-        # read input
-        name = self.GetDlgItem(win32ui.IDC_EDIT1).GetWindowText()
-        rev = self.GetDlgItem(win32ui.IDC_EDIT2).GetWindowText()
-        local = self.GetDlgItem(win32ui.IDC_CHECK1).GetCheck()
-
-        message = None        
-        if self.GetDlgItem(win32ui.IDC_CHECK2).GetCheck():
-            message = self.GetDlgItem(win32ui.IDC_EDIT3).GetWindowText()
-
-        # verify input
-        if name == "":
-            error_dialog("Please enter tag name")
-            return False
-        if rev == "":
-            error_dialog("Pleas enter revision to tag")
-            return False
-
-        # add tag to repo        
-        try:
-            self._add_hg_tag(name, rev, message, local)
-        except util.Abort, inst:
-            error_dialog("Error: %s" % inst)
-            return False
-        except:
-            error_dialog("Unknown wrror when adding tag")
-            raise
-            return False
-
-        return True
-    
-    def _add_hg_tag(self, name, revision, message, local, user=None,
-                    date=None, force=False):
-        root = thgutil.find_root(self.path)
-        u = ui.ui()
-        try:
-            repo = hg.repository(u, path=root)
-        except repo.RepoError:
-            return None
-
-        if name in repo.tags() and not force:
-            raise util.Abort(_('a tag named "%s" already exists')
-                             % name)
-        r = repo.changectx(revision).node()
-
-        if not message:
-            message = _('Added tag %s for changeset %s') % (name, short(r))
-
-        repo.tag(name, r, message, local, user, date)
-
-    def OnNotify(self, id, code):
-        if id == win32ui.IDC_CHECK2:
-            state = self.GetDlgItem(win32ui.IDC_CHECK2).GetCheck()
-            self.GetDlgItem(win32ui.IDC_EDIT3).SetReadOnly(state == False)
-        elif id == win32ui.IDC_BUTTON1:
-            import taglistdialog
-            dlg = taglistdialog.TagsDialog(self.root)
-            dlg.CreateWindow()
-
-def test(path):
-    dlg = AddTagDialog(path=path)
-    dlg.CreateWindow()
-    return dlg
-
-if __name__ == "__main__":
-    test("c:\\hg\\h1")

hgwin/taglistdialog.py

-"""
-taglistdialog.py - dialog for TortoiseHg to display repository tags
-
- Copyright (C) 2007 TK Soh <teekaysoh@gmail.com>
-
-This software may be used and distributed according to the terms
-of the GNU General Public License, incorporated herein by reference.
-"""
-
-from listdialog import ListsDialog
-from mercurial import hg, repo, ui, cmdutil, util, node
-import thgutil
-
-def get_tag_list(path):
-    root = thgutil.find_root(path)
-    u = ui.ui()
-    try:
-        repo = hg.repository(u, path=root)
-    except repo.RepoError:
-        return None
-
-    l = repo.tagslist()
-    l.reverse()
-    hexfunc = node.hex
-    taglist = []
-    for t, n in l:
-        try:
-            hn = hexfunc(n)
-            r, c = repo.changelog.rev(n), hexfunc(n)
-        except revlog.LookupError:
-            r, c = "?", hn
-
-        taglist.append((t, r, c))
-
-    return taglist
-
-headings = ['Name', 'Revision', 'Changeset']
-
-class TagsDialog(ListsDialog):
-    def __init__(self, path):
-        taglist = get_tag_list(path)
-        title = 'Hg tags - %s' % thgutil.find_root(path)
-        ListsDialog.__init__(self, title, taglist, headings, resizable=True)
-
-    # support dialog app
-    def PreDoModal(self):
-        pass
-
-def test(path):
-    dlg = TagsDialog(path)
-    dlg.CreateWindow()
-    
-if __name__=='__main__':
-    test("c:\hg\h1")
-    

hgwin/tortoisedialog.py

-#
-# front-end for TortoiseHg dialogs
-#
-# Copyright (C) 2007 TK Soh <teekaysoh@gmail.com>
-#
-
-import os
-import sys
-import getopt
-import thgutil
-from pywin.framework import dlgappcore, app
-
-class TortoiseHgDialogApp(dlgappcore.DialogApp):
-    def __init__(self):
-        dlgappcore.DialogApp.__init__(self)
-        
-    def CreateDialog(self):
-        return parse(sys.argv)
-
-app.AppBuilder = TortoiseHgDialogApp()
-
-def get_option(args):
-    long_opt_list =  ['command=', 'exepath=', 'listfile=', 'title=',
-                      'root=', 'cwd=', 'notify', 'deletelistfile']
-    opts, args = getopt.getopt(args, "c:e:l:ndt:R:", long_opt_list)
-    options = {'hgcmd': 'help', 'hgpath': 'hg'}
-    
-    for o, a in opts:
-        if o in ("-c", "--command"):
-            options['hgcmd'] = a
-        elif o in ("-l", "--listfile"):
-            options['listfile'] = a
-        elif o in ("-e", "--exepath"):
-            options['hgpath'] = a
-        elif o in ("-n", "--notify"):
-            options['notify'] = True
-        elif o in ("-t", "--title"):
-            options['title'] = a
-        elif o in ("-d", "--deletelistfile"):
-            options['rmlistfile'] = True
-        elif o in ("-R", "--root"):
-            options['root'] = a
-        elif o in ("--cwd"):
-            options['cwd'] = a
-
-    return (options, args)
-
-def get_list_from_file(filename):
-    fd = open(filename, "r")
-    lines = [ x.replace("\n", "") for x in fd.readlines() ]
-    fd.close()
-    return lines
-    
-def parse(args):
-    option, args = get_option(args)
-    
-    filelist = []
-    if option.has_key('listfile'):
-        filelist = get_list_from_file(option['listfile'])
-    if option.has_key('rmlistfile'):
-        os.unlink(option['listfile'])
-        
-    cmdline = "hg %s" % option['hgcmd']
-    if option.has_key('root'):
-        cmdline += " --repository %s" % thgutil.shellquote(option['root'])
-    if args:
-        cmdline += " %s" % " ".join([(x) for x in args])
-    if filelist:
-        cmdline += " %s" % " ".join([thgutil.shellquote(x) for x in filelist])
-                
-    opt = {}
-    if option.has_key('title'):
-        opt['title'] = option['title']
-    elif option.has_key('root'):
-        opt['title'] = "hg %s - %s" % (option['hgcmd'], option['cwd'])
-    else:
-        opt['title'] = "hg %s" % option['hgcmd']
-
-    cmd_notify = ('add', 'revert', 'merge', 'rollback')
-    if option.has_key('notify') or option['hgcmd'] in cmd_notify:
-        if filelist:
-            opt['notify_list'] = filelist
-        elif option.has_key('cwd'):
-            opt['notify_list'] = [ option['cwd'] ]
-    
-    if option['hgcmd'] == 'commit':
-        import commitdialog
-        if not filelist:
-            filelist = [option['cwd']]
-        return commitdialog.SimpleCommitDialog(cwd=option['cwd'], files=filelist)
-    elif option['hgcmd'] == 'update':
-        import updatedialog
-        if not filelist:
-            filelist = [option['root']]
-        return updatedialog.UpdateDialog(path=filelist[0])
-    elif option['hgcmd'] == 'status':
-        import statusdialog
-        return statusdialog.status_dialog(option['cwd'], files=filelist)
-    elif option['hgcmd'] == 'tags':
-        import taglistdialog
-        return taglistdialog.TagsDialog(option['root'])
-    elif option['hgcmd'] == 'tag':
-        import tagadddialog
-        return tagadddialog.AddTagDialog(option['root'])
-    else:
-        import gpopen
-        return gpopen.PopenDialog(cmdline, **opt)
-    
-if __name__=='__main__':
-    #dlg = parse(['-c', 'help', '--', '-v'])
-    #dlg = parse(['-c', 'log', '--root', 'c:\hg\h1', '--', '-l1'])
-    #dlg = parse(['-c', 'status', '--root', 'c:\hg\h1', ])
-    #dlg = parse(['-c', 'add', '--root', 'c:\hg\h1', '--listfile', 'c:\\hg\\h1\\f1', '--notify'])
-    dlg = parse(['-c', 'rollback', '--root', 'c:\\hg\\h1'])
-    dlg.CreateWindow()

hgwin/updatedialog.py

-"""
-updatedialog.py - a simple update (chekcout) dialog for TortoiseHg
-
- Copyright (C) 2007 TK Soh <teekaysoh@gmail.com>
-
-This software may be used and distributed according to the terms
-of the GNU General Public License, incorporated herein by reference.
-"""
-
-import win32ui
-import win32con
-from pywin.framework.dlgappcore import AppDialog
-from mercurial import util
-import gpopen
-import thgutil
-
-dlgStatic = 130
-dlgEdit = 129
-dlgButton = 128 
-
-def update_dlg_template():
-    style = (#win32con.DS_MODALFRAME | 
-             win32con.WS_POPUP | 
-             win32con.WS_VISIBLE | 
-             win32con.WS_CAPTION | 
-             win32con.WS_SYSMENU |
-             win32con.DS_CENTER |
-             # win32con.DS_CENTERMOUSE |
-             # win32con.WS_THICKFRAME |  # we can resize the dialog window
-             win32con.DS_SETFONT)
-
-    cs = win32con.WS_CHILD | win32con.WS_VISIBLE 
-    s = win32con.WS_TABSTOP | cs 
-
-    dlg = [["TortoiseHg", (3, 4, 219, 46), style, None, (8, "MS Sans Serif")],]
-    
-    dlg.append([dlgStatic, "Revision:", win32ui.IDC_PROMPT1, (5,8,40,12),
-                    cs | win32con.SS_LEFT
-               ])
-    dlg.append([dlgEdit, "tip", win32ui.IDC_EDIT1, (50,6,80,12),
-                    s | win32con.ES_AUTOHSCROLL | win32con.WS_BORDER
-               ])
-    dlg.append([dlgButton,"Overwrite local changes", win32ui.IDC_CHECK1, (50,25,100,12),
-                    s | win32con.BS_AUTOCHECKBOX
-               ])
-    dlg.append([dlgButton,"OK", win32con.IDOK, (171,5,40,15),
-                    s | win32con.BS_PUSHBUTTON
-               ]) 
-    dlg.append([dlgButton,"Cancel", win32con.IDCANCEL, (171,23,40,14),
-                    s | win32con.BS_PUSHBUTTON
-               ]) 
-    return dlg
-
-class UpdateDialog(AppDialog): 
-    def __init__(self, path, revision="tip", title=None, tmpl=None):
-        self.title = title
-        self.path = path
-        self.root = thgutil.find_root(path)
-        if tmpl is None:
-            tmpl = update_dlg_template()
-        AppDialog.__init__(self, tmpl)
-        self.AddDDX(win32ui.IDC_EDIT1, 'revision')
-        self.data['revision']=revision
-                
-    def OnInitDialog(self): 
-        rc = AppDialog.OnInitDialog(self)
-        title = "hg update - %s" % self.root
-        self.SetWindowText(title)
-
-        # uncheck overwrite button        
-        self.GetDlgItem(win32ui.IDC_CHECK1).SetCheck(0)
-        self.data['overwrite']=0
-
-    def OnOK(self):
-        self._do_update()
-        AppDialog.OnOK(self)
-
-    def _do_update(self):
-        rev = self.GetDlgItem(win32ui.IDC_EDIT1).GetWindowText()
-        if rev.startswith("-"):
-            rev = "-- " + rev
-        clean = self.GetDlgItem(win32ui.IDC_CHECK1).GetCheck()
-
-        cmdline = "hg --repository %s update --verbose %s %s" % (
-                        util.shellquote(self.root),
-                        clean and "--clean" or "",
-                        rev)
-        gpopen.run(cmdline, modal=True)
-
-def do_update(path, title="Hg update"):
-    dlg = UpdateDialog(path=path)
-    dlg.CreateWindow()
-    return dlg
-
-if __name__ == "__main__":
-    do_update("D:\\Profiles\\r28629\\My Documents\\Mercurial\\repos\\c1")
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.