示例#1
0
    def __init__(self):
        # Initialization of general-purpose variables
        self.about = None
        self.benchmark = None
        self.client_information = None
        self.current_macs = subprocess.Popen(
            [
                'sh', '-c', r"""ip -oneline -family inet link show | """
                r"""sed -n '/.*ether[[:space:]]*\([[:xdigit:]:]*\).*/"""
                r"""{s//\1/;y/abcdef-/ABCDEF:/;p;}';"""
                r"""echo $LTSP_CLIENT_MAC"""
            ],
            stdout=subprocess.PIPE).communicate()[0].split()
        self.current_thumbshots = dict()
        self.daemon = None
        self.displayed_compatibility_warning = False
        self.exec_command = None
        self.imagetypes = {
            'thin': GdkPixbuf.Pixbuf.new_from_file('images/thin.svg'),
            'fat': GdkPixbuf.Pixbuf.new_from_file('images/fat.svg'),
            'standalone':
            GdkPixbuf.Pixbuf.new_from_file('images/standalone.svg'),
            'offline': GdkPixbuf.Pixbuf.new_from_file('images/offline.svg')
        }
        self.labels_order = (1, 0)
        self.notify_queue = NotifyQueue(
            'Epoptes', '/usr/share/icons/hicolor/scalable/apps/epoptes.svg')
        self.send_message = None
        self.show_real_names = config.settings.getboolean('GUI',
                                                          'show_real_names',
                                                          fallback=False)
        # Thumbshot width and height. Good width defaults are multiples of 16,
        # so that the height is an integer in both 16/9 and 4/3 aspect ratios.
        self.ts_width = config.settings.getint('GUI',
                                               'thumbshots_width',
                                               fallback=128)
        self.ts_height = int(self.ts_width / (4 / 3))
        self.uid = os.getuid()
        self.vncserver = None
        self.vncserver_port = None
        self.vncserver_pwd = None
        self.vncviewer = None
        self.vncviewer_port = None

        self.builder = Gtk.Builder()
        self.builder.add_from_file('epoptes.ui')
        self.get = self.builder.get_object
        # Hide the remote assistance menuitem if epoptes-client isn't installed
        if not os.path.isfile(
                '/usr/share/epoptes-client/remote_assistance.py'):
            self.get('mi_remote_assistance').set_property('visible', False)
            self.get('smi_help_remote_support').set_property('visible', False)
        self.mnu_add_to_group = self.get('mnu_add_to_group')
        self.mni_add_to_group = self.get('mni_add_to_group')
        self.gstore = Gtk.ListStore(str, object, bool)
        self.trv_groups = self.get('trv_groups')
        self.trv_groups.set_model(self.gstore)
        self.mainwin = self.get('wnd_main')
        self.cstore = Gtk.ListStore(str, GdkPixbuf.Pixbuf, object, str)
        self.icv_clients = self.get('icv_clients')
        self.set_labels_order(1, 0, None)
        self.icv_clients.set_model(self.cstore)
        self.icv_clients.set_pixbuf_column(C_PIXBUF)
        self.icv_clients.set_text_column(C_LABEL)
        self.cstore.set_sort_column_id(C_LABEL, Gtk.SortType.ASCENDING)
        self.on_icv_clients_selection_changed(None)
        self.icv_clients.enable_model_drag_source(
            Gdk.ModifierType.BUTTON1_MASK,
            [Gtk.TargetEntry.new("add", Gtk.TargetFlags.SAME_APP, 0)],
            Gdk.DragAction.COPY)
        self.trv_groups.enable_model_drag_dest(
            [("add", Gtk.TargetFlags.SAME_APP, 0)], Gdk.DragAction.COPY)
        self.default_group = structs.Group(
            '<b>' + _('Detected clients') + '</b>', {})
        default_iter = self.gstore.append(
            [self.default_group.name, self.default_group, False])
        self.default_group_ref = Gtk.TreeRowReference.new(
            self.gstore, self.gstore.get_path(default_iter))
        # Connect glade handlers with the callback functions
        self.builder.connect_signals(self)
        self.trv_groups.get_selection().select_path(
            self.default_group_ref.get_path())
        self.get('adj_icon_size').set_value(self.ts_width)
        _saved_clients, groups = config.read_groups(
            config.expand_filename('groups.json'))
        if groups:
            self.mni_add_to_group.set_sensitive(True)
        for group in groups:
            self.gstore.append([group.name, group, True])
            mitem = Gtk.MenuItem(label=group.name)
            mitem.show()
            mitem.connect('activate',
                          self.on_imi_clients_add_to_group_activate, group)
            self.mnu_add_to_group.append(mitem)
        self.fill_icon_view(self.get_selected_group()[1])
        self.trv_groups.get_selection().select_path(
            config.settings.getint('GUI', 'selected_group', fallback=0))
        mitem = self.get(
            config.settings.get('GUI',
                                'label',
                                fallback='rmi_labels_host_user'))
        if not mitem:
            mitem = self.get('rmi_labels_host_user')
        mitem.set_active(True)
        self.get('cmi_show_real_names').set_active(self.show_real_names)
        self.mainwin.set_sensitive(False)
