Skip to content

Instantly share code, notes, and snippets.

@robmccormack
Created August 22, 2013 17:57
Show Gist options
  • Save robmccormack/6310595 to your computer and use it in GitHub Desktop.
Save robmccormack/6310595 to your computer and use it in GitHub Desktop.
tp_ok_cancel_dialog.py
import sublime
import sublime_plugin
import calendar
import webbrowser
# run this with at the Python console with:
# view.run_command("ok_cancel_dialog")
class OkCancelDialogCommand(sublime_plugin.TextCommand):
"test of sublime.ok_cancel_dialog"
def run(self, edit):
if sublime.ok_cancel_dialog("Press OK to see the Creativity Generator", "OKY"):
# Esc key will be taken as a Cancel
# this has two buttnos, Cancel and OK (default) we use OkyDoky
webbrowser.open_new_tab('http://creativitygenerator.com/')
return
else:
print ("You Pressed Cancel")
# ??? rob, maybe do these separately for clarit, I think it need the return above or dialo doesn't close
if sublime.ok_cancel_dialog("Do you want to see a calendar", "OK - Show me the dates"):
# print will print to console
print ("You Pressed OK") # this will print to console if OK pressed.
print calendar.prcal(2013)
else:
print ("You Pressed Cancel")
# ok_cancel_dialog(string, <ok_button>) bool
# Displays an ok / cancel question dialog to the user.
# If ok_button is provided, this may be used as the text on the ok button.
# Returns True if the user presses the ok button.
# https://www.sublimetext.com/docs/3/api_reference.html
# Calendar ref: http://www.tutorialspoint.com/python/python_date_time.htm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment