示例#1
0
    def _import(self,widget,data=None):

        """
        Get the categoey in which the channels will be imported.

        Convert JSON format channels to "Channel" objects.

        Add the channels to category.

        Get the channel data which are to be displayed in IconView in main
        window.

        Properly scale the image thumbnail of the channel.
        Add the channels to the Iconview in the main window.

        Close the Import Dialog Box.
        """

        all_category = Channel_Store.ALL
        if self.imported_data is not None:
            for channel in self.imported_data:
                imported_channel = Channel(self.imported_data[channel])
                all_category.add(channel,imported_channel)
                (channel_name,image_url,desc) = (channel
                                ,imported_channel.get_thumbnail_url()
                                ,imported_channel.get_description())
                scaled_image = graphics_util.get_scaled_image(image_url,180)
                self.app_window.icon_list_store.append([scaled_image,channel_name,desc])
        self.box.import_box.destroy()
    def _import(self, widget, data=None):
        """
        Get the categoey in which the channels will be imported.

        Convert JSON format channels to "Channel" objects.

        Add the channels to category.

        Get the channel data which are to be displayed in IconView in main
        window.

        Properly scale the image thumbnail of the channel.
        Add the channels to the Iconview in the main window.

        Close the Import Dialog Box.
        """

        all_category = Channel_Store.ALL
        if self.imported_data is not None:
            for channel in self.imported_data:
                imported_channel = Channel(self.imported_data[channel])
                all_category.add(channel, imported_channel)
                (channel_name, image_url,
                 desc) = (channel, imported_channel.get_thumbnail_url(),
                          imported_channel.get_description())
                scaled_image = graphics_util.get_scaled_image(image_url, 180)
                self.app_window.icon_list_store.append(
                    [scaled_image, channel_name, desc])
        self.box.import_box.destroy()
示例#3
0
 def show_monitor_channel(self):  #only for testing purpose
     """
     Show default channel in Channel Iconview when app starts.
     """
     monitor_data = channel_store.get_monitor_data()
     channel = Channel(monitor_data["monitor"])
     store = Channel_Store()
     store.get_default().add(channel.name, channel)
     (name, image_url, desc) = (channel.get_name(),
                                channel.get_thumbnail_url(),
                                channel.get_description())
     scaled_image = graphics_util.get_scaled_image(image_url, 180)
     for i in range(0, 1):
         self.app_window.icon_list_store.append([scaled_image, name, desc])
示例#4
0
    def show_monitor_channel(self):#only for testing purpose

        """
        Show default channel in Channel Iconview when app starts.
        """
        monitor_data = channel_store.get_monitor_data()
        channel = Channel(monitor_data["monitor"])
        store = Channel_Store()
        store.get_default().add(channel.name,channel)
        (name,image_url,desc) = (channel.get_name()
                                ,channel.get_thumbnail_url()
                                ,channel.get_description())
        scaled_image = graphics_util.get_scaled_image(image_url,180)
        for i in range(0,1):
            self.app_window.icon_list_store.append([scaled_image,name,desc])
示例#5
0
 def restore_app_state(self):
     
     """
     Restore channels present in last session of app.
     
     Channels are restored after importing channels from JSON File.
     """
     
     _file =file_util.find_file(__file__,
                                "../data/channels/saved_channels")
     importer = JSON_Importer()
     self.restored_data = importer.from_JSON(_file)
     if self.restored_data is not None:
         all_category = Channel_Store.ALL
         for channel in self.restored_data:
             restored_channel = Channel(self.restored_data[channel])
             all_category.add(channel,restored_channel)
             (channel_name,image_url,desc) = (channel
                             ,restored_channel.get_thumbnail_url()
                             ,restored_channel.get_description())
             scaled_image = graphics_util.get_scaled_image(image_url,180)
             self.app_window.icon_list_store.append([scaled_image,channel_name,desc])
