~ubuntu-branches/ubuntu/quantal/griffith/quantal

« back to all changes in this revision

Viewing changes to lib/macutils.py

  • Committer: Package Import Robot
  • Author(s): Piotr Ożarowski
  • Date: 2011-12-18 21:15:25 UTC
  • mfrom: (1.1.17) (3.1.11 sid)
  • Revision ID: package-import@ubuntu.com-20111218211525-endbgt82m3jh9gde
Tags: 0.13-1
* New upstream release
* VCS-* fields removed (berlios will be shutdown)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: UTF-8 -*-
 
2
 
 
3
__revision__ = '$Id: macutils.py 1519 2011-02-05 15:32:36Z iznogoud $'
 
4
 
 
5
# Copyright (c) 2005-2011 Vasco Nunes, Piotr Ożarowski
 
6
#
 
7
# This program is free software; you can redistribute it and/or modify
 
8
# it under the terms of the GNU General Public License as published by
 
9
# the Free Software Foundation; either version 2 of the License, or
 
10
# (at your option) any later version.
 
11
#
 
12
# This program is distributed in the hope that it will be useful,
 
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
# GNU Library General Public License for more details.
 
16
#
 
17
# You should have received a copy of the GNU General Public License
 
18
# along with this program; if not, write to the Free Software
 
19
# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 
20
 
 
21
# You may use and distribute this software under the terms of the
 
22
# GNU General Public License, version 2 or later
 
23
 
 
24
from Cocoa import *
 
25
 
 
26
# ================
 
27
# Save file dialog
 
28
# ================
 
29
 
 
30
def saveDialog(filetypes=[]):
 
31
    panel = NSSavePanel.savePanel()
 
32
    panel.setCanCreateDirectories_(True)
 
33
    panel.setCanChooseDirectories_(False)
 
34
    panel.setCanChooseFiles_(True)
 
35
    panel.setAllowsOtherFileTypes_(False)
 
36
    result = panel.runModalForDirectory_file_types_(
 
37
        NSHomeDirectory() + '/Desktop',None,filetypes)
 
38
    if result:
 
39
        return True, panel.filename(), panel.directory()
 
40
    else:
 
41
        return False, None, None
 
42
    return
 
43
    
 
44
# ================
 
45
# Open file dialog
 
46
# ================
 
47
 
 
48
def openDialog(filetypes=[]):
 
49
    panel = NSOpenPanel.openPanel()
 
50
    panel.setCanCreateDirectories_(False)
 
51
    panel.setCanChooseDirectories_(False)
 
52
    panel.setCanChooseFiles_(True)
 
53
    result = panel.runModalForDirectory_file_types_(
 
54
        NSHomeDirectory() + '/Desktop',None,filetypes)
 
55
    if result:
 
56
        return True, panel.filename(), panel.directory()
 
57
    else:
 
58
        return False, None, None
 
59
    return
 
60
    
 
61
# ================
 
62
# Alert dialog
 
63
# ================  
 
64
    
 
65
def createAlert(msg):
 
66
    alert = NSAlert.alloc().init()
 
67
    alert.setMessageText_(msg)
 
68
    alert.setInformativeText_("")
 
69
    alert.setAlertStyle_(NSInformationalAlertStyle)
 
70
    alert.runModal()
 
71
        
 
72
# ================
 
73
# Question dialog
 
74
# ================
 
75
        
 
76
def question(msg, window=None):
 
77
    alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
 
78
        msg, "Yes", "No", None, "")
 
79
    buttonPressed=alert.runModal()
 
80
    if buttonPressed == 0:
 
81
        return False
 
82
    else:
 
83
        return True
 
 
b'\\ No newline at end of file'