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

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

copy trusty epoptes code

File size: 3.1 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4###########################################################################
5# Get client properties.
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 pygtk
28
29from epoptes.common.constants import *
30
31class ClientInformation:
32    def __init__(self, selected, execute):
33        self.wTree = gtk.Builder()
34        self.wTree.add_from_file('client_information.ui')
35        self.wTree.connect_signals(self)
36        self.get = self.wTree.get_object
37        self.selected = selected
38       
39        self.dlg = self.get('infodlg')
40        self.edit_button = self.get('edit_alias_button')
41        set = lambda wdg, txt: self.get(wdg).set_text(txt.strip())
42
43        for client in selected:
44            inst = client[C_INSTANCE]
45            handle = inst.hsystem or client[C_SESSION_HANDLE]
46            if handle:
47                execute(handle, 'echo $RAM').addCallback(
48                    lambda r: set('client_ram', r.strip()+' MB'))
49                execute(handle, 'echo $CPU').addCallback(
50                    lambda r: set('client_cpu', r))
51                execute(handle, 'echo $VGA').addCallback(
52                    lambda r: set('client_vga', r))
53            set('client_alias', inst.alias)
54            set('client_hostname', inst.hostname)
55            set('client_mac', inst.mac)
56            set('client_ip', handle.split(':')[0])
57            set('client_type', inst.type)
58            user = '--'
59            if client[C_SESSION_HANDLE]:
60                uname, realname = inst.users[client[C_SESSION_HANDLE]].values()
61                user = uname
62                if realname:
63                    user += ' (%s)' %realname
64            set('client_online_user', user)
65            self.dlg.set_title(_('Properties of %s') %inst.get_name())
66       
67    def run(self):
68        self.dlg.run()
69        self.dlg.destroy()
70       
71    def on_edit_alias_clicked(self, widget):
72        inst = self.selected[0][C_INSTANCE]
73        edit_dlg = self.get('edit_alias_dialog')
74        entry = self.get('alias_entry')
75        entry.set_text(inst.alias)
76        resp = edit_dlg.run()
77        if resp == 1:
78            inst.set_name(entry.get_text().strip())
79            self.get('client_alias').set_text(inst.alias.strip())
80        edit_dlg.hide()
Note: See TracBrowser for help on using the repository browser.