示例#6
0
    def restore_app_state(self):
        """
        Restore channels present in last session of app.
        
        Channels are restored after importing channels from JSON File.
        """

        _file = file_util.find_file(__file__,
                                    "../data/channels/saved_channels")
        importer = JSON_Importer()
        self.restored_data = importer.from_JSON(_file)
        if self.restored_data is not None:
            all_category = Channel_Store.ALL
            for channel in self.restored_data:
                restored_channel = Channel(self.restored_data[channel])
                all_category.add(channel, restored_channel)
                (channel_name, image_url,
                 desc) = (channel, restored_channel.get_thumbnail_url(),
                          restored_channel.get_description())
                scaled_image = graphics_util.get_scaled_image(image_url, 180)
                self.app_window.icon_list_store.append(
                    [scaled_image, channel_name, desc])
示例#7
0
    def export_sample_monitor(self):
        """
       Exports  a monitor channel runinng on local machine. For that first we
       get monitor channel configuration data from channel store.
       After that the monitor data is exported to file in JSON format using
       JSON Exporter and Channel Encoder.
       """

        ## Data to export
        exported_data = channel_store.get_monitor_data()

        ## monitor channel
        monitor_channel = Channel(exported_data["monitor"])

        ## path where channel data is exported.
        path = file_util.find_file(
            __file__, "../data/channels/to_import_sample_data.p2psp")

        ## JSON Exporter
        exporter = JSON_Exporter()
        exporter.to_JSON(path, {"monitor": monitor_channel}, Channel_Encoder)
示例#8
0
    def add(self, widget, data=None):

        #verify thumbnil url,address,port validity
        #if not verified show proper message.
        #elif verified:
        #currently implemented only for local thumbnail images.
        #get texts from all the entries.
        #create channel with given data.
        #add the channel to store
        #get channel data and display it in iconview
        """
        Verify channel configuration and add it to the iconview where channels
        are listed and to the channel store.
        """

        name = self.box.name.get_text()
        desc = self.box.description.get_text()
        thumbnail = self.box.thumbnail.get_text()
        address = str(self.box.address.get_text())
        port = self.box.port.get_value_as_int()
        if name == "":
            msg_dialog = Gtk.MessageDialog(self.parent_window, 0,
                                           Gtk.MessageType.ERROR,
                                           Gtk.ButtonsType.CLOSE,
                                           "CHANNEL NAME IS EMPTY")
            msg_dialog.format_secondary_text(
                "A proper name for channel should be provided.")
            msg_dialog.run()
            msg_dialog.destroy()
            return
        elif desc == "":
            msg_dialog = Gtk.MessageDialog(self.parent_window, 0,
                                           Gtk.MessageType.ERROR,
                                           Gtk.ButtonsType.CLOSE,
                                           "CHANNEL DESCRIPTION IS EMPTY")
            msg_dialog.format_secondary_text(
                "Channel's details should be provided.")
            msg_dialog.run()
            msg_dialog.destroy()
            return
        elif url_util.verify_url(str(thumbnail)) == False:
            msg_dialog = Gtk.MessageDialog(self.parent_window, 0,
                                           Gtk.MessageType.ERROR,
                                           Gtk.ButtonsType.CLOSE,
                                           "INVALID URL")
            msg_dialog.format_secondary_text(str(thumbnail))
            msg_dialog.run()
            msg_dialog.destroy()
            return
        elif url_util.validate_ip(str(address)) == False:
            msg_dialog = Gtk.MessageDialog(self.parent_window, 0,
                                           Gtk.MessageType.ERROR,
                                           Gtk.ButtonsType.CLOSE, "INVALID IP")
            msg_dialog.format_secondary_text(str(address))
            msg_dialog.run()
            msg_dialog.destroy()
            return
        elif int(port) == 0:
            msg_dialog = Gtk.MessageDialog(self.parent_window, 0,
                                           Gtk.MessageType.ERROR,
                                           Gtk.ButtonsType.CLOSE,
                                           "INVALID PORT")
            msg_dialog.format_secondary_text(str(port))
            msg_dialog.run()
            msg_dialog.destroy()
            return
        else:
            channel_data = {
                "name": name,
                "thumbnail_url": url_util.get_path(str(thumbnail)),
                "description": desc,
                "splitter_addr": address,
                "splitter_port": port
            }
            channel = Channel(channel_data)
            store = Channel_Store()
            store.get_default().add(channel.name, channel)
            (name, image_url, desc) = (channel.get_name(),
                                       channel.get_thumbnail_url(),
                                       channel.get_description())
            scaled_image = graphics_util.get_scaled_image(image_url, 180)
            self.app_view.icon_list_store.append([scaled_image, name, desc])
            self.box.dialog.destroy()