示例#2
0
文件: gui.py 项目: a926kujfkuyf/fgs
    def __init__(self):
        self.shownCompatibilityWarning = False
        self.vncserver = None
        self.vncviewer = None
        self.scrWidth = 100
        self.scrHeight = 75
        self.showRealNames = False
        self.currentScreenshots = dict()
        self.current_macs = subprocess.Popen([
            'sh', '-c',
            """ip -oneline -family inet link show | sed -n '/.*ether[[:space:]]*\\([[:xdigit:]:]*\).*/{s//\\1/;y/abcdef-/ABCDEF:/;p;}'
            echo $LTSP_CLIENT_MAC"""
        ],
                                             stdout=subprocess.PIPE
                                             ).communicate()[0].split()
        self.uid = os.getuid()
        if 'thumbnails_width' in config.user:
            self.scrWidth = config.user['thumbnails_width']
        self.offline = gtk.gdk.pixbuf_new_from_file('images/offline.svg')
        self.thin = gtk.gdk.pixbuf_new_from_file('images/thin.svg')
        self.fat = gtk.gdk.pixbuf_new_from_file('images/fat.svg')
        self.standalone = gtk.gdk.pixbuf_new_from_file('images/standalone.svg')
        self.imagetypes = {
            'thin': self.thin,
            'fat': self.fat,
            'standalone': self.standalone,
            'offline': self.offline
        }

        self.wTree = gtk.Builder()
        self.wTree.add_from_file('epoptes.ui')

        self.get = lambda obj: self.wTree.get_object(obj)

        # Connect glade handlers with the callback functions
        self.wTree.connect_signals(self)

        # Hide the remote assistance menuitem if epoptes-client is not installed
        if not os.path.isfile('/usr/share/epoptes-client/remote-assistance'):
            self.get('mi_remote_assistance').set_property('visible', False)
            self.get('remote_assistance_separator').set_property(
                'visible', False)

        self.groups_menu = self.get('mAddToGroup')
        self.add_to_group_menu = self.get('miAddToGroup')

        self.gstore = gtk.ListStore(str, object, bool)

        self.gtree = self.get("groups_tree")
        self.gtree.set_model(self.gstore)
        self.gtree.get_selection().connect("changed",
                                           self.on_group_selection_changed)

        self.mainwin = self.get('mainwindow')

        self.cstore = gtk.ListStore(str, gtk.gdk.Pixbuf, object, str)
        self.cview = self.get('clientsview')
        self.cView_order = (1, 0)
        self.set_cView(*self.cView_order)

        self.cview.set_model(self.cstore)
        self.cview.set_pixbuf_column(C_PIXBUF)
        self.cview.set_text_column(C_LABEL)

        self.cstore.set_sort_column_id(C_LABEL, gtk.SORT_ASCENDING)
        self.on_clients_selection_changed()

        self.cview.enable_model_drag_source(gtk.gdk.BUTTON1_MASK,
                                            [("add", gtk.TARGET_SAME_APP, 0)],
                                            gtk.gdk.ACTION_COPY)
        self.gtree.enable_model_drag_dest([("add", gtk.TARGET_SAME_APP, 0)],
                                          gtk.gdk.ACTION_COPY)

        self.default_group = structs.Group('<b>' + _('Detected clients') +
                                           '</b>')
        default_iter = self.gstore.append(
            [self.default_group.name, self.default_group, False])
        self.default_group.ref = gtk.TreeRowReference(
            self.gstore, self.gstore.get_path(default_iter))
        self.gtree.get_selection().select_path(
            self.default_group.ref.get_path())

        self.get('iconsSizeAdjustment').set_value(self.scrWidth)
        self.reload_imagetypes()

        saved_clients, groups = config.read_groups(
            os.path.expanduser('~/.config/epoptes/groups.json'))
        if len(groups) > 0:
            self.add_to_group_menu.set_sensitive(True)
        for grp in groups:
            self.gstore.append([grp.name, grp, True])
            mitem = gtk.MenuItem(grp.name)
            mitem.show()
            mitem.connect('activate', self.on_add_to_group_clicked, grp)
            self.groups_menu.append(mitem)

        self.fillIconView(self.getSelectedGroup()[1])
        if config.settings.has_option('GUI', 'selected_group'):
            path = config.settings.getint('GUI', 'selected_group')
            self.gtree.get_selection().select_path(path)
        if config.settings.has_option('GUI', 'label'):
            try:
                self.get(config.settings.get('GUI', 'label')).set_active(True)
            except:
                pass
        if config.settings.has_option('GUI', 'showRealNames'):
            self.get('mcShowRealNames').set_active(
                config.settings.getboolean('GUI', 'showRealNames'))
        self.mainwin.set_sensitive(False)