Exemple #1
0
    def __init__(self, parent):
        aui.AuiMDIParentFrame.__init__(self, parent, -1,
                                          title="Conveggie a convore client",
                                          name="parentframe",
                                          size=(500,700),
                                          style=wx.DEFAULT_FRAME_STYLE)

        self.menu_items = {}

        self._persistance_mgr = PersistenceManager.Get()
        self._persistance_mgr.SetPersistenceFile(os.path.join(config.get_config_dir(), "ui.cfg"))

        self.request_queue = Queue.Queue()
        self.live_queue = Queue.Queue()
        self.convore_reader = ConvoreReader(self.request_queue)
        self.convore_reader.start()
        self.convore_live = ConvoreLive(self.live_queue, self.request_queue)
        self.convore_live.start()

        commands.request.set_queue(self.request_queue)

        Publisher().subscribe(self.on_group_selected, 'ui.convore.dashboard.group_selected')
        Publisher().subscribe(self.on_topic_selected, 'ui.convore.group.topic_selected')
        Publisher().subscribe(self._link_clicked, 'ui.convore.link_clicked')

        commands.response.subscribe(self._data_response_error, 'data_error')
        commands.response.subscribe(self._check_login, 'convore_login')

        s = wx.aui.AuiSimpleTabArt()
        self.SetArtProvider(s)
        self._create_menu()
        self.CreateStatusBar()

        self.Bind(wx.EVT_MENU, self._evt_menu, id=wx.ID_EXIT)
        self.Bind(wx.EVT_MENU, self._evt_menu, id=self.menu_items['your_groups'].GetId())
        self.Bind(wx.EVT_MENU, self._evt_menu, id=self.menu_items['live_stream'].GetId())

        self._persistance_mgr.RegisterAndRestore(self)


        self.SetIcon(self._make_icon())

        wx.CallAfter(self._login_and_fetch)
Exemple #2
0
class ParentFrame(aui.AuiMDIParentFrame):
    def __init__(self, parent):
        aui.AuiMDIParentFrame.__init__(self, parent, -1,
                                          title="Conveggie a convore client",
                                          name="parentframe",
                                          size=(500,700),
                                          style=wx.DEFAULT_FRAME_STYLE)

        self.menu_items = {}

        self._persistance_mgr = PersistenceManager.Get()
        self._persistance_mgr.SetPersistenceFile(os.path.join(config.get_config_dir(), "ui.cfg"))

        self.request_queue = Queue.Queue()
        self.live_queue = Queue.Queue()
        self.convore_reader = ConvoreReader(self.request_queue)
        self.convore_reader.start()
        self.convore_live = ConvoreLive(self.live_queue, self.request_queue)
        self.convore_live.start()

        commands.request.set_queue(self.request_queue)

        Publisher().subscribe(self.on_group_selected, 'ui.convore.dashboard.group_selected')
        Publisher().subscribe(self.on_topic_selected, 'ui.convore.group.topic_selected')
        Publisher().subscribe(self._link_clicked, 'ui.convore.link_clicked')

        commands.response.subscribe(self._data_response_error, 'data_error')
        commands.response.subscribe(self._check_login, 'convore_login')

        s = wx.aui.AuiSimpleTabArt()
        self.SetArtProvider(s)
        self._create_menu()
        self.CreateStatusBar()

        self.Bind(wx.EVT_MENU, self._evt_menu, id=wx.ID_EXIT)
        self.Bind(wx.EVT_MENU, self._evt_menu, id=self.menu_items['your_groups'].GetId())
        self.Bind(wx.EVT_MENU, self._evt_menu, id=self.menu_items['live_stream'].GetId())

        self._persistance_mgr.RegisterAndRestore(self)


        self.SetIcon(self._make_icon())

        wx.CallAfter(self._login_and_fetch)

    def _make_icon(self):
        """
        The various platforms have different requirements for the
        icon size...
        """
        img = wx.Image('./media/conveggie.png', wx.BITMAP_TYPE_PNG)
        if "wxMSW" in wx.PlatformInfo:
            img = img.Scale(16, 16)
        elif "wxGTK" in wx.PlatformInfo:
            img = img.Scale(22, 22)
        # wxMac can be any size upto 128x128, so leave the source img alone....
        icon = wx.IconFromBitmap(img.ConvertToBitmap() )
        return icon

    def _create_menu(self):
        menubar = wx.MenuBar()

        conveggie_menu = wx.Menu()
        convore_menu = wx.Menu()
        help_menu = wx.Menu()


        conveggie_menu.Append(wx.ID_EXIT,
                              '&Quit\tCtrl+Q',
                              'Quit Conveggie')

        self.menu_items['your_groups'] = convore_menu.Append(-1,
                             '&Your Groups\tCtrl+Shift+G',
                             'Display the Your Groups tab.')
        self.menu_items['live_stream'] = convore_menu.Append(-1,
                            '&Live Stream\tCtrl+Shift+L',
                            'Display the Live Stream Tab')

        #help_menu.AppendItem(wx.MenuItem(help_menu, wx.ID_HELP,
                                      #'&Help',
                                      #'Display the Conveggie help.')
                          #)
        #help_menu.AppendItem(wx.MenuItem(help_menu, wx.ID_ABOUT,
                                      #'&About',
                                      #'About Conveggie.')
                          #)

        menubar.Append(conveggie_menu, 'Con&veggie')
        menubar.Append(convore_menu, '&Convore')
