Beispiel #1
0
    def __init__(self, parent, id, title, style):
        """Construct the GUI from config file, and bind GUI events to
        their handlers.

        """
        # 读取sc2mafia.cfg
        self.readFromCfg()
        # 调用基类的构造函数
        wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=self.framesize, style=style)
        # 加载资源
        # self.resin = Resin(os.path.join(homepath,
        #        'res', self.prefer.getValue("iconset")))
        self.resin = Resin()
        # 图标
        self.SetIcon(self.resin.getIcon("notalon"))
        # 提示
        self.tips = wx.CreateFileTipProvider("Tips.txt", 0)
        self.showtips = int(self.config.get("other", "showtips"))
        if self.showtips:
            wx.CallAfter(self.ShowTips)  # 显示Tips的同时显示主界面
            # self.ShowTips()  # 与上面相反,显示Tips之后才显示主界面
        # 创建MenuBar
        self.createMenuBar()
        # 创建ToolBar
        self.createToolBar()
        # 创建StatusBar
        self.createStatusBar()
        # 创建主显示栏
        self.createMainWindow()
        # 绑定关闭窗口的方法
        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
        # 创建TaskBarIcon
        self.tbIcon = tbIcon(self)
Beispiel #2
0
class StartpageWindow(wx.Frame):
    """Main class of sc2mafia the start page, the create game page.
    All GUI logic is here.
    """

    def __init__(self, parent, id, title, style):
        """Construct the GUI from config file, and bind GUI events to
        their handlers.

        """
        # 读取sc2mafia.cfg
        self.readFromCfg()
        # 调用基类的构造函数
        wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=self.framesize, style=style)
        # 加载资源
        # self.resin = Resin(os.path.join(homepath,
        #        'res', self.prefer.getValue("iconset")))
        self.resin = Resin()
        # 图标
        self.SetIcon(self.resin.getIcon("notalon"))
        # 提示
        self.tips = wx.CreateFileTipProvider("Tips.txt", 0)
        self.showtips = int(self.config.get("other", "showtips"))
        if self.showtips:
            wx.CallAfter(self.ShowTips)  # 显示Tips的同时显示主界面
            # self.ShowTips()  # 与上面相反,显示Tips之后才显示主界面
        # 创建MenuBar
        self.createMenuBar()
        # 创建ToolBar
        self.createToolBar()
        # 创建StatusBar
        self.createStatusBar()
        # 创建主显示栏
        self.createMainWindow()
        # 绑定关闭窗口的方法
        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
        # 创建TaskBarIcon
        self.tbIcon = tbIcon(self)

    # -----------------创建主框架的相关函数------------------ #
    def readFromCfg(self):
        """读取配置文件

        """
        self.config = Config(os.path.join(homepath, "sc2mafia.cfg"))
        self.framesize = (int(self.config.get("frame", "width")), int(self.config.get("frame", "height")))

    def menuData(self):
        """菜单项数据

        """
        return (
            (u"程序", (u"退出", u"退出程序", self.OnCloseWindow)),
            (
                u"员工档案",
                (u"新建", u"在远程服务器新建一个员工档案", self.OnCreateStaff),
                (u"修改", u"修改一个员工档案", self.OnModifyStaff),
                (u"查看", u"查看所有员工档案", self.OnDisplayStaff),
                (u"筛选", u"筛选员工档案", self.OnFilterStaff),
            ),
            (u"工资", (u"工资单发送", "用邮件发送工资单", self.OnMailSalary)),
            (u"其他", (u"报销系统", u"在这里登录报销系统", self.OnOpenExpAccHtml)),
            (u"工具", (u"通讯录", u"快速查询通讯录的小工具", self.OnSearchAddr)),
            (
                u"帮助",
                (u"用户手册", u"用户手册", self.OnManual),
                ("", "", ""),
                (u"版权", u"本软件的版权信息", self.OnCopyRight),
                (u"关于作者", u"本软件作者的相关信息", self.OnAuthor),
                (u"关于本软件", u"本软件的相关信息", self.OnAbout),
            ),
        )

    def createMenuBar(self):
        """创建菜单栏

        """
        menuBar = wx.MenuBar()
        for eachMenuData in self.menuData():
            menuLabel = eachMenuData[0]
            menuItems = eachMenuData[1:]
            menuBar.Append(self.createMenu(menuItems), menuLabel)
            self.SetMenuBar(menuBar)

    def createMenu(self, menuData):
        """创建一个菜单 --从创建菜单栏函数中抽象出来的函数

        """
        menu = wx.Menu()
        for eachLabel, eachStatus, eachHandler in menuData:
            if not eachLabel:
                menu.AppendSeparator()
                continue
            menuItem = menu.Append(-1, eachLabel, eachStatus)
            self.Bind(wx.EVT_MENU, eachHandler, menuItem)
        return menu

    def toolBarData(self):
        """工具栏数据

        """
        return (
            (u"创建", "new.bmp", u"新建一个员工档案", self.OnCreateStaff),
            #                (u"修改", self.OnModifyStaff),
            (u"查看", "display.bmp", u"浏览", self.OnDisplayStaff),
            (u"筛选", "search.bmp", u"筛选", self.OnFilterStaff),
            ("", "", "", ""),
            (u"通讯录", "addr.bmp", u"搜索通讯录", self.OnSearchAddr),
        )

    def createToolBar(self):
        """创建工具栏

        """
        toolBar = self.CreateToolBar()
        for each in self.toolBarData():
            self.createSimpleTool(toolBar, *each)
        toolBar.Realize()

    def createSimpleTool(self, toolbar, label, filename, help, handler):
        """创建一个工具按钮  --从创建工具栏函数中抽象出来的函数

        """
        if not label:
            toolbar.AddSeparator()
            return
        bmp = wx.Image(filename, wx.BITMAP_TYPE_BMP).ConvertToBitmap()
        tool = toolbar.AddSimpleTool(-1, bmp, label, help)
        self.Bind(wx.EVT_MENU, handler, tool)

    def createMainWindow(self):
        """创建主显示窗口

        """
        pass

    # 显示每日提示
    def ShowTips(self):
        """Shows the tips window on startup; returns False if the option to
        turn off tips is checked.

        """
        # constructs the tip (wx.ShowTip), which returns whether or not the
        # user checked the 'show tips' box
        if wx.ShowTip(None, self.tips, True):
            btmp = 1
            print 1
        else:
            btmp = 0
            print 0
        self.config.set("other", "showtips", btmp)
        return self.config.get("other", "showtips")

    # ----------------------主框架的事件响应函数------------------------#
    def OnCreateStaff(self, event):
        pass

    def OnModifyStaff(self, event):
        pass

    def OnDisplayStaff(self, event):
        pass

    def OnFilterStaff(self, event):
        pass

    def OnMailSalary(self, event):
        pass

    def OnOpenExpAccHtml(self, event):
        pass

    def OnSearchAddr(self, event):
        pass

    def OnManual(self, event):
        pass

    def OnCopyRight(self, event):
        pass

    def OnAuthor(self, event):
        pass

    def OnAbout(self, event):
        pass

    def createStatusBar(self):
        self.statusBar = self.CreateStatusBar()
        self.statusBar.SetFieldsCount(3)
        self.statusBar.SetStatusWidths([-1, -2, -3])

    # Sash位置变动
    def OnSashPosChanged(self, event):
        """Handler for when the splitter sash,
        who divided the `tree` and the `content`, is moved.

        """
        pass

    #        pos = self.splitter.GetSashPosition()
    #        self.config.setValue("sashposition", pos)

    def OnSelChanged(self):
        pass

    # 关闭主框架,清理资源 # TODO:devo
    def OnCloseWindow(self, event):
        self.tbIcon.Destroy()
        self.Destroy()
