source: epoptes/trunk/fuentes/epoptes/ui/execcommand.py @ 295

Last change on this file since 295 was 295, checked in by mabarracus, 4 years ago

copy trusty epoptes code

File size: 2.2 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4###########################################################################
5# Command execution.
6#
7# Copyright (C) 2010 Fotis Tsamis <ftsamis@gmail.com>
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FINESS FOR A PARTICULAR PURPOSE.  See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21#
22# On Debian GNU/Linux systems, the complete text of the GNU General
23# Public License can be found in `/usr/share/common-licenses/GPL".
24###########################################################################
25
26import gtk
27import os
28
29from epoptes.common import config
30
31
32wTree = gtk.Builder()
33get = lambda obj: wTree.get_object(obj)
34store = gtk.ListStore(str)
35
36def startExecuteCmdDlg():
37    """Show the execute commands dialog and return the inserted command.
38
39    If the dialog was closed, return an empty string.
40    """
41    wTree.add_from_file('executeCommand.ui')
42    dlg = get('execDialog')
43    combo = get('combobox')
44    entry = combo.child
45    completion = get('entrycompletion')
46    entry.set_completion(completion)
47    completion.set_model(store)
48    entry.set_activates_default(True)
49    combo.set_model(store)
50    combo.set_text_column(0)
51   
52    entry.connect('changed', text_changed)
53   
54    combo = get('combobox')
55    store.clear()
56   
57    for cmd in config.history:
58        store.append([cmd])
59   
60    cmd = ''
61    reply = dlg.run()
62    if reply == 1:
63        cmd = combo.child.get_text().strip()
64        if cmd in config.history:
65            config.history.remove(cmd)
66        config.history.insert(0, cmd)
67        config.write_history()
68    dlg.destroy()
69   
70    return cmd
71
72def text_changed(editable):
73    if editable.get_text().strip():
74        get('execute').set_sensitive(True)
75    else:
76        get('execute').set_sensitive(False)
Note: See TracBrowser for help on using the repository browser.