1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
|
# Copyright 2004-2024 Tom Rothamel <pytom@bishoujo.us>
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation files
# (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
from __future__ import division, absolute_import, with_statement, print_function, unicode_literals
"""
This contains a wrapper for the tinyfiledialogs library. It's intended for use
in the launcher, and so may go away in some future Ren'Py version.
"""
cdef extern from "tinyfiledialogs/tinyfiledialogs.h":
int tinyfd_notifyPopup(
const char* aTitle,
const char *aMessage,
const char *aIconType)
int tinyfd_messageBox(
const char *aTitle,
const char *aMessage,
const char *aDialogType,
const char *aIconType,
int aDefaultButton)
char * tinyfd_inputBox(
const char *aTitle,
const char *aMessage,
const char *aDefaultInput)
char * tinyfd_saveFileDialog(
const char *aTitle,
const char *aDefaultPathAndFile,
int aNumOfFilterPatterns,
const char *const * aFilterPatterns,
const char *aSingleFilterDescription)
char * tinyfd_openFileDialog(
const char *aTitle,
const char *aDefaultPathAndFile,
int aNumOfFilterPatterns,
const char *const * aFilterPatterns,
const char *aSingleFilterDescription,
int aAllowMultipleSelects)
char * tinyfd_selectFolderDialog(
const char *aTitle,
const char *aDefaultPath)
char * tinyfd_colorChooser(
const char *aTitle,
const char *aDefaultHexRGB,
const unsigned char *aDefaultRGB,
const unsigned char *aoResultRGB)
def encode(s):
if s is None:
return None
else:
return s.encode("utf-8")
cdef const char *cstr_or_null(s):
if s is None:
return NULL
else:
return s
encoded_filters = [ ]
cdef const char *encoded_filter_array[32]
cdef const char **filter_array(l):
global encoded_filters
encoded_filters = [ i.encode("utf-8") for i in l ]
for i, b in enumerate(encoded_filters):
encoded_filter_array[i] = b
return encoded_filter_array
def notifyPopup(title, message, icon):
"""
Causes a notification popup to be displayed.
`title`
The title of the popup. May be None for no title.
`message`
The message of the popup. May be None for no message, and may contain tab and newline
characters.
`icon`
One of "info", "warning", or "error".
"""
title = encode(title)
message = encode(message)
icon = encode(icon)
return tinyfd_notifyPopup(cstr_or_null(title), cstr_or_null(message), icon.encode)
def messageBox(title, message, dialogtype, icon, defaultbutton):
"""
Causes a message box to be displayed.
`title`
The title of the message box. May be None for no title.
`message`
The message of the message box. May be None for no message, and may contain tab and newline
characters.
`dialogtype`
One of "ok", "okcancel", "yesno", or "yesnocancel".
`icon`
One of "info", "warning", "error", or "question".
`defaultbutton`
0 for no/cancel, 1 for ok/yes, 2 for no in "yesnocancel".
Returns 0 for no/cancel, 1 for ok/yes, 2 for no in "yesnocancel".
"""
title = encode(title)
message = encode(message)
dialogtype = encode(dialogtype)
icon = encode(icon)
return tinyfd_messageBox(cstr_or_null(title), cstr_or_null(message), dialogtype, icon, defaultbutton)
def inputBox(title, message, defaultinput=""):
"""
Displays an inputbox, to prompt for textual input.
`title`
The title of the input box. May be None for no title.
`message`
The message of the input box. May be none of no message, does not understand
tab and newline.
`defaultinput`
The default input string. If None, a password input is used.
Returns the input string, or None if the user cancelled the dialog.
"""
title = encode(title)
message = encode(message)
defaultinput = encode(defaultinput)
cdef char *rv
rv = tinyfd_inputBox(cstr_or_null(title), cstr_or_null(message), cstr_or_null(defaultinput))
if rv == NULL:
return None
else:
return rv.decode("utf-8")
def saveFileDialog(title, defaultPathAndFile, filters, singleFilterDescription):
"""
Displays a save file dialog.
`title`
The title of the dialog. May be None for no title.
`defaultPathAndFile`
The default path and file name. May be None for no default.
`filters`
A list of file filters. Each filter is a list of strings. The first
string is a description of the filter. The other strings are file
extensions.
`singleFilterDescription`
A description of the single file filter. May be None for no single file filter.
Returns the path and file name of the selected file, or None if the user cancelled the dialog.
"""
title = encode(title)
defaultPathAndFile = encode(defaultPathAndFile)
singleFilterDescription = encode(singleFilterDescription)
cdef char *rv
rv = tinyfd_saveFileDialog(cstr_or_null(title), cstr_or_null(defaultPathAndFile), len(filters), filter_array(filters), cstr_or_null(singleFilterDescription))
if rv == NULL:
return None
else:
return rv.decode("utf-8")
def openFileDialog(title, defaultPathAndFile, filters, singleFilterDescription, allowMultipleSelects=False):
"""
Displays a save file dialog.
`title`
The title of the dialog. May be None for no title.
`defaultPathAndFile`
The default path and file name. May be None for no default.
`filters`
A list of file filters. Each filter is a list of strings. The first
string is a description of the filter. The other strings are file
extensions.
`singleFilterDescription`
A description of the single file filter. May be None for no single file filter.
`allowMultipleSelects`
True for allowing multiple file selections.
Returns a list of the paths and file names of the selected files, or None if the user cancelled the dialog.
"""
title = encode(title)
defaultPathAndFile = encode(defaultPathAndFile)
singleFilterDescription = encode(singleFilterDescription)
cdef char *rv
rv = tinyfd_openFileDialog(cstr_or_null(title), cstr_or_null(defaultPathAndFile), len(filters), filter_array(filters), cstr_or_null(singleFilterDescription), allowMultipleSelects)
if rv == NULL:
return None
else:
return rv.decode("utf-8")
def selectFolderDialog(title, defaultPath):
"""
Displays a select folder dialog.
`title`
The title of the dialog. May be None for no title.
`defaultPath`
The default path. May be None for no default.
Returns None on cancel, otherwise the path of the selected directory.
"""
title = encode(title)
defaultPath = encode(defaultPath)
cdef char *rv
rv = tinyfd_selectFolderDialog(cstr_or_null(title), cstr_or_null(defaultPath))
if rv == NULL:
return None
else:
return rv.decode("utf-8")
def colorChooser(title, initialColor=None):
"""
Displays a color chooser dialog.
`title`
The title of the dialog. May be None for no title.
`initialColor`
The initial color, a string in the form "#ff0000". May be None for no initial color.
Returns the selected color, or None if the user cancelled the dialog.
"""
title = encode(title)
initialColor = encode(initialColor)
cdef char *rv
cdef unsigned char rgb[3]
rgb[0] = 0
rgb[1] = 0
rgb[2] = 0
rv = tinyfd_colorChooser(cstr_or_null(title), cstr_or_null(initialColor), rgb, rgb)
if rv == NULL:
return None
else:
return rv.decode("utf-8")
|