예제 #1
0
    def __init__(self, *args, **kwds):
        Log.__init__(self)
        self.__queueList = []
        self.__queueDict = {}
        if platform.system().lower() == "windows":
            # win用に書く
            pass
        else:
            home = os.getenv("HOME")
        nmlHome = os.path.join(home, WORKDIR)
        if not os.path.exists(nmlHome):
            os.mkdir(nmlHome)
        self.databasePath = os.path.join(nmlHome, DATABASE_FILE)
        self.systemDatabasePath = os.path.join(nmlHome, SYSTEM_DATABASE_FILE)

        db = Database(self.databasePath)
        db.ctTable()
        db.close()
        sdb = SystemDatabase(self.systemDatabasePath)
        sdb.ctTable()
        nid = sdb.getNicoid() if sdb.getNicoid() else u""
        npw = sdb.getNicopw() if sdb.getNicopw() else u""
        gid = sdb.getGmailid() if sdb.getGmailid() else u""
        gpw = sdb.getGmailpw() if sdb.getGmailpw() else u""
        sdr = sdb.getSavedir() if sdb.getSavedir() else u""
        sdb.close()

        self.nicoTable = NTable(nid, npw, gid, gpw, sdr)

        # begin wxGlade: NicoMovieLoadGUI.__init__
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.treeCtrl = gizmos.TreeListCtrl(self, -1, style=wx.TR_HAS_BUTTONS | wx.TR_NO_LINES | wx.TR_FULL_ROW_HIGHLIGHT | wx.TR_HIDE_ROOT | wx.TR_DEFAULT_STYLE)
        self.pnlCenter = wx.Panel(self, -1)
        self.lblUrl = wx.StaticText(self.pnlCenter, -1, "URL:")
        self.tclUrl = wx.TextCtrl(self.pnlCenter, -1, "", style=wx.TE_PROCESS_ENTER)
        self.pnlBottom = wx.Panel(self, -1)
        self.lblQueueList = wx.StaticText(self.pnlBottom, -1, "QueueList:")
        self.lclQueueList = wx.ListCtrl(self.pnlBottom, -1, style=wx.LC_REPORT | wx.LC_AUTOARRANGE | wx.LC_NO_HEADER | wx.SUNKEN_BORDER)
        self.lblLog = wx.StaticText(self.pnlBottom, -1, "Log:")
        self.tclLog = wx.TextCtrl(self.pnlBottom, -1, "", style=wx.TE_MULTILINE | wx.TE_READONLY)
        self.static_line_1 = wx.StaticLine(self, -1, style=wx.LI_VERTICAL)
        self.pnlRight = wx.Panel(self, -1)
        self.btnRss = wx.ToggleButton(self.pnlRight, -1, "RSS")
        self.btnAdd = wx.Button(self.pnlRight, -1, u"新規登録")
        self.btnLoad = wx.Button(self.pnlRight, -1, u"再ロード")
        self.btnClearLog = wx.Button(self.pnlRight, -1, u"ログ消去")
        self.btnDelete = wx.Button(self.pnlRight, -1, u"削除")
        self.btnSettings = wx.Button(self.pnlRight, -1, u"設定")
        self.btnExit = wx.Button(self.pnlRight, -1, "Exit")

        self.__set_properties()
        self.__do_layout()
        # end wxGlade
        self.__bind()
        self.__setTreeListCtrl()
        self.__set_QueueListCtrl()
        # other wigets
        self.dlgSettings = SettingsDialog(self.nicoTable, self.logging, self)
        # main
        self.nicoMain = NicoMovieLoadMain(self.databasePath, self.systemDatabasePath, self.logging)
        self.nicoMain.main()
        # timer
        timer = wx.Timer(self)
        timer.Start(3 * 1000)
        print "timer start"