示例#9
0
    def add(self,widget,data=None):

        #verify thumbnil url,address,port validity
        #if not verified show proper message.
        #elif verified:
        #currently implemented only for local thumbnail images.
        #get texts from all the entries.
        #create channel with given data.
        #add the channel to store
        #get channel data and display it in iconview
        
        """
        Verify channel configuration and add it to the iconview where channels
        are listed and to the channel store.
        """
        
        name = self.box.name.get_text()
        desc = self.box.description.get_text()
        thumbnail = self.box.thumbnail.get_text()
        address = str(self.box.address.get_text())
        port = self.box.port.get_value_as_int()
        if name == "":
            msg_dialog = Gtk.MessageDialog(self.parent_window, 0, Gtk.MessageType.ERROR,
            Gtk.ButtonsType.CLOSE, "CHANNEL NAME IS EMPTY")
            msg_dialog.format_secondary_text("A proper name for channel should be provided.")
            msg_dialog.run()
            msg_dialog.destroy()
            return
        elif desc == "":
            msg_dialog = Gtk.MessageDialog(self.parent_window, 0, Gtk.MessageType.ERROR,
            Gtk.ButtonsType.CLOSE, "CHANNEL DESCRIPTION IS EMPTY")
            msg_dialog.format_secondary_text("Channel's details should be provided.")
            msg_dialog.run()
            msg_dialog.destroy()
            return
        elif url_util.verify_url(str(thumbnail)) == False:
            msg_dialog = Gtk.MessageDialog(self.parent_window, 0, Gtk.MessageType.ERROR,
            Gtk.ButtonsType.CLOSE, "INVALID URL")
            msg_dialog.format_secondary_text(str(thumbnail))
            msg_dialog.run()
            msg_dialog.destroy()
            return
        elif url_util.validate_ip(str(address)) == False:
            msg_dialog = Gtk.MessageDialog(self.parent_window, 0, Gtk.MessageType.ERROR,
            Gtk.ButtonsType.CLOSE, "INVALID IP")
            msg_dialog.format_secondary_text(str(address))
            msg_dialog.run()
            msg_dialog.destroy()
            return
        elif int(port) == 0:
            msg_dialog = Gtk.MessageDialog(self.parent_window, 0, Gtk.MessageType.ERROR,
            Gtk.ButtonsType.CLOSE, "INVALID PORT")
            msg_dialog.format_secondary_text(str(port))
            msg_dialog.run()
            msg_dialog.destroy()
            return
        else :
            channel_data = {"name" : name
            ,"thumbnail_url" : url_util.get_path(str(thumbnail))
            ,"description"   : desc
            ,"splitter_addr" : address
            ,"splitter_port" : port
            }
            channel = Channel(channel_data)
            store = Channel_Store()
            store.get_default().add(channel.name,channel)
            (name,image_url,desc) = (channel.get_name()
                                    ,channel.get_thumbnail_url()
                                    ,channel.get_description())
            scaled_image = graphics_util.get_scaled_image(image_url,180)
            self.app_view.icon_list_store.append([scaled_image
                                                          ,name
                                                          ,desc])
            self.box.dialog.destroy()