-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgnc_file.py
More file actions
126 lines (73 loc) · 3.1 KB
/
gnc_file.py
File metadata and controls
126 lines (73 loc) · 3.1 KB
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
import sys
#import gi
#gi.require_version('Gtk', '2.0')
from gi.repository import Gtk
import pdb
# define a function equivalent to N_ for internationalization
def N_(msg):
return msg
class GncFileDialog(object):
GNC_FILE_DIALOG_OPEN = 0
GNC_FILE_DIALOG_IMPORT = 1
GNC_FILE_DIALOG_SAVE = 2
GNC_FILE_DIALOG_EXPORT = 3
def __init__ (self):
pass
def gnc_gtk_dialog_add_button (self, dialog, label, stock_id, response):
button = Gtk.Button(label=label)
if stock_id:
image = Gtk.Image()
image.set_from_stock(stock_id, Gtk.IconSize.BUTTON)
button.set_image(image)
button.set_property("can-default", True)
button.show_all()
dialog.add_action_widget(button, response)
def gnc_file_dialog (self, parent, title, filters, starting_dir, dialog_type):
okbutton = Gtk.STOCK_OPEN
ok_icon = None
action = Gtk.FileChooserAction.OPEN
if dialog_type == GncFileDialog.GNC_FILE_DIALOG_OPEN:
action = Gtk.FileChooserAction.OPEN
okbutton = Gtk.STOCK_OPEN
if title == None:
title = N_("Open")
elif dialog_type == GncFileDialog.GNC_FILE_DIALOG_IMPORT:
action = Gtk.FileChooserAction.OPEN
okbutton = N_("_Import")
if title == None:
title = N_("Import")
elif dialog_type == GncFileDialog.GNC_FILE_DIALOG_SAVE:
action = Gtk.FileChooserAction.SAVE
okbutton = Gtk.STOCK_SAVE
if title == None:
title = N_("Save")
elif dialog_type == GncFileDialog.GNC_FILE_DIALOG_EXPORT:
action = Gtk.FileChooserAction.SAVE
okbutton = N_("_Export")
ok_icon = Gtk.STOCK_CONVERT
if title == None:
title = N_("Export")
print("doing dialog type",dialog_type,okbutton, file=sys.stderr)
#file_box = Gtk.FileChooserDialog(title=title, parent=None, action=action, buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL), backend=None)
#file_box = Gtk.FileChooserDialog(title=title, parent=None, action=action, buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL))
file_box = Gtk.FileChooserDialog(title=title, parent=parent, action=action, buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL))
if ok_icon:
self.gnc_gtk_dialog_add_button(file_box, okbutton, ok_icon, Gtk.ResponseType.ACCEPT)
else:
file_box.add_button(okbutton, Gtk.ResponseType.ACCEPT)
if starting_dir:
file_box.set_current_folder(starting_dir)
file_box.set_modal(True)
if filters != None:
pass
response = file_box.run()
file_name = ""
if response == Gtk.ResponseType.ACCEPT:
internal_name = file_box.get_uri()
if internal_name.startswith("file://"):
internal_name = file_box.get_filename()
file_name = internal_name
file_box.destroy()
if file_name == "":
file_name = "(null)"
return file_name