1 # sced (SuperCollider mode for gedit)
3 # Copyright 2012 Jakob Leben
4 # Copyright 2009 Artem Popov and other contributors (see AUTHORS)
6 # sced is free software:
7 # 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 3 of the License, or
10 # (at your option) any later version.
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 General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 from Settings
import Settings
24 def on_pref_widget_notify_sensitive(widget
, spec
):
25 label
= widget
.get_data("pref-label")
27 label
.set_sensitive(widget
.props
.sensitive
)
29 # FIXME: implement custom widget (or custom widget sequence) as well
30 def create_pref_section(title
, wlabels
=[], custom
=[]):
31 vbox
= gtk
.VBox(spacing
=6)
33 label
= gobject
.new(gtk
.Label
, label
="<b>%s</b>" % title
,
36 vbox
.pack_start(label
, expand
=False)
39 align
= gobject
.new(gtk
.Alignment
, left_padding
=12)
40 vbox
.pack_start(align
, expand
=False)
43 table
= gobject
.new(gtk
.Table
,
44 n_rows
=len(wlabels
) + len(custom
),
51 for i
in range(len(wlabels
)):
52 l
, widget
= wlabels
[i
]
53 label
= gobject
.new(gtk
.Label
, label
=l
, xalign
=0)
54 widget
.connect("notify::sensitive", on_pref_widget_notify_sensitive
)
55 widget
.set_data("pref-label", label
)
58 table
.attach(label
, 0, 1, i
, i
+ 1,
59 xoptions
=gtk
.FILL
, yoptions
=gtk
.FILL
)
60 table
.attach(widget
, 1, 2, i
, i
+ 1,
61 xoptions
=gtk
.EXPAND | gtk
.FILL
, yoptions
=gtk
.FILL
)
63 table
.attach(widget
, 0, 2, i
, i
+ 1,
64 xoptions
=gtk
.EXPAND | gtk
.FILL
, yoptions
=gtk
.FILL
)
69 # FIXME: fix notification
70 class ConfigurationDialog(gtk
.Dialog
):
72 "response": "override",
74 def __init__(self
, plugin
):
75 gtk
.Dialog
.__init
__(self
, title
=_("Sced configuration"),
76 flags
=gtk
.DIALOG_MODAL | gtk
.DIALOG_DESTROY_WITH_PARENT
,
78 gtk
.STOCK_CANCEL
, gtk
.RESPONSE_REJECT
,
79 gtk
.STOCK_OK
, gtk
.RESPONSE_ACCEPT
81 self
.set_default_response(gtk
.RESPONSE_ACCEPT
)
83 self
.__settings
= plugin
.settings()
85 self
.__create
_page
_general
()
87 def __create_filesystem_entry( self
, chooser
, action
, stock
= gtk
.STOCK_OPEN
):
89 btn
= gtk
.Button(stock
=stock
)
95 chooser
.set_action(action
)
96 chooser
.set_filename(entry
.get_text())
97 response
= chooser
.run()
99 if response
== gtk
.RESPONSE_ACCEPT
:
100 entry
.set_text(chooser
.get_filename())
102 btn
.connect("clicked", run_dialog
)
108 def __create_page_general(self
):
110 chooser
= gtk
.FileChooserDialog(
112 title
= "Choose interpreter program",
114 gtk
.STOCK_CANCEL
, gtk
.RESPONSE_REJECT
,
115 gtk
.STOCK_OK
, gtk
.RESPONSE_ACCEPT
118 chooser
.set_select_multiple(False)
120 sc_dir_view
, sc_dir_entry
= self
.__create
_filesystem
_entry
(
122 gtk
.FILE_CHOOSER_ACTION_SELECT_FOLDER
)
124 adv_view
= gtk
.CheckButton()
126 cmd_view
, cmd_entry
= self
.__create
_filesystem
_entry
(
128 gtk
.FILE_CHOOSER_ACTION_OPEN
)
130 wd_view
, wd_entry
= self
.__create
_filesystem
_entry
(
132 gtk
.FILE_CHOOSER_ACTION_SELECT_FOLDER
)
134 def toggle_advanced(advanced
):
135 sc_dir_view
.set_sensitive(not advanced
)
136 cmd_view
.set_sensitive(advanced
)
137 wd_view
.set_sensitive(advanced
)
139 adv_view
.connect("toggled", lambda btn
: toggle_advanced(btn
.get_active()) )
142 sets
= self
.__settings
143 if sets
.sc_dir
is not None:
144 sc_dir_entry
.set_text(sets
.sc_dir
)
145 adv_view
.set_active(sets
.advanced
is True)
146 if sets
.sclang_cmd
is not None:
147 cmd_entry
.set_text(sets
.sclang_cmd
)
148 if sets
.sclang_work_dir
is not None:
149 wd_entry
.set_text(sets
.sclang_work_dir
)
150 toggle_advanced(sets
.advanced
is True)
152 self
.__adv
_check
= adv_view
153 self
.__sc
_dir
_entry
= sc_dir_entry
154 self
.__cmd
_entry
= cmd_entry
155 self
.__wd
_entry
= wd_entry
158 section
= create_pref_section("Basic", [
159 ("SuperCollider folder:", sc_dir_view
),
160 ("Advanced settings:", adv_view
),
162 section
.props
.border_width
= 12
163 self
.vbox
.add(section
)
165 section
= create_pref_section("Interpreter options", [
166 ("Command:", cmd_view
),
167 ("Runtime folder:", wd_view
)
169 section
.props
.border_width
= 12
170 self
.vbox
.add(section
)
173 def do_response(self
, response
):
174 if response
== gtk
.RESPONSE_ACCEPT
:
175 sets
= self
.__settings
176 sets
.sc_dir
= self
.__sc
_dir
_entry
.get_text()
177 sets
.advanced
= self
.__adv
_check
.get_active()
178 sets
.sclang_work_dir
= self
.__wd
_entry
.get_text()
179 sets
.sclang_cmd
= self
.__cmd
_entry
.get_text()