src/tinydialogs

Source   Edit  

Tiny file dialogs v3.8.8 Nim bindings.

Example

import std/os
import tinydialogs

beep()
notifyPopup("Message", "You just received a message from Beef", Info)
echo messageBox("Hey", "Do you want to receive more notifications?", YesNo, Question, Yes)
echo inputBox("Name", "Please enter your password :]", "")
echo saveFileDialog("Save the file", getCurrentDir() / "\0", ["*.txt", "*.text"], "Text file") # "\0" for an emtpy file
echo openFileDialog("Open the file", getCurrentDir() / "\0", ["*.txt", "*.text"], "Text file")
echo openMultipleFilesDialog("Open the files", getCurrentDir() / "\0") # No fiilter = Any file
echo selectFolderDialog("Open the directory of the file", getCurrentDir())
echo colorChooser("Choose a color")
echo colorChooser("Choose a color", "#000000") # Hex
echo colorChooser("Choose a color", [0u8, 0u8, 0u8]) # RGB

Types

Button = enum
  Cancel,                   ## Cancel/No
  Yes,                      ## Ok/Yes
  No                         ## No in DialogType.YesNoCancel
Source   Edit  
DialogType = enum
  Ok = "ok", OkCancel = "okcancel", YesNo = "yesno", YesNoCancel = "yesnocancel"
Source   Edit  
IconType = enum
  Info = "info", Warning = "warning", Error = "error", Question = "question" ## Question only works in the message box.
Source   Edit  

Procs

proc beep() {....raises: [], tags: [], forbids: [].}
A beep sound. Source   Edit  
proc colorChooser(title = ""; defaultHexRGB = ""): tuple[hex: string,
    rgb: array[3, byte]] {....raises: [], tags: [], forbids: [].}
Returns ("", [0u8, 0u8, 0u8]) when no color is selected. Source   Edit  
proc colorChooser(title: string; defaultRGB: array[3, byte]): tuple[hex: string,
    rgb: array[3, byte]] {....raises: [], tags: [], forbids: [].}
Returns ("", [0u8, 0u8, 0u8]) when no color is selected. Source   Edit  
proc inputBox(title, message, defaultInput: string): string {....raises: [],
    tags: [], forbids: [].}

\n\t have no effect in message.

Use "" in defaultInput for a password box or something else for an input box. (#1 related)

Source   Edit  
proc messageBox(title, message: string; dialogType: DialogType;
                iconType: IconType; defaultButton: Button): Button {....raises: [],
    tags: [], forbids: [].}
message may contain \n\t. Returns the clicked Button. Source   Edit  
proc notifyPopup(title, message: string; iconType: IconType) {....raises: [],
    tags: [], forbids: [].}
message may contain \n\t. Source   Edit  
proc openFileDialog(title, defaultPath: string;
                    filterPatterns: openArray[string] = [];
                    singleFilterDescription = ""): string {....raises: [],
    tags: [], forbids: [].}

Returns the selected file (or an empty string when cancelled).

For an empty defaultPath use a trailing slash as in dir/ (or using std/os "dir" / "\0").

Example of filterPatterns: ["*.txt", "*.text"].

singleFilterDescriptor is the text to show instead of filterPatterns. Note: tinyfiledialogs at the moment only supports one filter.

Source   Edit  
proc openMultipleFilesDialog(title, defaultPath: string;
                             filterPatterns: openArray[string] = [];
                             singleFilterDescription = ""): seq[string] {.
    ...raises: [], tags: [], forbids: [].}

Returns the selected files (or empty string when cancelled).

For an empty defaultPath use a trailing slash as in dir/ (or using std/os "dir" / "\0").

Example of filterPatterns: ["*.txt", "*.text"].

singleFilterDescriptor is the text to show instead of filterPatterns. Note: tinyfiledialogs at the moment only supports one filter.

Source   Edit  
proc saveFileDialog(title, defaultPath: string;
                    filterPatterns: openArray[string] = [];
                    singleFilterDescription = ""): string {....raises: [],
    tags: [], forbids: [].}

Returns the selected file (or an empty string when cancelled).

For an empty defaultPath use a trailing slash as in dir/ (or using std/os "dir" / "\0").

Example of filterPatterns: ["*.txt", "*.text"].

singleFilterDescriptor is the text to show instead of filterPatterns. Note: tinyfiledialogs at the moment only supports one filter.

Source   Edit  
proc selectFolderDialog(title, defaultPath: string): string {....raises: [],
    tags: [], forbids: [].}
Returns the selected folder (or empty when cancelled). Source   Edit