Beispiel #3
0
class HumanResourceWindow(wx.Frame):
    """Main class of interest in HRS. Frame for the HRS application.

    All GUI logic is here.

    """

    def __init__(self, parent, id, title, style):
        """Construct the GUI from preferences, and bind GUI events to
        their handlers.

        """
        # 读取Preferences
        self.readFromPreferences()
        # 调用基类的构造函数
        wx.Frame.__init__(self, parent, wx.ID_ANY, title,
                size=self.framesize, style=style)
        # 加载资源
        #self.resin = Resin(os.path.join(homepath,
        #        'res', self.prefer.getValue("iconset")))
        self.resin = Resin()
        # 图标
        self.SetIcon(self.resin.getIcon("notalon"))
        # 提示
        self.tips = wx.CreateFileTipProvider("Tips.txt", 0)
        self.showtips = self.prefer.getValue("show-tips")
        if self.showtips:
            wx.CallAfter(self.ShowTips)  # 显示Tips的同时显示主界面
            #self.ShowTips()  # 显示Tips之后才显示主界面
        # 创建MenuBar
        self.createMenuBar()
        # 创建ToolBar
        self.createToolBar()
        # 创建StatusBar
        self.createStatusBar()
        # 创建主显示栏
        self.createMainWindow()
        # 绑定关闭窗口的方法
        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
        # 创建TaskBarIcon
        self.tbIcon = tbIcon(self)

    # -----------------创建主框架的相关函数------------------ #
    def readFromPreferences(self):
        """读取配置文件

        """
        self.prefer = HRSPreferences(os.path.join(homepath, "preferences.xml"))
        self.framesize = (self.prefer.getValue("framewidth"),
                self.prefer.getValue("frameheight"))

    def menuData(self):
        """菜单项数据

        """
        return ((u"程序",
                    (u"退出", u"退出程序", self.OnCloseWindow)),
                (u"员工档案",
                    (u"新建", u"在远程服务器新建一个员工档案", self.OnCreateStaff),
                    (u"修改", u"修改一个员工档案", self.OnModifyStaff),
                    (u"查看", u"查看所有员工档案", self.OnDisplayStaff),
                    (u"筛选", u"筛选员工档案", self.OnFilterStaff)),
                (u"工资",
                    (u"工资单发送", "用邮件发送工资单", self.OnMailSalary),
                    ),
                (u"其他",
                    (u"报销系统", u"在这里登录报销系统", self.OnOpenExpAccHtml)),
                (u"工具",
                    (u"通讯录", u"快速查询通讯录的小工具", self.OnSearchAddr)),
                (u"帮助",
                    (u"用户手册", u"用户手册", self.OnManual),
                    ("", "", ""),
                    (u"版权", u"本软件的版权信息", self.OnCopyRight),
                    (u"关于作者", u"本软件作者的相关信息", self.OnAuthor),
                    (u"关于本软件", u"本软件的相关信息", self.OnAbout)),
                )

    def createMenuBar(self):
        """创建菜单栏

        """
        menuBar = wx.MenuBar()
        for eachMenuData in self.menuData():
            menuLabel = eachMenuData[0]
            menuItems = eachMenuData[1:]
            menuBar.Append(self.createMenu(menuItems), menuLabel)
            self.SetMenuBar(menuBar)
