diff --git a/ApplicationServices/Terminal/ProgressBar/ProgressBar.vb b/ApplicationServices/Terminal/ProgressBar/ProgressBar.vb index 05bf68e1..a9e132b0 100644 --- a/ApplicationServices/Terminal/ProgressBar/ProgressBar.vb +++ b/ApplicationServices/Terminal/ProgressBar/ProgressBar.vb @@ -195,10 +195,10 @@ Namespace Terminal.ProgressBar Me.y = Y If Not disabled Then - AddHandler TerminalEvents.Resize, AddressOf __resize + AddHandler TerminalEvents.Resize, AddressOf consoleWindowResize Try - Call __resize(Nothing, Nothing) + Call consoleWindowResize(Nothing, Nothing) Catch ex As Exception End Try @@ -214,7 +214,7 @@ Namespace Terminal.ProgressBar Call Me.New(title, Y:=Console.CursorTop, CLS:=False) End Sub - Private Sub __resize(size As Size, old As Size) + Private Sub consoleWindowResize(size As Size, old As Size) Console.ResetColor() Console.SetCursorPosition(0, y) Console.BackgroundColor = ConsoleColor.DarkCyan @@ -270,7 +270,7 @@ Namespace Terminal.ProgressBar ''' ''' ''' - Private Sub __tick(p%, details$) + Private Sub tick(p%, details$) Console.BackgroundColor = ConsoleColor.Yellow ' /运算返回完整的商,包括余数,SetCursorPosition会自动四舍五入 Dim cx As Integer = p * (Console.WindowWidth - 2) / 100 @@ -278,7 +278,7 @@ Namespace Terminal.ProgressBar Console.SetCursorPosition(0, y) If p < current Then - Call __resize(Nothing, Nothing) + Call consoleWindowResize(Nothing, Nothing) End If For i As Integer = 0 To cx @@ -306,7 +306,7 @@ Namespace Terminal.ProgressBar current = percent If Not disabled Then - Call __tick(current, details) + Call tick(current, details) End If End Sub @@ -319,7 +319,7 @@ Namespace Terminal.ProgressBar If disposing Then If Not disabled Then ' TODO: dispose managed state (managed objects). - RemoveHandler TerminalEvents.Resize, AddressOf __resize + RemoveHandler TerminalEvents.Resize, AddressOf consoleWindowResize End If Call timer.Stop() diff --git a/ApplicationServices/Terminal/ProgressBar/SwayBar.vb b/ApplicationServices/Terminal/ProgressBar/SwayBar.vb index b507acb7..0f05c627 100644 --- a/ApplicationServices/Terminal/ProgressBar/SwayBar.vb +++ b/ApplicationServices/Terminal/ProgressBar/SwayBar.vb @@ -59,33 +59,38 @@ Namespace Terminal.ProgressBar Public Class SwayBar : Inherits AbstractBar - Private bar As String - Private pointer As String - Private _blankPointer As String - Private counter As Integer - Private currdir As direction + Dim bar As String + Dim pointer As String + Dim blankPointer As String + Dim counter As Integer + Dim currdir As direction + Private Enum direction right left End Enum + Public Sub New() MyBase.New() - Me.bar = "| |" - Me.pointer = "***" - Me._blankPointer = Me.BlankPointer() - Me.currdir = direction.right - Me.counter = 1 + + bar = "| |" + pointer = "***" + blankPointer = buildBlankPointer() + currdir = direction.right + counter = 1 End Sub ''' ''' sets the atribute blankPointer with a empty string the same length that the pointer ''' ''' A string filled with space characters - Private Function BlankPointer() As String + Private Function buildBlankPointer() As String Dim blank As New StringBuilder() - For cont As Integer = 0 To Me.pointer.Length - 1 + + For cont As Integer = 0 To pointer.Length - 1 blank.Append(" ") Next + Return blank.ToString() End Function @@ -93,7 +98,7 @@ Namespace Terminal.ProgressBar ''' reset the bar to its original state ''' Private Sub ClearBar() - Me.bar = Me.bar.Replace(Me.pointer, Me._blankPointer) + bar = bar.Replace(pointer, blankPointer) End Sub ''' @@ -102,29 +107,33 @@ Namespace Terminal.ProgressBar ''' start index ''' end index Private Sub PlacePointer(start As Integer, [end] As Integer) - Me.ClearBar() - Me.bar = Me.bar.Remove(start, [end]) - Me.bar = Me.bar.Insert(start, Me.pointer) + Call ClearBar() + + bar = bar.Remove(start, [end]) + bar = bar.Insert(start, pointer) End Sub ''' ''' prints the progress bar acorrding to pointers and current direction ''' Public Overrides Sub [Step]() - If Me.currdir = direction.right Then - Me.PlacePointer(counter, Me.pointer.Length) - Me.counter += 1 - If Me.counter + Me.pointer.Length = Me.bar.Length Then - Me.currdir = direction.left + If currdir = direction.right Then + PlacePointer(counter, pointer.Length) + counter += 1 + + If counter + pointer.Length = bar.Length Then + currdir = direction.left End If Else - Me.PlacePointer(counter - Me.pointer.Length, Me.pointer.Length) - Me.counter -= 1 - If Me.counter = Me.pointer.Length Then - Me.currdir = direction.right + PlacePointer(counter - pointer.Length, pointer.Length) + counter -= 1 + + If counter = pointer.Length Then + currdir = direction.right End If End If - Console.Write(Me.bar & vbCr) + + Call Console.Write(bar & vbCr) End Sub End Class End Namespace diff --git a/ApplicationServices/Tools/WinForm/Extensions.vb b/ApplicationServices/Tools/WinForm/Extensions.vb index 01efa903..a0edb8a1 100644 --- a/ApplicationServices/Tools/WinForm/Extensions.vb +++ b/ApplicationServices/Tools/WinForm/Extensions.vb @@ -1,54 +1,110 @@ #Region "Microsoft.VisualBasic::b0d6b9f9fff39c2db1dd7121d7223ca9, Microsoft.VisualBasic.Core\ApplicationServices\Tools\WinForm\Extensions.vb" - ' Author: - ' - ' asuka (amethyst.asuka@gcmodeller.org) - ' xie (genetics@smrucc.org) - ' xieguigang (xie.guigang@live.com) - ' - ' Copyright (c) 2018 GPL3 Licensed - ' - ' - ' GNU GENERAL PUBLIC LICENSE (GPL3) - ' - ' - ' This program is free software: you can redistribute it and/or modify - ' it under the terms of the GNU General Public License as published by - ' the Free Software Foundation, either version 3 of the License, or - ' (at your option) any later version. - ' - ' This program is distributed in the hope that it will be useful, - ' but WITHOUT ANY WARRANTY; without even the implied warranty of - ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ' GNU General Public License for more details. - ' - ' You should have received a copy of the GNU General Public License - ' along with this program. If not, see . +' Author: +' +' asuka (amethyst.asuka@gcmodeller.org) +' xie (genetics@smrucc.org) +' xieguigang (xie.guigang@live.com) +' +' Copyright (c) 2018 GPL3 Licensed +' +' +' GNU GENERAL PUBLIC LICENSE (GPL3) +' +' +' This program is free software: you can redistribute it and/or modify +' it under the terms of the GNU General Public License as published by +' the Free Software Foundation, either version 3 of the License, or +' (at your option) any later version. +' +' This program is distributed in the hope that it will be useful, +' but WITHOUT ANY WARRANTY; without even the implied warranty of +' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +' GNU General Public License for more details. +' +' You should have received a copy of the GNU General Public License +' along with this program. If not, see . - ' /********************************************************************************/ +' /********************************************************************************/ - ' Summaries: +' Summaries: - ' Module Extensions - ' - ' Function: AddFilesHistory - ' - ' Sub: AddFileHistory, AddRowData, Clear, WriteLine - ' - ' - ' /********************************************************************************/ +' Module Extensions +' +' Function: AddFilesHistory +' +' Sub: AddFileHistory, AddRowData, Clear, WriteLine +' +' +' /********************************************************************************/ #End Region Imports System.Runtime.CompilerServices Imports Microsoft.VisualBasic.Linq +Imports Keyboard = System.Windows.Forms.Keys Namespace Windows.Forms Public Module Extensions + ReadOnly chars As New Dictionary(Of Keys, Char) + + + Public Function IsPrintableCharacter(key As Keys) As Boolean + Return chars.ContainsKey(key) + End Function + + + Public Function ToChar(key As Keys) As Char + If Not key.IsPrintableCharacter Then + Return Nothing + Else + Return chars(key) + End If + End Function + + Sub New() + chars(Keyboard.A) = "a" + chars(Keyboard.B) = "b" + chars(Keyboard.C) = "c" + chars(Keyboard.D) = "d" + chars(Keyboard.E) = "e" + chars(Keyboard.F) = "f" + chars(Keyboard.G) = "g" + chars(Keyboard.H) = "h" + chars(Keyboard.I) = "i" + chars(Keyboard.J) = "j" + chars(Keyboard.K) = "k" + chars(Keyboard.L) = "l" + chars(Keyboard.M) = "m" + chars(Keyboard.N) = "n" + chars(Keyboard.O) = "o" + chars(Keyboard.P) = "p" + chars(Keyboard.Q) = "q" + chars(Keyboard.R) = "r" + chars(Keyboard.S) = "s" + chars(Keyboard.T) = "t" + chars(Keyboard.U) = "u" + chars(Keyboard.V) = "v" + chars(Keyboard.W) = "w" + chars(Keyboard.X) = "x" + chars(Keyboard.Y) = "y" + chars(Keyboard.Z) = "z" + chars(Keyboard.D0) = "0" : chars(Keyboard.NumPad0) = "0" + chars(Keyboard.D0) = "1" : chars(Keyboard.NumPad0) = "1" + chars(Keyboard.D0) = "2" : chars(Keyboard.NumPad0) = "2" + chars(Keyboard.D0) = "3" : chars(Keyboard.NumPad0) = "3" + chars(Keyboard.D0) = "4" : chars(Keyboard.NumPad0) = "4" + chars(Keyboard.D0) = "5" : chars(Keyboard.NumPad0) = "5" + chars(Keyboard.D0) = "6" : chars(Keyboard.NumPad0) = "6" + chars(Keyboard.D0) = "7" : chars(Keyboard.NumPad0) = "7" + chars(Keyboard.D0) = "8" : chars(Keyboard.NumPad0) = "8" + chars(Keyboard.D0) = "9" : chars(Keyboard.NumPad0) = "9" + End Sub + Public Sub AddRowData(view As DataGridView, name$, ParamArray values As Object()) Call view.Rows.Add(values) diff --git a/ApplicationServices/Tools/WinForm/MockForm.vb b/ApplicationServices/Tools/WinForm/MockForm.vb index 27a03794..470c1f9d 100644 --- a/ApplicationServices/Tools/WinForm/MockForm.vb +++ b/ApplicationServices/Tools/WinForm/MockForm.vb @@ -128,25 +128,29 @@ Namespace Windows.Forms Dim parent As Control Sub New(parent As Control) - Call MyBase.New(__cmd) - Me.parent = parent - __init() + Call MyBase.New(getCmd) + Call init(parent) End Sub ''' ''' Init by win32 API ''' - Private Sub __init() - SetParent(hwnd, parent.Handle) ' 直接嵌套到TabPage1内 - SetWindowLong(hwnd, (-16), GetWindowLong(hwnd, (-16)) And (Not WS_CAPTION) And (Not WS_VSCROLL) And (Not WS_HSCROLL)) ' 设置窗体样式 - SetWindowPos(parent.Handle, -1, 100, 100, 100, 100, SWP_SHOWWINDOW) ' 改变子窗体位置 + Private Sub init(parent As Control) + ' 直接嵌套到TabPage1内 + SetParent(hwnd, parent.Handle) + ' 设置窗体样式 + SetWindowLong(hwnd, (-16), GetWindowLong(hwnd, (-16)) And (Not WS_CAPTION) And (Not WS_VSCROLL) And (Not WS_HSCROLL)) + ' 改变子窗体位置 + SetWindowPos(parent.Handle, -1, 100, 100, 100, 100, SWP_SHOWWINDOW) + + Me.parent = parent End Sub ''' ''' Start a new cmd.exe instance for the terminal mock ''' ''' - Private Shared Function __cmd() As String + Private Shared Function getCmd() As String Call Process.Start("cmd.exe") Call Thread.Sleep(18) ' 过快下面的FindWindow有可能找不到窗体 Return "c:\windows\system32\cmd.exe"