#        menubar.Append(help_menu, '&Help')
        self.SetMenuBar(menubar)

    def _login_and_fetch(self):
        username = wx.ConfigBase_Get().Read(config.KEY_CONVORE_USERNAME, "")
        password = wx.ConfigBase_Get().Read(config.KEY_CONVORE_PASSWORD, "")

        if username == "" or password == "":
            dlg = LoginDialog(self)
            if dlg.ShowModal() <> wx.ID_OK:
                self.Close()
                return

            if dlg.save == True:
                wx.ConfigBase_Get().Write(config.KEY_CONVORE_USERNAME, dlg.username)
                wx.ConfigBase_Get().Write(config.KEY_CONVORE_PASSWORD, dlg.password)
            else:
                wx.ConfigBase_Get().DeleteEntry(config.KEY_CONVORE_USERNAME, True)
                wx.ConfigBase_Get().DeleteEntry(config.KEY_CONVORE_PASSWORD, True)

            username = dlg.username
            password = dlg.password

        login_data = {'username': username,
                      'password': password}

        commands.request.send('convore_login', login_data)

        group_list = GroupListFrame(self)
        live_stream = LiveStreamFrame(self)

        group_list.Activate()
        group_list.SetFocus()

        self.live_queue.put(Message('data.request.convore.live.login', login_data))
        self.live_queue.put(Message('data.request.convore.live.fetch'))

    def _data_response_error(self, message):
        """handles all pubsub data.request messages and puts them in the
        request queue for the data thread."""
        dial = wx.MessageDialog(self, message.data, 'Error',
                                wx.OK | wx.ICON_ERROR
                                )
        dial.ShowModal()

    def _check_login(self, message):
        if message.data['login'] == False:
            dial = wx.MessageDialog(self, 'Error login into Convore', 'Error',
                                    wx.OK | wx.ICON_ERROR
                                    )
            dial.ShowModal()

    def _link_clicked(self, message):
        wx.LaunchDefaultBrowser(message.data['href'])

    def _evt_menu(self, event):

        if event.Id == wx.ID_EXIT:
            self._persistance_mgr.SaveAndUnregister()
            self.Close()
            event.Skip()
        elif event.Id == self.menu_items['your_groups'].GetId():
            frame = self.FindWindowByName('your_groups')
            if frame == None:
                frame = GroupListFrame(self)

            frame.Activate()
            frame.SetFocus()
        elif event.Id == self.menu_items['live_stream'].GetId():
            frame = self.FindWindowByName('live_stream')
            if frame == None:
                frame = LiveStreamFrame(self)

            frame.Activate()
            frame.SetFocus()

    def on_group_selected(self, message):
        frame = self.FindWindowByName('group:%s' %(message.data.id))
        if frame == None:
            frame = GroupFrame(self, message.data)

        frame.Activate()
        frame.SetFocus()

    def on_topic_selected(self, message):
        frame = self.FindWindowByName('topic:%s' %(message.data.id))

        if frame == None:
            frame = TopicFrame(self, message.data)

        frame.Activate()
        frame.SetFocus()