Пример #1
0
 def OnInit(self):
     # Shareware check
     self.shareware = pShareware.pShareware()
     self.trial = self.shareware.checkTrial()
     if self.trial:
         frame = pDictGUI(None, "pDict trial")
     else:
         frame = pDictGUI(None, "pDict")
     del self.shareware
     del self.trial
     self.SetTopWindow(frame)
     frame.Show(True)
     return True
Пример #2
0
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, -1, title, size=(550, 400))

        # Shareware check
        self.shareware = pShareware.pShareware()
        self.trial = self.shareware.checkTrial()

        # Menu
        menuBar = wx.MenuBar()
        menu = wx.Menu()
        menu.Append(4, "&About", "About")
        if self.trial:
            menu.Append(7, "&Register", "Register")
            
        menu.AppendSeparator()
        menu.Append(wx.ID_EXIT, "&Exit\tCtrl+Q", "Exit")
        menuBar.Append(menu, "&pDict")

        menu = wx.Menu()
        menu.Append(6, "&Toggle Online/Offline mode", \
                "Toggle Online/Offline mode")
        menuBar.Append(menu, "&Settings")

        self.SetMenuBar(menuBar)

        self.Bind(wx.EVT_MENU, self.onQuit, id=wx.ID_EXIT)
        self.Bind(wx.EVT_MENU, self.showAboutBox, id=4)
        self.Bind(wx.EVT_MENU, self.toggleNet, id=6)
        self.Bind(wx.EVT_MENU, self.showRegisterScreen, id=7)

        # Dirty hack for prefetching
        self.tmp_value = ""

        # Statusbar
        self.sb = self.CreateStatusBar()
        self.sb.SetFieldsCount(2)
        # Auto size both fields
        self.sb.SetStatusWidths([-3, -1])

        # Panel (Main window)
        panel = wx.Panel(self)
        panel.SetBackgroundColour('#d0d0d0')

        # Toggle Buttons for dictionary -> thesaurus
        self.toggle_dictionary = wx.ToggleButton(panel, 1, 'Dictionary')
        self.toggle_dictionary.SetValue(True)
        self.Bind(wx.EVT_TOGGLEBUTTON, self.toggleDict, id=1)

        self.toggle_thesaurus_de = wx.ToggleButton(panel, 2,
                'Thesaurus German')
        self.Bind(wx.EVT_TOGGLEBUTTON, self.toggleThesaurusDE, id=2)

        self.toggle_thesaurus_en = wx.ToggleButton(panel, 5,
                'Thesaurus English')
        self.Bind(wx.EVT_TOGGLEBUTTON, self.toggleThesaurusEN, id=5)

        self.toggle_word_definition = wx.ToggleButton(panel, 8,
                'Definition')
        self.Bind(wx.EVT_TOGGLEBUTTON, self.toggleWordDefinition, id=8)

        self.search_field = wx.SearchCtrl(panel, 3, '',
                style=wx.TE_PROCESS_ENTER)
        self.search_field.SetFocus()
        self.Bind(wx.EVT_TEXT_ENTER, self.search, id=3)
        self.Bind(wx.EVT_SEARCHCTRL_SEARCH_BTN, self.search, id=3)
        # Since not threaded, it takes a long time. Won't be on the released
        # version until done right.
        #self.Bind(wx.EVT_TEXT, self.UpdateChoices, id=3)

        # Insert the scrolled window inside the panel
        self.sw = wx.ScrolledWindow(panel, 
                style=wx.SUNKEN_BORDER | wx.HSCROLL | wx.VSCROLL)
        self.sw.SetBackgroundColour('#ececec')

        # Stacking the controls vertically using a sizer; 10px borders for
        # controls and 0px for the ScrolledWindow to fit it into the panel
        # smoothly
        sizer = wx.BoxSizer(wx.VERTICAL)
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add(self.toggle_dictionary, 0, wx.LEFT, 10)
        hbox.Add(self.toggle_thesaurus_de, 0, wx.LEFT, 10)
        hbox.Add(self.toggle_thesaurus_en, 0, wx.LEFT, 10)
        hbox.Add(self.toggle_word_definition, 0, wx.LEFT, 10)
        sizer.Add(hbox, 0, wx.ALL, 10)
        sizer.Add(self.search_field, 0, wx.ALL | wx.EXPAND, 10)
        
        # Display the greeter message
        font = wx.Font(18, wx.FONTFAMILY_ROMAN, wx.SLANT,
                weight=wx.FONTWEIGHT_LIGHT) 
        greet = wx.StaticText(self.sw, -1, "Type a word..",
                (25, 20)).SetFont(font)
        sizer.Add(self.sw, 10, wx.TOP | wx.LEFT | wx.RIGHT | wx.EXPAND, 0)

        # Icon
        iconFile = "pDict.ico"
        icon1 = wx.Icon(iconFile, wx.BITMAP_TYPE_ICO)
        self.SetIcon(icon1)
        

        # Center and auto-size the main window
        self.Center()
        panel.SetSizer(sizer)
        panel.Layout()

        # Initialize databases
        self.word_def = pWordDef.pWordDef()
        self.thesaurus = ThesaurusOffline.ThesaurusOffline()
        self.dictOff = DictOffline.DictOffline()
        self.dictOn = DictOnline.DictOnline()
        tmp = self.dictOn.search("test")
        if tmp != "offline":
            self.online = True
            self.sb.SetStatusText("Online mode", 1)
        else:
            self.online = False
            self.sb.SetStatusText("Offline mode", 1)