#        self.mainSizer.Add(menuBar, 0, wx.EXPAND)
#        self.mainSizer.Add(self.mainPanel, 1, wx.EXPAND)

    def createMenu(self, menuData):
        """创建一个菜单 --从创建菜单栏函数中抽象出来的函数

        """
        menu = wx.Menu()
        for eachLabel, eachStatus, eachHandler in menuData:
            if not eachLabel:
                menu.AppendSeparator()
                continue
            menuItem = menu.Append(-1, eachLabel, eachStatus)
            self.Bind(wx.EVT_MENU, eachHandler, menuItem)
        return menu

    def toolBarData(self):
        """工具栏数据

        """
        return ((u"创建", "new.bmp", u"新建一个员工档案", self.OnCreateStaff),
#                (u"修改", self.OnModifyStaff),
                (u"查看", "display.bmp", u"浏览", self.OnDisplayStaff),
                (u"筛选", "search.bmp", u"筛选", self.OnFilterStaff),
                ("", "", "", ""),
                (u"通讯录", "addr.bmp", u"搜索通讯录", self.OnSearchAddr),
               )

    def createToolBar(self):
        """创建工具栏

        """
        toolBar = self.CreateToolBar()
        for each in self.toolBarData():
            self.createSimpleTool(toolBar, *each)
        toolBar.Realize()

    def createSimpleTool(self, toolbar, label, filename, help, handler):
        """创建一个工具按钮  --从创建工具栏函数中抽象出来的函数

        """
        if not label:
            toolbar.AddSeparator()
            return
        bmp = wx.Image(filename, wx.BITMAP_TYPE_BMP).ConvertToBitmap()
        tool = toolbar.AddSimpleTool(-1, bmp, label, help)
        self.Bind(wx.EVT_MENU, handler, tool)

    def createMainWindow(self):
        """创建主显示窗口

        """
        # 主面板&主Sizer (contains MenuBar)
        self.mainPanel = wx.Panel(self, wx.ID_ANY)
        self.mainSizer = wx.BoxSizer(wx.VERTICAL)
        self.mainPanel.SetSizer(self.mainSizer)
        # Splitter
        self.splitter = wx.SplitterWindow(self.mainPanel,
                                style=wx.SP_LIVE_UPDATE | wx.SP_3DSASH)
        self.splitter.SetMinimumPaneSize(200)
        self.mainSizer.Add(self.splitter, 2, wx.EXPAND)\
                # second number has to be '2' in case the splitter can expand
                # 设为0,对象将不改变尺寸;大于0,则sizer中的child
                # 根据因数分割sizer的总尺寸
        self.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGED, self.OnSashPosChanged)
        # 左面板
        self.lPanel = wx.Panel(self.splitter, wx.NewId())
        # 右面板
        self.rPanel = wx.Panel(self.splitter, wx.NewId())
        # TreeCtrl
        self.tree = wx.TreeCtrl(self.lPanel, style=wx.TR_EDIT_LABELS)
        # TextCtrl
        self.content = wx.TextCtrl(self.rPanel, wx.NewId())
        # 左Sizer
        self.lBox = wx.BoxSizer(wx.VERTICAL)
        self.lBox.Add(self.tree, wx.NewId(), wx.EXPAND)
        self.lPanel.SetSizer(self.lBox)
        # 右Sizer
        self.rBox = wx.BoxSizer(wx.VERTICAL)
        self.rBox.Add(self.content, wx.NewId(), wx.EXPAND)
        self.rPanel.SetSizer(self.rBox)
        # 绑定选中Tree元素事件
        self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelChanged, self.tree)
        # Split
        sashPosition = self.prefer.getValue("sashposition")
        self.splitter.SplitVertically(self.lPanel, self.rPanel, sashPosition)

    # 显示每日提示
    def ShowTips(self):
        """Shows the tips window on startup; returns False if the option to
        turn off tips is checked.

        """
        # constructs the tip (wx.ShowTip), which returns whether or not the
        # user checked the 'show tips' box
        self.prefer.setValue("show-tips", wx.ShowTip(None, self.tips, True))
        return self.prefer.getValue("show-tips")

    # ----------------------主框架的事件响应函数------------------------#
    def OnCreateStaff(self, event):
        pass

    def OnModifyStaff(self, event):
        pass

    def OnDisplayStaff(self, event):
        pass

    def OnFilterStaff(self, event):
        pass

    def OnMailSalary(self, event):
        from apps.mail_salary import mail_salary
        self.mail_salary = mail_salary.MailSalaryFrame(self)
        self.mail_salary.SetIcon(self.resin.getIcon("wx"))
        self.mail_salary.Show()

    def OnOpenExpAccHtml(self, event):
        pass

    def OnSearchAddr(self, event):
        from apps.addr_book import addr_book
        self.addr_book = addr_book.AddrBookFrame(self)
        self.addr_book.Show()

    def OnManual(self, event):
        pass

    def OnCopyRight(self, event):
        pass

    def OnAuthor(self, event):
        pass

    def OnAbout(self, event):
        pass

    def createStatusBar(self):
        self.statusBar = self.CreateStatusBar()
        self.statusBar.SetFieldsCount(3)
        self.statusBar.SetStatusWidths([-1, -2, -3])

    # Sash位置变动
    def OnSashPosChanged(self, event):
        """Handler for when the splitter sash,
        who divided the `tree` and the `content`, is moved.

        """
        pos = self.splitter.GetSashPosition()
        self.prefer.setValue("sashposition", pos)

    def OnSelChanged(self):
        pass

    # 关闭主框架,清理资源 # TODO:devo
    def OnCloseWindow(self, event):
        self.tbIcon.Destroy()
        self.Destroy()