예제 #2
0
class NicoMovieLoadGUI(wx.Frame, Log):
    def __init__(self, *args, **kwds):
        Log.__init__(self)
        self.__queueList = []
        self.__queueDict = {}
        if platform.system().lower() == "windows":
            # win用に書く
            pass
        else:
            home = os.getenv("HOME")
        nmlHome = os.path.join(home, WORKDIR)
        if not os.path.exists(nmlHome):
            os.mkdir(nmlHome)
        self.databasePath = os.path.join(nmlHome, DATABASE_FILE)
        self.systemDatabasePath = os.path.join(nmlHome, SYSTEM_DATABASE_FILE)

        db = Database(self.databasePath)
        db.ctTable()
        db.close()
        sdb = SystemDatabase(self.systemDatabasePath)
        sdb.ctTable()
        nid = sdb.getNicoid() if sdb.getNicoid() else u""
        npw = sdb.getNicopw() if sdb.getNicopw() else u""
        gid = sdb.getGmailid() if sdb.getGmailid() else u""
        gpw = sdb.getGmailpw() if sdb.getGmailpw() else u""
        sdr = sdb.getSavedir() if sdb.getSavedir() else u""
        sdb.close()

        self.nicoTable = NTable(nid, npw, gid, gpw, sdr)

        # begin wxGlade: NicoMovieLoadGUI.__init__
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.treeCtrl = gizmos.TreeListCtrl(self, -1, style=wx.TR_HAS_BUTTONS | wx.TR_NO_LINES | wx.TR_FULL_ROW_HIGHLIGHT | wx.TR_HIDE_ROOT | wx.TR_DEFAULT_STYLE)
        self.pnlCenter = wx.Panel(self, -1)
        self.lblUrl = wx.StaticText(self.pnlCenter, -1, "URL:")
        self.tclUrl = wx.TextCtrl(self.pnlCenter, -1, "", style=wx.TE_PROCESS_ENTER)
        self.pnlBottom = wx.Panel(self, -1)
        self.lblQueueList = wx.StaticText(self.pnlBottom, -1, "QueueList:")
        self.lclQueueList = wx.ListCtrl(self.pnlBottom, -1, style=wx.LC_REPORT | wx.LC_AUTOARRANGE | wx.LC_NO_HEADER | wx.SUNKEN_BORDER)
        self.lblLog = wx.StaticText(self.pnlBottom, -1, "Log:")
        self.tclLog = wx.TextCtrl(self.pnlBottom, -1, "", style=wx.TE_MULTILINE | wx.TE_READONLY)
        self.static_line_1 = wx.StaticLine(self, -1, style=wx.LI_VERTICAL)
        self.pnlRight = wx.Panel(self, -1)
        self.btnRss = wx.ToggleButton(self.pnlRight, -1, "RSS")
        self.btnAdd = wx.Button(self.pnlRight, -1, u"新規登録")
        self.btnLoad = wx.Button(self.pnlRight, -1, u"再ロード")
        self.btnClearLog = wx.Button(self.pnlRight, -1, u"ログ消去")
        self.btnDelete = wx.Button(self.pnlRight, -1, u"削除")
        self.btnSettings = wx.Button(self.pnlRight, -1, u"設定")
        self.btnExit = wx.Button(self.pnlRight, -1, "Exit")

        self.__set_properties()
        self.__do_layout()
        # end wxGlade
        self.__bind()
        self.__setTreeListCtrl()
        self.__set_QueueListCtrl()
        # other wigets
        self.dlgSettings = SettingsDialog(self.nicoTable, self.logging, self)
        # main
        self.nicoMain = NicoMovieLoadMain(self.databasePath, self.systemDatabasePath, self.logging)
        self.nicoMain.main()
        # timer
        timer = wx.Timer(self)
        timer.Start(3 * 1000)
        print "timer start"

    def __bind(self):
        self.Bind(wx.EVT_BUTTON, self.OnSettings, self.btnSettings)
        self.Bind(wx.EVT_BUTTON, self.OnClearLog, self.btnClearLog)
        self.Bind(wx.EVT_BUTTON, self.OnAdd, self.btnAdd)
        self.Bind(wx.EVT_TEXT_ENTER, self.OnAdd, self.tclUrl)
        self.Bind(wx.EVT_TIMER, self.updateQueueList)

    def OnAdd(self, evt):
        """
        add movieid/mylistid from self.tclUrl
        """
        url = self.tclUrl.GetValue()
        mid = self.nicoMain.find(url)
        if not mid:
            self.logging("Add: IDが見つかりませんでした")
        elif self.nicoMain.register(mid):
            self.logging(u"Add: %sを登録しました" % mid)
        elif mid[0:2] == u"sm":
            self.nicoMain.getQueueObj().addFront(mid)
            self.logging(u"Add: %sを次に予約しました" % mid)
        self.tclUrl.SetValue("")

    def logging(self, *texts, **indent):
        """
        texts: shown strings
        indent: (indent=True/False) If indent is True, show indent.
        """
        self.output(texts[0])
        self.output("\n")
        #self.log(*texts, **indent)  # raise unknown error

    def OnClearLog(self, evt):
        """
        log Clear
        """
        self.tclLog.SetValue("")
        time.sleep(0.1)

    def OnSettings(self, evt):
        self.dlgSettings.ShowModal()
        #try:
        sdb = SystemDatabase(self.systemDatabasePath)
        sdb.svNicoid(self.nicoTable.getNicoid().encode("utf-8"))
        sdb.svNicopw(self.nicoTable.getNicopw().encode("utf-8"))
        sdb.svGmailid(self.nicoTable.getGmailid().encode("utf-8"))
        sdb.svGmailpw(self.nicoTable.getGmailpw().encode("utf-8"))
        sdb.svSavedir(self.nicoTable.getSavedir().encode("utf-8"))
        sdb.close()

        self.dlgSettings = SettingsDialog(self.nicoTable, self.tclLog.WriteText, self)

    def output(self, text):
        """
        overwrite
        """
        self.tclLog.SetInsertionPointEnd()
        self.tclLog.WriteText(text)

    def __set_properties(self):
        # begin wxGlade: NicoMovieLoadGUI.__set_properties
        self.SetTitle("NicoMovieLoad")
        self.SetSize((700, 650))
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: NicoMovieLoadGUI.__do_layout
        sizer0 = wx.BoxSizer(wx.HORIZONTAL)
        sizerButtons = wx.BoxSizer(wx.VERTICAL)
        sizer_1 = wx.BoxSizer(wx.VERTICAL)
        szrBottom = wx.BoxSizer(wx.HORIZONTAL)
        szrLog = wx.BoxSizer(wx.VERTICAL)
        szrQueueList = wx.BoxSizer(wx.VERTICAL)
        szrUrlTextBox = wx.BoxSizer(wx.HORIZONTAL)
        szrUrlBox = wx.BoxSizer(wx.VERTICAL)
        szrUrlText = wx.BoxSizer(wx.VERTICAL)
        sizer_1.Add(self.treeCtrl, 1, wx.EXPAND, 0)
        szrUrlText.Add(self.lblUrl, 1, 0, 0)
        szrUrlTextBox.Add(szrUrlText, 0, wx.EXPAND, 0)
        szrUrlBox.Add(self.tclUrl, 0, wx.EXPAND, 0)
        szrUrlTextBox.Add(szrUrlBox, 1, wx.EXPAND, 0)
        self.pnlCenter.SetSizer(szrUrlTextBox)
        sizer_1.Add(self.pnlCenter, 0, wx.EXPAND, 0)
        szrQueueList.Add(self.lblQueueList, 0, wx.EXPAND, 0)
        szrQueueList.Add(self.lclQueueList, 1, wx.EXPAND, 0)
        szrBottom.Add(szrQueueList, 1, wx.EXPAND, 0)
        szrLog.Add(self.lblLog, 0, wx.EXPAND, 0)
        szrLog.Add(self.tclLog, 1, wx.EXPAND, 0)
        szrBottom.Add(szrLog, 1, wx.EXPAND, 0)
        self.pnlBottom.SetSizer(szrBottom)
        sizer_1.Add(self.pnlBottom, 1, wx.EXPAND, 0)
        sizer0.Add(sizer_1, 1, wx.EXPAND, 0)
        sizer0.Add(self.static_line_1, 0, wx.LEFT | wx.RIGHT | wx.EXPAND, 1)
        sizerButtons.Add(self.btnRss, 0, wx.EXPAND, 0)
        sizerButtons.Add(self.btnAdd, 0, wx.EXPAND, 0)
        sizerButtons.Add(self.btnLoad, 0, wx.EXPAND, 0)
        sizerButtons.Add(self.btnClearLog, 0, wx.EXPAND, 0)
        sizerButtons.Add(self.btnDelete, 0, wx.EXPAND, 0)
        sizerButtons.Add(self.btnSettings, 0, wx.EXPAND, 0)
        sizerButtons.Add(self.btnExit, 0, wx.EXPAND, 0)
        self.pnlRight.SetSizer(sizerButtons)
        sizer0.Add(self.pnlRight, 0, wx.EXPAND, 0)
        self.SetSizer(sizer0)
        self.Layout()
        # end wxGlade

    def __setTreeListCtrl(self):
        isz = (16,16)  # image
        il = wx.ImageList(isz[0], isz[1])
        fldridx     = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FOLDER,      wx.ART_OTHER, isz))
        fldropenidx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN,   wx.ART_OTHER, isz))
        fileidx     = il.Add(wx.ArtProvider_GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER, isz))

        self.treeCtrl.SetImageList(il)
        self.il = il

        # create some columns
        self.treeCtrl.AddColumn(u"タイトル")
        self.treeCtrl.AddColumn(u"済み or RSS")
        self.treeCtrl.AddColumn(u"id")
        self.treeCtrl.SetMainColumn(0) # the one with the tree in it...
        self.treeCtrl.SetColumnWidth(0, 175)
        # append data
        self.treeCtrlRoot = []
        self.root = self.treeCtrl.AddRoot("The Root Item")
        self.treeCtrlRoot.append(self.root)
        #self.treeCtrl.SetItemText(self.root, "col 1 self.root", 1)
        #self.treeCtrl.SetItemText(self.root, "col 2 self.root", 2)
        #self.treeCtrl.SetItemImage(self.root, fldridx, which = wx.TreeItemIcon_Normal)
        #self.treeCtrl.SetItemImage(self.root, fldropenidx, which = wx.TreeItemIcon_Expanded)
        for x in range(5):
            txt = "Item %d" % x
            child = self.treeCtrl.AppendItem(self.root, txt)  # tree part
            self.treeCtrl.SetItemText(child, txt + " do RSS or dont", 1)  # description 1
            self.treeCtrl.SetItemText(child, txt + " mylist id", 2)  # description 2
            self.treeCtrl.SetItemImage(child, fldridx, which = wx.TreeItemIcon_Normal)
            self.treeCtrl.SetItemImage(child, fldropenidx, which = wx.TreeItemIcon_Expanded)
            for i in xrange(5):
                txt2 = "Item"
                last = self.treeCtrl.AppendItem(child, txt2)
                self.treeCtrl.SetItemText(last, txt + " Loaded or yet", 1)  # description 1
                self.treeCtrl.SetItemText(last, txt + " move id", 2)  # description 2
                self.treeCtrl.SetItemImage(last, fileidx, which = wx.TreeItemIcon_Normal)
                self.treeCtrl.SetItemImage(last, fileidx, which = wx.TreeItemIcon_Selected)

    def __set_QueueListCtrl(self):
        self.lclQueueList.InsertColumn(0, u"ID")
        self.lclQueueList.InsertColumn(1, u"title")
        self.lclQueueList.SetColumnWidth(0, wx.LIST_AUTOSIZE)
        self.lclQueueList.SetColumnWidth(1, wx.LIST_AUTOSIZE)
        self.lclQueueList.OnGetItemText = self.OnGetItemText

    def updateQueueList(self):
        movieQueue = self.nicoMain.getQueueObj.getQueueList()
        print movieQueue
        # 辞書の値の更新
        for movieid in self.__queueDict.keys():
            if not(movieid in movieQueue):
                del self.__queueDict[movieid]
        for movieid in movieQueue:
            if self.__queueDict.has_key(movieid) == False:
                try:
                    api = NicovideoAPI(movie_id=movieid)
                    title = api.get_movie_title()
                except:
                    title = "unknown"
                self.__queueDict.update({movieid : title})

        for movieid, title in self.__queueDict.items():
            self.__queueList.append((movieid, title))
        self.lclQueueList.SetItemCount(len(self.__queueList))

    def appendQueueList(self, mid, title):
        self.__queueList.append((mid, title))
        self.lclQueueList.SetItemCount(len(self.__queueList))

    def OnGetItemText(self, row, col):
        return self.__queueList[row][col]

    def removeQueueList(self):
        self.lclQueueList.DeleteItem(0)