Пример #1
0
    def CreateWidgets(self):
        self.nameLabel = QLabel("姓名:")
        self.birthdayLabel = QLabel("出生年月:")
        self.birthdayEditLabel = MyLabel("1900-01-01")
        self.birthdayEditLabel.setFrameStyle(QFrame.Panel|QFrame.Sunken)
        self.addressLabel = QLabel("地址:")
        self.deathdayLabel = QLabel("去世年月:")
        self.deathdayEditLabel = MyLabel("- - - ")
        self.deathdayEditLabel.setFrameStyle(QFrame.Panel|QFrame.Sunken)

        self.nameEdit = QLineEdit()
        self.addressEdit = QLineEdit()
        self.buttons = QDialogButtonBox(
            QDialogButtonBox.Ok | QDialogButtonBox.Cancel,
            Qt.Horizontal, self)

        self.confirmButton = QPushButton("确定")
        self.cancelButton = QPushButton("取消")

        self.birthCalendar = QCalendarWidget()
        self.birthCalendar.setWindowTitle("出生年月")
        self.birthCalendar.setWindowIcon(QIcon("./icon/calendar1.png"))
        self.birthCalendar.hide()
        self.deathCalendar = QCalendarWidget()
        self.deathCalendar.setWindowTitle("去世年月")
        self.deathCalendar.setWindowIcon(QIcon("./icon/calendar2.png"))
        self.deathCalendar.hide()

        self.deadCheckBox = QCheckBox("去世")  # 默认未去世
        self.marryCheckBox = QCheckBox("结婚")
        self.marryCheckBox.toggle()  # 默认结婚
Пример #2
0
 def createUI(self):
     self.ui = Ui_MainWindow()
     self.ui.setupUi(self)
     self.nowTimeText = time.strftime(
         u'%H:%M:%S'.encode('utf-8')).decode('utf-8')
     self.ui.labelStartTime.setText(self.nowTimeText)
     self.ui.labelEndTime.setText('')
     self.ui.lineEditTimeCount.setFocus()
     self.msgLabel = MyLabel(u'<h1>时间到!</h1><img src=":/img/38.gif"/>')
     self.msgLabel.hide()
     self.msgLabel.setBuddy(self)
     self.ui.btnComplete.setDisabled(True)
     self.ui.btnDiscard.setDisabled(True)
Пример #3
0
    def spawn_heide_console_window(self):
        self.active_window = Window.CONSOLE

        self.output_window = Toplevel()
        self.output_window.title("HEIDE Console")
        self.output_window.minsize(height=425, width=650)
        self.output_window.maxsize(height=425, width=650)

        self.output_window.protocol("WM_DELETE_WINDOW", self.close_console)

        # console window spawn location
        w = self.output_window.winfo_screenwidth()
        h = self.output_window.winfo_screenheight()
        output_wind_size = \
            tuple(int(_) for _ in
                  self.output_window.geometry().split('+')[0].split('x'))
        x = w / 2 - output_wind_size[0] / 2
        y = h / 2 - output_wind_size[1] / 2
        self.output_window.geometry("%dx%d+%d+%d" % (output_wind_size +
                                                     (x, y)))

        self.output_window.grab_set()

        text_frame = Frame(self.output_window, padx=20)
        text_frame.grid(row=0, column=0)

        Label(text_frame, text="Output").pack(anchor=W)

        self.output_text = ScrolledText(text_frame, height=23, width=85)
        self.output_text.pack()

        load_bar_frame = Frame(self.output_window, padx=20)
        load_bar_frame.grid(row=1, column=0)

        self.load_bar_label = MyLabel(load_bar_frame,
                                      "../imgs/loading_bar.gif")
        self.load_bar_label.pack()

        button_frame = Frame(self.output_window, padx=20)
        button_frame.grid(row=2, column=0)

        Button(button_frame, text="Close",
               command=self.close_console).grid(row=0, column=0)
        Button(button_frame,
               text="Save",
               command=self.heide.heide_save_console_output).grid(row=0,
                                                                  column=1)

        self.output_text.configure(state="disabled")

        self.output_window.update()
Пример #4
0
 def addDialogRow(self, bl, title, val):
     bh = self.getDialogRow()
     bh.add_widget(MyLabel(text="%s:" % title))
     ti = TextInput(text=str(val), height=cm(1))
     bh.add_widget(ti)
     bl.add_widget(bh)
     return bl, ti
Пример #5
0
 def addFriend(self, name, signature, pic_path):
     item_widget = QListWidgetItem()
     item_widget.setSizeHint(QSize(90, 65))
     self.list.addItem(item_widget)
     label = MyLabel(name, signature, pic_path)
     self.friendList[name] = label
     self.list.setItemWidget(item_widget, label)
Пример #6
0
 def createUI(self):
     self.ui = Ui_MainWindow()
     self.ui.setupUi(self)
     self.nowTimeText = time.strftime(u'%H:%M:%S'.encode('utf-8')).decode('utf-8') 
     self.ui.labelStartTime.setText(self.nowTimeText)
     self.ui.labelEndTime.setText('')
     self.ui.lineEditTimeCount.setFocus()
     self.msgLabel = MyLabel(u'<h1>时间到!</h1><img src=":/img/38.gif"/>')
     self.msgLabel.hide()
     self.msgLabel.setBuddy(self)
     self.ui.btnComplete.setDisabled(True)
     self.ui.btnDiscard.setDisabled(True)
Пример #7
0
    def spawn_heide_console_window(self):
        self.active_window = Window.CONSOLE

        self.output_window = Toplevel()
        self.output_window.title("HEIDE Console")
        self.output_window.minsize(height=425, width=650)
        self.output_window.maxsize(height=425, width=650)

        self.output_window.protocol("WM_DELETE_WINDOW", self.close_console)

        # console window spawn location
        w = self.output_window.winfo_screenwidth()
        h = self.output_window.winfo_screenheight()
        output_wind_size = \
            tuple(int(_) for _ in
                  self.output_window.geometry().split('+')[0].split('x'))
        x = w/2 - output_wind_size[0]/2
        y = h/2 - output_wind_size[1]/2
        self.output_window.geometry("%dx%d+%d+%d" %
                                       (output_wind_size + (x, y)))

        self.output_window.grab_set()

        text_frame = Frame(self.output_window, padx=20)
        text_frame.grid(row=0, column=0)

        Label(text_frame, text="Output").pack(anchor=W)

        self.output_text = ScrolledText(text_frame, height=23, width=85)
        self.output_text.pack()

        load_bar_frame = Frame(self.output_window, padx=20)
        load_bar_frame.grid(row=1, column=0)

        self.load_bar_label = MyLabel(load_bar_frame,
                                         "../imgs/loading_bar.gif")
        self.load_bar_label.pack()

        button_frame = Frame(self.output_window, padx=20)
        button_frame.grid(row=2, column=0)

        Button(button_frame, text="Close",
               command=self.close_console).grid(row=0, column=0)
        Button(button_frame, text="Save",
               command=self.heide.heide_save_console_output).grid(row=0,
                                                                  column=1)

        self.output_text.configure(state="disabled")

        self.output_window.update()
Пример #8
0
    def addSettingsDialogPart(self, bl, inWConf=None):

        presetVals = []
        for s in self.defSettings:
            presetVals.append(s['name'])
        presetDef = presetVals[0]

        #bl = BoxLayout(orientation="vertical")
        bh = self.getDialogRow()
        bh.add_widget(MyLabel(text="Preset:"))
        self.spPreset = Spinner(text=presetDef,
                                values=presetVals,
                                height=cm(1))
        bh.add_widget(self.spPreset)
        bl.add_widget(bh)
        self.spPreset.bind(text=self.on_presetChange)

        if inWConf:
            self.spPreset.text = inWConf['atr']['name']

        bl, self.ti_title = self.addDialogRow(
            bl, "Title", "" if inWConf == None else inWConf['atr']['title'])
        bl, self.ti_min = self.addDialogRow(
            bl, "Min value",
            -175 if inWConf == None else str(inWConf['atr']['min']))
        bl, self.ti_max = self.addDialogRow(
            bl, "Max value",
            175 if inWConf == None else str(inWConf['atr']['max']))
        bl, self.ti_tick = self.addDialogRow(
            bl, "Tick", 25 if inWConf == None else str(inWConf['atr']['tick']))
        bl, self.ti_subtick = self.addDialogRow(
            bl, "Sub ticks",
            6 if inWConf == None else str(inWConf['atr']['subtick']))
        bl, self.ti_start_angle = self.addDialogRow(
            bl, "Start angle",
            -170 if inWConf == None else str(inWConf['atr']['start_angle']))
        bl, self.ti_end_angle = self.addDialogRow(
            bl, "End angle",
            170 if inWConf == None else str(inWConf['atr']['end_angle']))
        bl, self.ti_value_font_size = self.addDialogRow(
            bl, "Value size",
            23 if inWConf == None else str(inWConf['atr']['value_font_size']))
        bl, self.ti_label_font_size = self.addDialogRow(
            bl, "Labels size",
            50 if inWConf == None else str(inWConf['atr']['label_font_size']))

        return bl
Пример #9
0
class gui_module:
    def __init__(self, heide):
        self.heide = heide
        self.active_window = None

        self.heide_version = "HEIDE v0.5"
        self.root = Tk()

        self.logo = None

        self.key_bindings()
        self.root.protocol("WM_DELETE_WINDOW", self.heide.heide_quit)

        self.param_custom_font = tkinter.font.Font()
        self.data_custom_font = tkinter.font.Font()
        self.alg_custom_font = tkinter.font.Font()

        self.param_label = Label
        self.data_label = Label
        self.alg_label = Label

        self.__command_label = Label
        self.__command_label_txt = StringVar()

        self.output_window = Toplevel
        self.output_text = ScrolledText
        self.__photo = PhotoImage
        self.load_bar_label = MyLabel

        self.settings_window = Toplevel
        self.__he_src_entry = Entry
        self.__max_num_subpr_entry = Entry
        self.__display_mem_usage = IntVar
        self.__display_mem_usage_checkbutton = Checkbutton

        self.__new_project_window = Toplevel
        self.he_src_entry_np = Entry
        self.project_name_entry = Entry
        self.project_loc_entry = Entry
        self.existing_params_entry = Entry
        self.existing_data_entry = Entry
        self.existing_alg_entry = Entry

    def key_bindings(self):
        keys =["Control_L", "Control_R",
               "s",
               "p", "P",
               "d", "D",
               "a", "A",
               "o",
               "n",
               "C",
               "q",
               "F1"]
        for key in keys:
            self.root.bind("<KeyPress-" + key + ">",
                           self.heide.edit_mod.key_press)
            self.root.bind("<KeyRelease-" + key + ">",
                           self.heide.edit_mod.key_release)


    def spawn_start_up_window(self):
        self.active_window = Window.START_UP

        # Root widget creation for startup window
        self.root.wm_title(self.heide_version + " Startup Window")
        self.root.wm_minsize(height=250, width=500)
        self.root.wm_maxsize(height=250, width=500)
        self.logo = Image("photo", file="./imgs/logo.gif")
        self.root.tk.call("wm", "iconphoto", self.root._w,
                          "-default", self.logo)

        logo_frame = Frame(self.root, height=250, width=250, padx=10, pady=50)
        logo_frame.grid(row=0, column=0)
        Label(logo_frame, image=self.logo).pack()

        text_frame = Frame(self.root, height=250, width=250, padx=10, pady=0)
        text_frame.grid(row=0, column=1)
        Label(text_frame, text=self.heide_version,
              font=("Helvetica", 30)).pack(anchor=W)

        self.__command_label = Label(text_frame,
                                     textvariable=self.__command_label_txt,
                                     wraplength=250, justify=LEFT)
        self.__command_label.pack()

        self.set_command_label("Initializing HEIDE ...")

        self.root.update()


    def set_command_label(self, text):
        self.__command_label_txt.set(text)

    def display_start_up_error(self, set_txt):
        self.__command_label.configure(fg="red")
        self.set_command_label(set_txt)

        self.root.update()

        # self.root.wait_window()
        self.root.quit()

        sys.exit()

    def display_error(self, error_type, error):
        tkinter.messagebox.showerror(error_type, error)
        return

    def spawn_heide_window(self):
        self.active_window = Window.HEIDE
        # Root widget creation for HEIDE GUI
        self.root.wm_title(self.heide_version)
        self.root.wm_minsize(height=927, width=1500)
        self.root.wm_maxsize(height=927, width=1500)

        # Create the root widgets menubar
        menubar = Menu(self.root)

        # add 'File' dropdown menu to menubar
        file_menu = Menu(menubar, tearoff=0)
        menubar.add_cascade(label="File", menu=file_menu)

        file_menu.add_command(label="New Project   CTRL+n",
                              command=self.heide.heide_new_project)

        # create submenu for opening files or projects
        open_menu = Menu(file_menu, tearoff=0)
        open_menu.add_command(label="Open Project       CTRL+o",
                              command=lambda: self.heide.heide_open(
                                  File_Type.PROJ_FILE, None))
        open_menu.add_command(label="Open Param File",
                              command=lambda: self.heide.heide_open(
                                  File_Type.PARAM_FILE, None))
        open_menu.add_command(label="Open Data File",
                              command=lambda: self.heide.heide_open(
                                  File_Type.DATA_FILE, None))
        open_menu.add_command(label="Open Alg File",
                              command=lambda: self.heide.heide_open(
                                  File_Type.ALG_FILE, None))
        file_menu.add_cascade(label="Open", menu=open_menu, underline=0)

        # create submenu for saving files
        save_menu = Menu(file_menu, tearoff=0)
        save_menu.add_command(label="Save Project".ljust(20) + "CTRL+s",
                              command=lambda: self.heide.heide_save(
                                  File_Type.PROJ_FILE))
        save_menu.add_command(label="Save Params".ljust(18) + "CTRL+p",
                              command=lambda: self.heide.heide_save(
                                  File_Type.PARAM_FILE))
        save_menu.add_command(label="Save Data".ljust(20) + "CTRL+d",
                              command=lambda: self.heide.heide_save(
                                  File_Type.DATA_FILE))
        save_menu.add_command(label="Save Alg".ljust(21) + "CTRL+a",
                              command=lambda: self.heide.heide_save(
                                  File_Type.ALG_FILE))
        file_menu.add_cascade(label="Save", menu=save_menu, underline=0)

        # create submenu for save as
        save_as_menu = Menu(file_menu, tearoff=0)
        save_as_menu.add_command(label="Save Params As...".ljust(20) + "CTRL+P",
                                 command=lambda: self.heide.heide_save_as(
                                     File_Type.PARAM_FILE))
        save_as_menu.add_command(label="Save Data As...".ljust(22) + "CTRL+D",
                                 command=lambda: self.heide.heide_save_as(
                                     File_Type.DATA_FILE))
        save_as_menu.add_command(label="Save Alg As...".ljust(23) + "CTRL+A",
                                 command=lambda: self.heide.heide_save_as(
                                     File_Type.ALG_FILE))
        file_menu.add_cascade(label="Save As...", menu=save_as_menu,
                              underline=0)

        # create submenu for import
        import_menu = Menu(file_menu, tearoff=0)
        import_menu.add_command(label="Import Params",
                                command=lambda: self.heide.heide_import(
                                    File_Type.PARAM_FILE))
        import_menu.add_command(label="Import Data",
                                command=lambda: self.heide.heide_import(
                                    File_Type.DATA_FILE))
        import_menu.add_command(label="Import Alg",
                                command=lambda: self.heide.heide_import(
                                    File_Type.ALG_FILE))
        file_menu.add_cascade(label="Import", menu=import_menu,
                              underline=0)

        file_menu.add_command(label="Close Project   CTRL+C",
                              command=self.heide.heide_close_project)

        file_menu.add_command(label="Settings",
                              command=self.spawn_settings_window)

        file_menu.add_separator()

        file_menu.add_command(label="Quit               CTRL+q",
                              command=self.heide.heide_quit)

        # Add 'Run' dropdown menu to menubar
        run_menu = Menu(menubar, tearoff=0)
        menubar.add_cascade(label="Run", menu=run_menu)

        run_menu.add_command(label="Run    F1",
                             command=self.heide.heide_run)

        # Tell root to display menubar
        self.root.config(menu=menubar)

        # The GUI is split into 3 frames: the parameter frame, data frame, the
        # algorithm frame.
        #
        #     - Parameter and Data Frame -
        #         Contains 'editors' where HElib setup parameters and data with
        #         which to perform computations on can be specified
        #
        #     - Algorithm Frame -
        #         Contains an 'editor' where the algorithm for computation is
        #         specified. The algorithm will be run on the data in the 'data
        #         editor' after it has been encrypted using the parameters
        #         specified in the 'parameter editor'

        param_and_data_frame = Frame(self.root, height=25, width=50, pady=15,
                                     padx=20)
        param_and_data_frame.grid(row=0, column=0)

        alg_frame = Frame(self.root, height=25, width=50, pady=15, padx=20)
        alg_frame.grid(row=0, column=1)

        keyboard_keys = ["Cancel",
                         "BackSpace",
                         "Tab",
                         "Return",
                         "Shift_L",
                         "Control_L",
                         "Alt_L",
                         "Shift_R",
                         "Control_R",
                         "Alt_R",
                         "Escape",
                         "Insert",
                         "Delete"]

        self.param_label = Label(param_and_data_frame,
                                 text="Parameter Editor",
                                 font=self.param_custom_font).pack(anchor=W)
        param_editor = ScrolledText(param_and_data_frame, height=25, width=85,
                                    undo=True)
        param_editor.bind("<Key>", self.heide.edit_mod.param_edit_modified)
        for key in keyboard_keys:
            param_editor.bind(key, self.heide.edit_mod.param_edit_modified)
        param_editor.pack()

        Frame(param_and_data_frame, height=50).pack()

        self.data_label = Label(param_and_data_frame,
                                text="Data Editor",
                                font=self.data_custom_font).pack(anchor=W)
        data_editor = ScrolledText(param_and_data_frame, height=25, width=85,
                                   undo=True)
        data_editor.bind("<Key>", self.heide.edit_mod.data_edit_modified)
        for key in keyboard_keys:
            data_editor.bind(key, self.heide.edit_mod.data_edit_modified)
        data_editor.pack()

        self.alg_label = Label(alg_frame,
                               text="Algorithm Editor",
                               font=self.alg_custom_font).pack(anchor=W)
        alg_editor = ScrolledText(alg_frame, height=55, width=113, undo=True)
        alg_editor.bind("<Key>", self.heide.edit_mod.alg_edit_modified)
        for key in keyboard_keys:
            alg_editor.bind(key, self.heide.edit_mod.alg_edit_modified)
        alg_editor.pack()

        # set editor manager variables
        self.heide.edit_mod.set_editors(param_editor, data_editor, alg_editor)

        """
        Start mainloop, which will wait for user to do something
        """
        self.root.mainloop()

    def spawn_settings_window(self):
        self.active_window = Window.SETTINGS
        self.settings_window = Toplevel(padx=20, pady=20)
        self.settings_window.title("HEIDE Settings")
        self.settings_window.minsize(height=225, width=375)
        self.settings_window.maxsize(height=225, width=375)

        # setting window spawn location
        w = self.settings_window.winfo_screenwidth()
        h = self.settings_window.winfo_screenheight()
        settings_size = \
            tuple(int(_) for _ in
                  self.settings_window.geometry().split('+')[0].split('x'))
        x = w/2 - settings_size[0]/2
        y = h/2 - settings_size[1]/2
        self.settings_window.geometry("%dx%d+%d+%d" % (settings_size + (x, y)))

        self.settings_window.grab_set()

        Label(self.settings_window, text="Makefile Locations",
              font=("Helvetica", 15), anchor=W).grid(row=0, column=0)

        Label(self.settings_window, text="HE Source Code:").grid(row=1,
                                                                   column=0,
                                                                   sticky=W)
        self.__he_src_entry = Entry(self.settings_window)
        self.__he_src_entry.grid(row=1, column=1, sticky=W)
        self.__he_src_entry.insert(0, self.heide.set_mod.he_src)

        Label(self.settings_window, text="Run Settings",
              font=("Helvetica", 15), anchor=W).grid(row=2, column=0)

        Label(self.settings_window, text="Max # Subprocesses:").grid(row=3,
                                                                   column=0,
                                                                   sticky=W)
        self.__max_num_subpr_entry = Entry(self.settings_window)
        self.__max_num_subpr_entry.grid(row=3, column=1, sticky=W)
        self.__max_num_subpr_entry.insert(0, self.heide.set_mod.max_num_subpr)

        self.__display_mem_usage = IntVar()
        Label(self.settings_window, text="Display Memory Usage:").grid(row=4,
                                                                   column=0,
                                                                   sticky=W)
        self.__display_mem_usage_checkbutton = Checkbutton(self.settings_window,
                               variable=self.__display_mem_usage)
        if self.heide.set_mod.display_mem_usage:
            self.__display_mem_usage_checkbutton.select()
        self.__display_mem_usage_checkbutton.grid(row=4, column=1, sticky=W)

        Button(self.settings_window, text="Close",
               command=self.close_settings).grid(row=5, column=0, pady=20)
        Button(self.settings_window, text="Apply",
               command=self.heide.set_mod.apply_settings).grid(row=5, column=1,
                                                               pady=30)

        self.settings_window.update()

    def close_settings(self):
        self.active_window = Window.HEIDE
        self.settings_window.destroy()

    def get_settings(self):
        return json.dumps({"he_src": self.__he_src_entry.get(),
                           "max_num_subpr" :
                               int(self.__max_num_subpr_entry.get()),
                           "display_mem_usage" :
                               bool(self.__display_mem_usage.get())})

    def spawn_heide_console_window(self):
        self.active_window = Window.CONSOLE

        self.output_window = Toplevel()
        self.output_window.title("HEIDE Console")
        self.output_window.minsize(height=425, width=650)
        self.output_window.maxsize(height=425, width=650)

        self.output_window.protocol("WM_DELETE_WINDOW", self.close_console)

        # console window spawn location
        w = self.output_window.winfo_screenwidth()
        h = self.output_window.winfo_screenheight()
        output_wind_size = \
            tuple(int(_) for _ in
                  self.output_window.geometry().split('+')[0].split('x'))
        x = w/2 - output_wind_size[0]/2
        y = h/2 - output_wind_size[1]/2
        self.output_window.geometry("%dx%d+%d+%d" %
                                       (output_wind_size + (x, y)))

        self.output_window.grab_set()

        text_frame = Frame(self.output_window, padx=20)
        text_frame.grid(row=0, column=0)

        Label(text_frame, text="Output").pack(anchor=W)

        self.output_text = ScrolledText(text_frame, height=23, width=85)
        self.output_text.pack()

        load_bar_frame = Frame(self.output_window, padx=20)
        load_bar_frame.grid(row=1, column=0)

        self.load_bar_label = MyLabel(load_bar_frame,
                                         "../imgs/loading_bar.gif")
        self.load_bar_label.pack()

        button_frame = Frame(self.output_window, padx=20)
        button_frame.grid(row=2, column=0)

        Button(button_frame, text="Close",
               command=self.close_console).grid(row=0, column=0)
        Button(button_frame, text="Save",
               command=self.heide.heide_save_console_output).grid(row=0,
                                                                  column=1)

        self.output_text.configure(state="disabled")

        self.output_window.update()


    def close_console(self):
        self.active_window = Window.HEIDE
        self.output_window.destroy()

        os.chdir(self.heide.og_dir)

        # terminate all currently running processes
        for proc in self.heide.running_processes:
            proc.terminate()

    def heide_console_display_result(self, config, ret_val, out, err):
        if ret_val == 0:
            self.output_text.configure(state="normal")
            self.output_text.insert("end",
                                        "/***** CONFIGURATION *****/\n\n")
            self.output_text.insert("end", config)

            self.output_text.insert("end",
                                        "\n/***** OUTPUT *****/\n\n")
            self.output_text.insert("end", out)
            self.output_text.insert("end", "\n" + "#" * 80 + "\n")
            self.output_text.configure(state="disabled")
        else:
            self.output_text.configure(state="normal")
            self.output_text.insert("end",
                                        "/***** CONFIGURATION *****/\n\n")
            self.output_text.insert("end", config)
            self.output_text.insert("end", out)
            self.output_text.insert("end", "\n" + "#" * 80 + "\n")
            self.output_text.insert("end",
                                        "/***** An ERROR has occurred *****/\n")
            self.output_text.insert("end", err)
            self.output_text.insert("end", "\n" + "#" * 80 + "\n")
            self.output_text.configure(state="disabled")

        self.output_window.update()

    def spawn_new_project_window(self):
        self.active_window = Window.NEW_PROJECT
        self.__new_project_window = Toplevel(padx=20, pady=20)
        self.__new_project_window.title("New Project")
        self.__new_project_window.minsize(height=350, width=405)
        self.__new_project_window.maxsize(height=350, width=405)

        # new project window spawn location
        w = self.__new_project_window.winfo_screenwidth()
        h = self.__new_project_window.winfo_screenheight()
        new_proj_wind_size = \
            tuple(int(_) for _ in
                  self.__new_project_window.geometry().split('+')[0].split('x'))
        x = w/2 - new_proj_wind_size[0]/2
        y = h/2 - new_proj_wind_size[1]/2
        self.__new_project_window.geometry("%dx%d+%d+%d" %
                                       (new_proj_wind_size + (x, y)))

        self.__new_project_window.grab_set()

        Label(self.__new_project_window, text="Makefile Locations",
              font=("Helvetica", 15)).grid(row=0, column=0, sticky=W)

        Label(self.__new_project_window,
              text="HE Source Code:").grid(row=1, column=0, sticky=W)
        self.he_src_entry_np = Entry(self.__new_project_window)
        self.he_src_entry_np.grid(row=1, column=1, sticky=W)
        self.he_src_entry_np.insert(0, self.heide.set_mod.he_src)

        Label(self.__new_project_window, text="Project Details",
              font=("Helvetica", 15)).grid(row=2, column=0, sticky=W)

        Label(self.__new_project_window,
              text="Project Name:").grid(row=3, column=0, sticky=W)
        self.project_name_entry = Entry(self.__new_project_window)
        self.project_name_entry.grid(row=3, column=1, sticky=W)

        Label(self.__new_project_window,
              text="Project Location:").grid(row=4, column=0, sticky=W)
        self.project_loc_entry = Entry(self.__new_project_window)
        self.project_loc_entry.grid(row=4, column=1, sticky=W)
        self.project_loc_entry.insert(0, self.heide.set_mod.heide_proj_dir)

        Label(self.__new_project_window, text="Existing Sources",
              font=("Helvetica", 15)).grid(row=5, column=0, sticky=W)

        Label(self.__new_project_window,
              text="Existing Parameter File:").grid(row=6, column=0, sticky=W)
        self.existing_params_entry = Entry(self.__new_project_window)
        self.existing_params_entry.grid(row=6, column=1, sticky=W)
        Button(self.__new_project_window, text="...",
               command=lambda:
               self.heide.file_mod.get_existing_loc(self.existing_params_entry)
              ).grid(row=6, column=3)

        Label(self.__new_project_window,
              text="Existing Data File:").grid(row=7, column=0, sticky=W)
        self.existing_data_entry = Entry(self.__new_project_window)
        self.existing_data_entry.grid(row=7, column=1, sticky=W)
        Button(self.__new_project_window, text="...",
               command=lambda:
               self.heide.file_mod.get_existing_loc(self.existing_data_entry)
              ).grid(row=7, column=3)

        Label(self.__new_project_window,
              text="Existing Algorithm File:").grid(row=8, column=0, sticky=W)
        self.existing_alg_entry = Entry(self.__new_project_window)
        self.existing_alg_entry.grid(row=8, column=1, sticky=W)
        Button(self.__new_project_window, text="...",
               command=lambda:
               self.heide.file_mod.get_existing_loc(self.existing_alg_entry)
              ).grid(row=8, column=3)

        Button(self.__new_project_window, text="Close",
               command=self.close_new_proj).grid(row=9, column=0, pady=20)
        Button(self.__new_project_window, text="Create",
               command=self.heide.create_new_proj).grid(row=9,
                                                              column=1,
                                                              pady=30)

        self.__new_project_window.update()

    def close_new_proj(self):
        self.active_window = Window.HEIDE
        self.__new_project_window.destroy()
Пример #10
0
class MyMainWindow(QMainWindow):
    """ the widget """
    def __init__(self):
        ''' the init function '''
        QWidget.__init__(self)
        self.createSystemTray()
        self.createUI()
        self.createConnections()
        self.createActions()
        self.setWindowTitle(u'定时器')
        #then the size policy
        self.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum)
        self.quitWithoutTray = False
        #then the positon/geometry
        self.setGeometry(400, 400, self.size().width(), self.size().height())

        self.mission = None
        self.intervalTimer = None
        DB.initTables()

    def closeEvent(self, evt):
        '''
        override the closeEvent to decide whether use systemTray
        '''
        if self.quitWithoutTray:
            if None != self.mission:
                self.mission.storeEvent()
            evt.accept()
        else:
            self.hide()
            evt.ignore()

    def showAllShortCut(self):
        '''
        not implemented
        show all shortcuts set
        '''
        pass

    def keyPressEvent(self, evt):
        if evt.key() == Qt.Key_Escape or (evt.key() == Qt.Key_W\
                and evt.modifiers() & Qt.ControlModifier):
            self.hide()
            self.msgLabel.hide()  #TODO no esc effect
            if self.msgLabel.isVisible():
                self.msgLabel.hide()
        elif (evt.key() == Qt.Key_Q and evt.modifiers() & Qt.ControlModifier):
            self.noTrayClose()
        #global shortcut to invoke the app, not implemented
        elif (evt.key() == Qt.Key_T and evt.modifiers() & Qt.AltModifier):
            self.show()
        else:
            QWidget.keyPressEvent(self, evt)

    @pyqtSlot(int)
    def trayActivated(self, reason):
        if QSystemTrayIcon.DoubleClick == reason or QSystemTrayIcon.Trigger == reason:
            self.show()

    def createUI(self):
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.nowTimeText = time.strftime(
            u'%H:%M:%S'.encode('utf-8')).decode('utf-8')
        self.ui.labelStartTime.setText(self.nowTimeText)
        self.ui.labelEndTime.setText('')
        self.ui.lineEditTimeCount.setFocus()
        self.msgLabel = MyLabel(u'<h1>时间到!</h1><img src=":/img/38.gif"/>')
        self.msgLabel.hide()
        self.msgLabel.setBuddy(self)
        self.ui.btnComplete.setDisabled(True)
        self.ui.btnDiscard.setDisabled(True)

    def createConnections(self):
        self.connect(self.ui.btnStartTimer, SIGNAL('clicked()'), \
                self.startTimer)
        self.connect(self.ui.btnComplete, SIGNAL('clicked()'), \
                self.missionComplete)
        self.connect(self.ui.btnDiscard, SIGNAL('clicked()'), \
                self.missionDiscarded)

    def createActions(self):
        self.ui.actViewData.setShortcut('Alt+D')
        self.connect(self.ui.actViewData, SIGNAL('triggered()'), self.viewData)

    @pyqtSlot()
    def viewData(self):
        self.dataWidget = getattr(self, 'dataWidget', False)
        if not self.dataWidget:
            self.dataWidget = getWidgetWithData()
        if self.dataWidget.isVisible():
            self.dataWidget.hide()
        else:
            self.dataWidget.show()

    def startTimer(self):
        #ui update
        self.nowTimeText = time.strftime(
            u'%H:%M:%S'.encode('utf-8')).decode('utf-8')
        minute = self.ui.lineEditTimeCount.text()
        try:
            minute = float(minute)
            self.timeCount = minute
        except ValueError:
            return
        self.ui.labelStartTime.setText(self.nowTimeText)
        self.dueTime = datetime.now() + timedelta(seconds=minute * 60)
        dueTimeText = self.dueTime.strftime(
            u'%H:%M:%S'.encode('utf8')).decode('utf8')
        self.ui.labelEndTime.setText(dueTimeText)

        self.ui.btnStartTimer.setDisabled(True)
        self.ui.btnComplete.setDisabled(False)
        self.ui.btnDiscard.setDisabled(False)
        #then timer
        self.mainTimer = QTimer()
        self.mainTimer.singleShot(minute * 60 * 1000, self,
                                  SLOT('timeOutMsg()'))

        self.mission = DB.dailyEvent()
        desc = self.ui.LEDescription.toPlainText()
        if len(desc) != 0:
            self.mission.setDescription(desc)

        self.resetIntervalTimer()

    def resetIntervalTimer(self):
        if None == self.intervalTimer:
            self.intervalTimer = QTimer()
            self.connect(self.intervalTimer, SIGNAL('timeout()'),
                         self.intervalNoticeMsg)
        else:
            self.intervalTimer.stop()

        self.intervalNoticeTime = self.ui.intervalNoticeEdit.text()
        if self.intervalNoticeTime != '':
            try:
                self.intervalNoticeTime = float(self.intervalNoticeTime)
            except ValueError:
                return
            self.intervalCount = 0
            self.intervalTimer.start(self.intervalNoticeTime * 60 * 1000)

    @pyqtSlot()
    def missionDiscarded(self):
        #db
        self.mission.setDiscarded()
        self.mission.setEndTimeNow()
        self.mission.storeEvent()
        #ui
        self.ui.btnComplete.setDisabled(True)
        self.ui.btnDiscard.setDisabled(True)
        self.ui.btnStartTimer.setDisabled(False)
        self.updateProgress()
        #timers
        self.mainTimer.stop()
        self.intervalTimer.stop()
        self.intervalCount = 0
        #TODO duplicated code!
        #TODO ui state change waiting -> in progress -> waiting

    @pyqtSlot()
    def intervalNoticeMsg(self):
        if not self.mission.isComplete() and not self.mission.isDiscarded():
            self.intervalCount = self.intervalCount + 1
            self.systemTray.showMessage(
                u'友情提醒', u'已经过了' + unicode(self.intervalCount) + u'个' +
                unicode(self.intervalNoticeTime) + u'分钟\n' + u'有木有!' * 20,
                QSystemTrayIcon.Information, 2000)
            self.updateProgress()

    @pyqtSlot()
    def missionComplete(self):
        #db
        self.mission.setEndTimeNow()
        self.mission.setComplete()
        #if complete in 30s, marked as not timeouted
        if datetime.now() > self.dueTime + timedelta(seconds=30):
            self.mission.setTimeouted()

        self.mission.storeEvent()
        #ui
        self.ui.btnComplete.setDisabled(True)
        self.ui.btnDiscard.setDisabled(True)
        self.ui.btnStartTimer.setDisabled(False)
        self.updateProgress()
        #timer
        self.intervalCount = 0
        if self.mainTimer:
            self.mainTimer.stop()

    @pyqtSlot()
    def noTrayClose(self):
        self.quitWithoutTray = True
        self.close()
        sys.exit()

    @pyqtSlot()
    def timeOutMsg(self):
        if self.dueTime + timedelta(milliseconds=100) > datetime.now(
        ) > self.dueTime and not self.mission.isComplete():
            #if this is the right timeoutMsg, that is, not a discarded one, so, in the interval
            self.mainTimer.stop()
            self.msgLabel.setWindowFlags(Qt.FramelessWindowHint)
            self.msgLabel.setGeometry(self.msgLabel.width(),
                                      self.msgLabel.height(),
                                      self.size().width(),
                                      self.size().height())
            self.msgLabel.show()

    @pyqtSlot()
    def updateStartTime(self):
        text = self.ui.lineEditStartTime.text()
        if len(text) < 1:
            self.nowTimeText = time.strftime(
                u'%H:%M:%S'.encode('utf-8')).decode('utf-8')
            text = self.nowTimeText
        else:
            infer = TimeInference(text)

        self.ui.labelStartTime.setText(text)

    def updateProgress(self):
        startTime = self.mission.startTime
        nowTime = datetime.now()
        usedSeconds = (nowTime - startTime).seconds
        progress = usedSeconds / float(self.timeCount * 60)
        progress = 1 if progress > 1 else progress
        self.ui.progressBar.setValue(int(progress * 100))
        pass

    def createSystemTray(self):
        self.systemTray = QSystemTrayIcon(self)
        self.trayIcon = QIcon(':/systemTray/tray.ico')
        self.trayMenu = QMenu(self)
        self.exitAction = QAction(u'退出', self)
        self.showAction = QAction(u'显示', self)
        self.connect(self.exitAction, SIGNAL('triggered()'), self.noTrayClose)
        self.connect(self.showAction, SIGNAL('triggered()'), self.show)
        self.trayMenu.addAction(self.exitAction)
        self.trayMenu.addAction(self.showAction)
        self.systemTray.setContextMenu(self.trayMenu)
        self.systemTray.setIcon(self.trayIcon)
        #self.connect(self.systemTray, SIGNAL('activated(int)'), self.trayActivated)
        self.systemTray.activated.connect(self.trayActivated)
        self.systemTray.show()

    pass
Пример #11
0
class MyMainWindow(QMainWindow):
    """ the widget """
    def __init__(self):
        ''' the init function '''
        QWidget.__init__(self)
        self.createSystemTray()
        self.createUI()
        self.createConnections()
        self.createActions()
        self.setWindowTitle(u'定时器')
        #then the size policy
        self.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum)
        self.quitWithoutTray = False
        #then the positon/geometry
        self.setGeometry(400, 400, self.size().width(), self.size().height())

        self.mission = None
        self.intervalTimer = None
        DB.initTables()

    def closeEvent(self, evt):
        '''
        override the closeEvent to decide whether use systemTray
        '''
        if self.quitWithoutTray:
            if None != self.mission:
                self.mission.storeEvent()
            evt.accept()
        else:
            self.hide()
            evt.ignore()

    def showAllShortCut(self):
        '''
        not implemented
        show all shortcuts set
        '''
        pass

    def keyPressEvent(self, evt):
        if evt.key() == Qt.Key_Escape or (evt.key() == Qt.Key_W\
                and evt.modifiers() & Qt.ControlModifier):
            self.hide()
            self.msgLabel.hide()#TODO no esc effect
            if self.msgLabel.isVisible():
                self.msgLabel.hide()
        elif (evt.key() == Qt.Key_Q and evt.modifiers()&Qt.ControlModifier):
            self.noTrayClose()
        #global shortcut to invoke the app, not implemented
        elif (evt.key() == Qt.Key_T and evt.modifiers()&Qt.AltModifier):
            self.show()
        else:
            QWidget.keyPressEvent(self, evt)

    @pyqtSlot(int)
    def trayActivated(self, reason):
        if QSystemTrayIcon.DoubleClick == reason or QSystemTrayIcon.Trigger == reason:
            self.show()

    def createUI(self):
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.nowTimeText = time.strftime(u'%H:%M:%S'.encode('utf-8')).decode('utf-8') 
        self.ui.labelStartTime.setText(self.nowTimeText)
        self.ui.labelEndTime.setText('')
        self.ui.lineEditTimeCount.setFocus()
        self.msgLabel = MyLabel(u'<h1>时间到!</h1><img src=":/img/38.gif"/>')
        self.msgLabel.hide()
        self.msgLabel.setBuddy(self)
        self.ui.btnComplete.setDisabled(True)
        self.ui.btnDiscard.setDisabled(True)

    def createConnections(self):
        self.connect(self.ui.btnStartTimer, SIGNAL('clicked()'), \
                self.startTimer)
        self.connect(self.ui.btnComplete, SIGNAL('clicked()'), \
                self.missionComplete)
        self.connect(self.ui.btnDiscard, SIGNAL('clicked()'), \
                self.missionDiscarded)

    def createActions(self):
        self.ui.actViewData.setShortcut('Alt+D')
        self.connect(self.ui.actViewData, SIGNAL('triggered()'),
                self.viewData)

    @pyqtSlot()
    def viewData(self):
        self.dataWidget = getattr(self, 'dataWidget', False)
        if not self.dataWidget:
            self.dataWidget = getWidgetWithData()
        if self.dataWidget.isVisible():
            self.dataWidget.hide()
        else:
            self.dataWidget.show()

    def startTimer(self):
        #ui update
        self.nowTimeText = time.strftime(u'%H:%M:%S'.encode('utf-8')).decode('utf-8')
        minute = self.ui.lineEditTimeCount.text()
        try:
            minute = float(minute)
            self.timeCount = minute
        except ValueError:
            return
        self.ui.labelStartTime.setText(self.nowTimeText)
        self.dueTime = datetime.now() + timedelta(seconds=minute*60)
        dueTimeText = self.dueTime.strftime(u'%H:%M:%S'.encode('utf8')).decode('utf8')
        self.ui.labelEndTime.setText(dueTimeText)

        self.ui.btnStartTimer.setDisabled(True)
        self.ui.btnComplete.setDisabled(False)
        self.ui.btnDiscard.setDisabled(False)
        #then timer
        self.mainTimer = QTimer()
        self.mainTimer.singleShot(minute*60*1000, self, SLOT('timeOutMsg()'))

        self.mission = DB.dailyEvent()
        desc = self.ui.LEDescription.toPlainText()
        if len(desc) != 0:
            self.mission.setDescription(desc)

        self.resetIntervalTimer()

    def resetIntervalTimer(self):
        if None == self.intervalTimer:
            self.intervalTimer = QTimer()
            self.connect(self.intervalTimer, SIGNAL('timeout()'), self.intervalNoticeMsg)
        else:
            self.intervalTimer.stop()

        self.intervalNoticeTime = self.ui.intervalNoticeEdit.text()
        if self.intervalNoticeTime != '':
            try:
                self.intervalNoticeTime = float(self.intervalNoticeTime)
            except ValueError:
                return
            self.intervalCount = 0
            self.intervalTimer.start(self.intervalNoticeTime*60*1000)

    @pyqtSlot()
    def missionDiscarded(self):
        #db
        self.mission.setDiscarded()
        self.mission.setEndTimeNow()
        self.mission.storeEvent()
        #ui
        self.ui.btnComplete.setDisabled(True)
        self.ui.btnDiscard.setDisabled(True)
        self.ui.btnStartTimer.setDisabled(False)
        self.updateProgress()
        #timers
        self.mainTimer.stop()
        self.intervalTimer.stop()
        self.intervalCount = 0
        #TODO duplicated code!
        #TODO ui state change waiting -> in progress -> waiting

    @pyqtSlot()
    def intervalNoticeMsg(self):
        if not self.mission.isComplete() and not self.mission.isDiscarded():
            self.intervalCount = self.intervalCount + 1
            self.systemTray.showMessage(u'友情提醒', u'已经过了'+unicode(self.intervalCount)+u'个'+unicode(self.intervalNoticeTime)+u'分钟\n'+u'有木有!'*20, QSystemTrayIcon.Information, 2000)
            self.updateProgress()


    @pyqtSlot()
    def missionComplete(self):
        #db
        self.mission.setEndTimeNow()
        self.mission.setComplete()
        #if complete in 30s, marked as not timeouted
        if datetime.now() > self.dueTime + timedelta(seconds=30):
            self.mission.setTimeouted()

        self.mission.storeEvent()
        #ui
        self.ui.btnComplete.setDisabled(True)
        self.ui.btnDiscard.setDisabled(True)
        self.ui.btnStartTimer.setDisabled(False)
        self.updateProgress()
        #timer
        self.intervalCount = 0
        if self.mainTimer:
            self.mainTimer.stop()

    @pyqtSlot()
    def noTrayClose(self):
        self.quitWithoutTray = True
        self.close()
        sys.exit()

    @pyqtSlot()
    def timeOutMsg(self):
        if self.dueTime+timedelta(milliseconds=100) > datetime.now() > self.dueTime and not self.mission.isComplete():
            #if this is the right timeoutMsg, that is, not a discarded one, so, in the interval
            self.mainTimer.stop()
            self.msgLabel.setWindowFlags(Qt.FramelessWindowHint)
            self.msgLabel.setGeometry(self.msgLabel.width(), self.msgLabel.height(), self.size().width(), self.size().height())
            self.msgLabel.show()

    @pyqtSlot()
    def updateStartTime(self):
        text = self.ui.lineEditStartTime.text()
        if len(text) < 1:
            self.nowTimeText = time.strftime(u'%H:%M:%S'.encode('utf-8')).decode('utf-8') 
            text =  self.nowTimeText
        else:
            infer = TimeInference(text)

        self.ui.labelStartTime.setText(text)

    def updateProgress(self):
        startTime = self.mission.startTime
        nowTime = datetime.now()
        usedSeconds = (nowTime-startTime).seconds
        progress = usedSeconds / float(self.timeCount*60)
        progress = 1 if progress > 1 else progress
        self.ui.progressBar.setValue(int(progress * 100))
        pass

    def createSystemTray(self):
        self.systemTray = QSystemTrayIcon(self)
        self.trayIcon = QIcon(':/systemTray/tray.ico')
        self.trayMenu = QMenu(self)
        self.exitAction = QAction(u'退出', self)
        self.showAction = QAction(u'显示', self)
        self.connect(self.exitAction, SIGNAL('triggered()'), self.noTrayClose)
        self.connect(self.showAction, SIGNAL('triggered()'), self.show)
        self.trayMenu.addAction(self.exitAction)
        self.trayMenu.addAction(self.showAction)
        self.systemTray.setContextMenu(self.trayMenu)
        self.systemTray.setIcon(self.trayIcon)
        #self.connect(self.systemTray, SIGNAL('activated(int)'), self.trayActivated)
        self.systemTray.activated.connect(self.trayActivated)
        self.systemTray.show()
    pass
Пример #12
0
class InputDlg(QDialog):
    def __init__(self, parent = None):
        super(InputDlg,self).__init__(parent)
        self.setWindowTitle("家族信息表")
        self.setWindowIcon(QIcon("./icon/dialog.png"))
        self.personInfo = PersonInfo()
        self.CreateWidgets()
        self.Layout()
        self.connect(self.birthdayEditLabel, SIGNAL("mouseDoubleClicked()"), self.ShowBirthCalendar)
        self.connect(self.birthCalendar, SIGNAL("selectionChanged()"), self.ShowBirthday)
        self.connect(self.deadCheckBox, SIGNAL("stateChanged(int)"), self.SetDeath)
        self.buttons.accepted.connect(self.accept)
        self.buttons.rejected.connect(self.reject)

    def CreateWidgets(self):
        self.nameLabel = QLabel("姓名:")
        self.birthdayLabel = QLabel("出生年月:")
        self.birthdayEditLabel = MyLabel("1900-01-01")
        self.birthdayEditLabel.setFrameStyle(QFrame.Panel|QFrame.Sunken)
        self.addressLabel = QLabel("地址:")
        self.deathdayLabel = QLabel("去世年月:")
        self.deathdayEditLabel = MyLabel("- - - ")
        self.deathdayEditLabel.setFrameStyle(QFrame.Panel|QFrame.Sunken)

        self.nameEdit = QLineEdit()
        self.addressEdit = QLineEdit()
        self.buttons = QDialogButtonBox(
            QDialogButtonBox.Ok | QDialogButtonBox.Cancel,
            Qt.Horizontal, self)

        self.confirmButton = QPushButton("确定")
        self.cancelButton = QPushButton("取消")

        self.birthCalendar = QCalendarWidget()
        self.birthCalendar.setWindowTitle("出生年月")
        self.birthCalendar.setWindowIcon(QIcon("./icon/calendar1.png"))
        self.birthCalendar.hide()
        self.deathCalendar = QCalendarWidget()
        self.deathCalendar.setWindowTitle("去世年月")
        self.deathCalendar.setWindowIcon(QIcon("./icon/calendar2.png"))
        self.deathCalendar.hide()

        self.deadCheckBox = QCheckBox("去世")  # 默认未去世
        self.marryCheckBox = QCheckBox("结婚")
        self.marryCheckBox.toggle()  # 默认结婚


    def Layout(self):
        self.UpLayout()
        mainLayout = QGridLayout(self)
        mainLayout.addLayout(self.upLayout, 0, 0)

    def UpLayout(self):
        self.upLayout = QGridLayout()
        self.upLayout.addWidget(self.nameLabel, 0, 0)
        self.upLayout.addWidget(self.nameEdit, 0, 1)
        self.upLayout.addWidget(self.birthdayLabel, 1, 0)
        self.upLayout.addWidget(self.birthdayEditLabel, 1, 1)
        self.upLayout.addWidget(self.addressLabel, 2, 0)
        self.upLayout.addWidget(self.addressEdit, 2, 1)
        self.upLayout.addWidget(self.deadCheckBox, 3, 0)
        self.upLayout.addWidget(self.marryCheckBox, 3, 1)
        self.upLayout.addWidget(self.deathdayLabel, 4, 0)
        self.upLayout.addWidget(self.deathdayEditLabel, 4, 1)
        self.upLayout.addWidget(self.buttons, 5, 1)

    def ShowBirthCalendar(self):
        self.birthCalendar.show()

    def ShowDeathCalendar(self):
        self.deathCalendar.show()

    def SetDeath(self, state):
        # state为2时,表示复选框选中
        if state == 2:
            self.connect(self.deathdayEditLabel, SIGNAL("mouseDoubleClicked()"), self.ShowDeathCalendar)
            self.connect(self.deathCalendar, SIGNAL("selectionChanged()"), self.ShowDeathday)
        # 否则将之前建立的连接断开
        else:
            self.disconnect(self.deathdayEditLabel, SIGNAL("mouseDoubleClicked()"), self.ShowDeathCalendar)
            self.disconnect(self.deathCalendar, SIGNAL("selectionChanged()"), self.ShowDeathday)    


    def ShowBirthday(self):
        birthday = self.birthCalendar.selectedDate()
        birthdayString = birthday.toString()
        pattern = re.compile(r"\d+")  # 匹配月、日、年
        birthdayList = re.findall(pattern, birthdayString)
        self.birthdayEditLabel.setText(str(birthdayList[2])+"-"+str(birthdayList[0])+"-"+str(birthdayList[1]))

    def ShowDeathday(self):
        deathday = self.deathCalendar.selectedDate()
        deathdayString = deathday.toString()
        pattern = re.compile(r"\d+")  # 匹配月、日、年
        deathdayList = re.findall(pattern, deathdayString)
        self.deathdayEditLabel.setText(str(deathdayList[2])+"-"+str(deathdayList[0])+"-"+str(deathdayList[1]))

    # 获取对话框中的数据
    def GetData(self):
        personInfo = PersonInfo()
        personInfo.name = self.nameEdit.text()
        personInfo.birthday = self.birthdayEditLabel.text()
        personInfo.address = self.addressEdit.text()
        if self.marryCheckBox.checkState() == 2:
            personInfo.marry = "是"
        else:
            personInfo.marry = "否"
        if self.deadCheckBox.checkState() == 2:
            personInfo.alive = "否"
            personInfo.deathday = self.deathdayEditLabel.text()
        else:
            personInfo.alive = "是"
            personInfo.deathday = "- - -"
        return personInfo
Пример #13
0
    def setupUi(self, Form):
        Form.setObjectName(_fromUtf8("Form"))
        Form.resize(1081, 599)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(_fromUtf8(":/images/funcell.png")),
                       QtGui.QIcon.Normal, QtGui.QIcon.Off)
        Form.setWindowIcon(icon)
        Form.setStyleSheet(
            _fromUtf8(
                "QToolButton[objectName=\"closetoolButton\"] {\n"
                "border:0px;\n"
                "}\n"
                "QToolButton[objectName=\"closetoolButton\"]:hover {\n"
                "image:url(:/images/close_hover.png);\n"
                "}\n"
                "QToolButton[objectName=\"closetoolButton\"]:pressed {\n"
                "image:url(:/images/close_pressed.png);\n"
                "}\n"
                "\n"
                "QToolButton[objectName=\"closetoolButton_2\"] {\n"
                "border:0px;\n"
                "}\n"
                "QToolButton[objectName=\"closetoolButton_2\"]:hover {\n"
                "image:url(:/images/min_hover.png);\n"
                "}\n"
                "QToolButton[objectName=\"closetoolButton_2\"]:pressed {\n"
                "image:url(:/images/min_pressed.png);\n"
                "}\n"
                "\n"
                "QWidget[objectName=\"Form\"]{\n"
                "border-image:url(\":/images/funcell_bg.png\");\n"
                "}\n"
                "\n"
                "QToolButton[objectName=\"toolButton\"]{\n"
                "background-color: rgb(85, 255, 127);\n"
                "border-radius: 10px;\n"
                "}\n"
                "QLineEdit[objectName=\"lineEdit\"],QLineEdit[objectName=\"lineEdit_2\"]{\n"
                "border:0px;\n"
                "background-color:transparent;\n"
                "}\n"
                "QCheckBox[objectName=\"checkBox\"],QLabel[objectName=\"label_3\"],QLineEdit[objectName=\"lineEdit\"],QLineEdit[objectName=\"lineEdit_2\"]{\n"
                "font-family:\'微软雅黑\';\n"
                "color:white;\n"
                "}\n"
                "\n"
                "QLabel[objectName=\"label_4\"],QLabel[objectName=\"label_5\"]{\n"
                "font-family:\'微软雅黑\';\n"
                "color:red;\n"
                "}\n"
                ""))
        self.widget = QtGui.QWidget(Form)
        self.widget.setGeometry(QtCore.QRect(-1, -1, 1081, 601))
        self.widget.setObjectName(_fromUtf8("widget"))
        self.line_2 = QtGui.QFrame(self.widget)
        self.line_2.setGeometry(QtCore.QRect(320, 225, 420, 3))
        self.line_2.setFrameShape(QtGui.QFrame.HLine)
        self.line_2.setFrameShadow(QtGui.QFrame.Sunken)
        self.line_2.setObjectName(_fromUtf8("line_2"))
        self.label = QtGui.QLabel(self.widget)
        self.label.setGeometry(QtCore.QRect(320, 182, 30, 30))
        self.label.setText(_fromUtf8(""))
        self.label.setPixmap(QtGui.QPixmap(_fromUtf8(":/images/use.png")))
        self.label.setObjectName(_fromUtf8("label"))
        self.line_3 = QtGui.QFrame(self.widget)
        self.line_3.setGeometry(QtCore.QRect(320, 295, 420, 3))
        self.line_3.setFrameShape(QtGui.QFrame.HLine)
        self.line_3.setFrameShadow(QtGui.QFrame.Sunken)
        self.line_3.setObjectName(_fromUtf8("line_3"))
        self.checkBox = QtGui.QCheckBox(self.widget)
        self.checkBox.setGeometry(QtCore.QRect(670, 365, 71, 16))
        self.checkBox.setChecked(True)
        self.checkBox.setObjectName(_fromUtf8("checkBox"))
        self.toolButton = QtGui.QToolButton(self.widget)
        self.toolButton.setGeometry(QtCore.QRect(320, 425, 420, 61))
        self.toolButton.setAutoRepeat(False)
        self.toolButton.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)
        self.toolButton.setObjectName(_fromUtf8("toolButton"))
        self.lineEdit = QtGui.QLineEdit(self.widget)
        self.lineEdit.setGeometry(QtCore.QRect(390, 185, 321, 25))
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("微软雅黑"))
        self.lineEdit.setFont(font)
        self.lineEdit.setText(_fromUtf8(""))
        self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
        self.line_4 = QtGui.QFrame(self.widget)
        self.line_4.setGeometry(QtCore.QRect(360, 255, 3, 25))
        self.line_4.setFrameShape(QtGui.QFrame.VLine)
        self.line_4.setFrameShadow(QtGui.QFrame.Sunken)
        self.line_4.setObjectName(_fromUtf8("line_4"))
        self.lineEdit_2 = QtGui.QLineEdit(self.widget)
        self.lineEdit_2.setGeometry(QtCore.QRect(390, 255, 321, 25))
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("微软雅黑"))
        self.lineEdit_2.setFont(font)
        self.lineEdit_2.setText(_fromUtf8(""))
        self.lineEdit_2.setEchoMode(QtGui.QLineEdit.Password)
        self.lineEdit_2.setObjectName(_fromUtf8("lineEdit_2"))
        self.line = QtGui.QFrame(self.widget)
        self.line.setGeometry(QtCore.QRect(360, 185, 3, 25))
        self.line.setFrameShape(QtGui.QFrame.VLine)
        self.line.setFrameShadow(QtGui.QFrame.Sunken)
        self.line.setObjectName(_fromUtf8("line"))
        #         self.label_3 = QtGui.QLabel(self.widget)
        #         self.label_3.setGeometry(QtCore.QRect(640, 525, 105, 31))
        #         self.label_3.setObjectName(_fromUtf8("label_3"))
        self.label_3 = MyLabel(self)
        self.label_3.setGeometry(QtCore.QRect(640, 525, 105, 31))
        self.label_3.setObjectName(_fromUtf8("label_3"))
        self.label_3.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.label_2 = QtGui.QLabel(self.widget)
        self.label_2.setGeometry(QtCore.QRect(320, 250, 30, 30))
        self.label_2.setText(_fromUtf8(""))
        self.label_2.setPixmap(QtGui.QPixmap(_fromUtf8(":/images/suo.png")))
        self.label_2.setObjectName(_fromUtf8("label_2"))
        self.closetoolButton = QtGui.QToolButton(self.widget)
        self.closetoolButton.setGeometry(QtCore.QRect(1050, 5, 27, 22))
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(_fromUtf8(":/images/close_normal.png")),
                       QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.closetoolButton.setIcon(icon)
        self.closetoolButton.setIconSize(QtCore.QSize(27, 22))
        self.closetoolButton.setObjectName(_fromUtf8("closetoolButton"))
        self.closetoolButton_2 = QtGui.QToolButton(self.widget)
        self.closetoolButton_2.setGeometry(QtCore.QRect(1020, 5, 27, 22))
        icon1 = QtGui.QIcon()
        icon1.addPixmap(QtGui.QPixmap(_fromUtf8(":/images/min_normal.png")),
                        QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.closetoolButton_2.setIcon(icon1)
        self.closetoolButton_2.setIconSize(QtCore.QSize(27, 22))
        self.closetoolButton_2.setObjectName(_fromUtf8("closetoolButton_2"))
        self.label_4 = QtGui.QLabel(self.widget)
        self.label_4.setGeometry(QtCore.QRect(770, 210, 105, 31))
        self.label_4.setObjectName(_fromUtf8("label_4"))
        self.label_5 = QtGui.QLabel(self.widget)
        self.label_5.setGeometry(QtCore.QRect(770, 280, 105, 31))
        self.label_5.setObjectName(_fromUtf8("label_5"))

        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)
        self.closetoolButton.clicked.connect(self.close)
        self.closetoolButton_2.clicked.connect(self.showMinimized)
        self.toolButton.clicked.connect(self.LoginTask)
        self.initUserInfo()
Пример #14
0
class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName(_fromUtf8("Form"))
        Form.resize(1081, 599)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(_fromUtf8(":/images/funcell.png")),
                       QtGui.QIcon.Normal, QtGui.QIcon.Off)
        Form.setWindowIcon(icon)
        Form.setStyleSheet(
            _fromUtf8(
                "QToolButton[objectName=\"closetoolButton\"] {\n"
                "border:0px;\n"
                "}\n"
                "QToolButton[objectName=\"closetoolButton\"]:hover {\n"
                "image:url(:/images/close_hover.png);\n"
                "}\n"
                "QToolButton[objectName=\"closetoolButton\"]:pressed {\n"
                "image:url(:/images/close_pressed.png);\n"
                "}\n"
                "\n"
                "QToolButton[objectName=\"closetoolButton_2\"] {\n"
                "border:0px;\n"
                "}\n"
                "QToolButton[objectName=\"closetoolButton_2\"]:hover {\n"
                "image:url(:/images/min_hover.png);\n"
                "}\n"
                "QToolButton[objectName=\"closetoolButton_2\"]:pressed {\n"
                "image:url(:/images/min_pressed.png);\n"
                "}\n"
                "\n"
                "QWidget[objectName=\"Form\"]{\n"
                "border-image:url(\":/images/funcell_bg.png\");\n"
                "}\n"
                "\n"
                "QToolButton[objectName=\"toolButton\"]{\n"
                "background-color: rgb(85, 255, 127);\n"
                "border-radius: 10px;\n"
                "}\n"
                "QLineEdit[objectName=\"lineEdit\"],QLineEdit[objectName=\"lineEdit_2\"]{\n"
                "border:0px;\n"
                "background-color:transparent;\n"
                "}\n"
                "QCheckBox[objectName=\"checkBox\"],QLabel[objectName=\"label_3\"],QLineEdit[objectName=\"lineEdit\"],QLineEdit[objectName=\"lineEdit_2\"]{\n"
                "font-family:\'微软雅黑\';\n"
                "color:white;\n"
                "}\n"
                "\n"
                "QLabel[objectName=\"label_4\"],QLabel[objectName=\"label_5\"]{\n"
                "font-family:\'微软雅黑\';\n"
                "color:red;\n"
                "}\n"
                ""))
        self.widget = QtGui.QWidget(Form)
        self.widget.setGeometry(QtCore.QRect(-1, -1, 1081, 601))
        self.widget.setObjectName(_fromUtf8("widget"))
        self.line_2 = QtGui.QFrame(self.widget)
        self.line_2.setGeometry(QtCore.QRect(320, 225, 420, 3))
        self.line_2.setFrameShape(QtGui.QFrame.HLine)
        self.line_2.setFrameShadow(QtGui.QFrame.Sunken)
        self.line_2.setObjectName(_fromUtf8("line_2"))
        self.label = QtGui.QLabel(self.widget)
        self.label.setGeometry(QtCore.QRect(320, 182, 30, 30))
        self.label.setText(_fromUtf8(""))
        self.label.setPixmap(QtGui.QPixmap(_fromUtf8(":/images/use.png")))
        self.label.setObjectName(_fromUtf8("label"))
        self.line_3 = QtGui.QFrame(self.widget)
        self.line_3.setGeometry(QtCore.QRect(320, 295, 420, 3))
        self.line_3.setFrameShape(QtGui.QFrame.HLine)
        self.line_3.setFrameShadow(QtGui.QFrame.Sunken)
        self.line_3.setObjectName(_fromUtf8("line_3"))
        self.checkBox = QtGui.QCheckBox(self.widget)
        self.checkBox.setGeometry(QtCore.QRect(670, 365, 71, 16))
        self.checkBox.setChecked(True)
        self.checkBox.setObjectName(_fromUtf8("checkBox"))
        self.toolButton = QtGui.QToolButton(self.widget)
        self.toolButton.setGeometry(QtCore.QRect(320, 425, 420, 61))
        self.toolButton.setAutoRepeat(False)
        self.toolButton.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)
        self.toolButton.setObjectName(_fromUtf8("toolButton"))
        self.lineEdit = QtGui.QLineEdit(self.widget)
        self.lineEdit.setGeometry(QtCore.QRect(390, 185, 321, 25))
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("微软雅黑"))
        self.lineEdit.setFont(font)
        self.lineEdit.setText(_fromUtf8(""))
        self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
        self.line_4 = QtGui.QFrame(self.widget)
        self.line_4.setGeometry(QtCore.QRect(360, 255, 3, 25))
        self.line_4.setFrameShape(QtGui.QFrame.VLine)
        self.line_4.setFrameShadow(QtGui.QFrame.Sunken)
        self.line_4.setObjectName(_fromUtf8("line_4"))
        self.lineEdit_2 = QtGui.QLineEdit(self.widget)
        self.lineEdit_2.setGeometry(QtCore.QRect(390, 255, 321, 25))
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("微软雅黑"))
        self.lineEdit_2.setFont(font)
        self.lineEdit_2.setText(_fromUtf8(""))
        self.lineEdit_2.setEchoMode(QtGui.QLineEdit.Password)
        self.lineEdit_2.setObjectName(_fromUtf8("lineEdit_2"))
        self.line = QtGui.QFrame(self.widget)
        self.line.setGeometry(QtCore.QRect(360, 185, 3, 25))
        self.line.setFrameShape(QtGui.QFrame.VLine)
        self.line.setFrameShadow(QtGui.QFrame.Sunken)
        self.line.setObjectName(_fromUtf8("line"))
        #         self.label_3 = QtGui.QLabel(self.widget)
        #         self.label_3.setGeometry(QtCore.QRect(640, 525, 105, 31))
        #         self.label_3.setObjectName(_fromUtf8("label_3"))
        self.label_3 = MyLabel(self)
        self.label_3.setGeometry(QtCore.QRect(640, 525, 105, 31))
        self.label_3.setObjectName(_fromUtf8("label_3"))
        self.label_3.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.label_2 = QtGui.QLabel(self.widget)
        self.label_2.setGeometry(QtCore.QRect(320, 250, 30, 30))
        self.label_2.setText(_fromUtf8(""))
        self.label_2.setPixmap(QtGui.QPixmap(_fromUtf8(":/images/suo.png")))
        self.label_2.setObjectName(_fromUtf8("label_2"))
        self.closetoolButton = QtGui.QToolButton(self.widget)
        self.closetoolButton.setGeometry(QtCore.QRect(1050, 5, 27, 22))
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(_fromUtf8(":/images/close_normal.png")),
                       QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.closetoolButton.setIcon(icon)
        self.closetoolButton.setIconSize(QtCore.QSize(27, 22))
        self.closetoolButton.setObjectName(_fromUtf8("closetoolButton"))
        self.closetoolButton_2 = QtGui.QToolButton(self.widget)
        self.closetoolButton_2.setGeometry(QtCore.QRect(1020, 5, 27, 22))
        icon1 = QtGui.QIcon()
        icon1.addPixmap(QtGui.QPixmap(_fromUtf8(":/images/min_normal.png")),
                        QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.closetoolButton_2.setIcon(icon1)
        self.closetoolButton_2.setIconSize(QtCore.QSize(27, 22))
        self.closetoolButton_2.setObjectName(_fromUtf8("closetoolButton_2"))
        self.label_4 = QtGui.QLabel(self.widget)
        self.label_4.setGeometry(QtCore.QRect(770, 210, 105, 31))
        self.label_4.setObjectName(_fromUtf8("label_4"))
        self.label_5 = QtGui.QLabel(self.widget)
        self.label_5.setGeometry(QtCore.QRect(770, 280, 105, 31))
        self.label_5.setObjectName(_fromUtf8("label_5"))

        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)
        self.closetoolButton.clicked.connect(self.close)
        self.closetoolButton_2.clicked.connect(self.showMinimized)
        self.toolButton.clicked.connect(self.LoginTask)
        self.initUserInfo()

    def retranslateUi(self, Form):
        Form.setWindowTitle(_translate("Form", "请登录", None))
        self.checkBox.setText(_translate("Form", "记住密码", None))
        self.toolButton.setText(_translate("Form", "登 录", None))
        self.label_3.setText(_translate("Form", "没有帐号?立即注册", None))
        self.closetoolButton.setText(_translate("Form", "...", None))
        self.closetoolButton_2.setText(_translate("Form", "...", None))
        self.label_4.setText(_translate("Form", "游戏ProductCode", None))
        self.label_5.setText(_translate("Form", "游戏ProductKey", None))

    def mouseMoveEvent(self, event):
        if (event.buttons() == Qt.LeftButton):
            self.endPos = event.globalPos() - self.startPos
            self.move(self.endPos)

    def mousePressEvent(self, event):

        if (event.button() == Qt.LeftButton):
            self.startPos = event.globalPos() - self.frameGeometry().topLeft()

        elif (event.button() == Qt.MiddleButton):
            self.closeWindowAnimation()

    def registerTask(self):
        print 'register user'

    def saveUserInfo(self):
        GameFile = file_operate.getFullPath("Log/GameFile.log")
        checkflag = "False"
        if self.checkBox.isChecked():
            checkflag = "True"
        info = self.lineEdit.text() + '|' + self.lineEdit_2.text(
        ) + '|' + checkflag

        logFile = codecs.open(GameFile, 'w', 'utf-8')
        content = info + '\r\n'
        logFile.write(unicode(content, 'gbk'))
        logFile.close()

    def initUserInfo(self):
        GameFile = file_operate.getFullPath("Log/GameFile.log")
        if not os.path.exists('Log'):
            os.makedirs('Log')
        if os.path.exists(GameFile):
            f = open(GameFile, 'a+')
            data = str(f.read())
            f.close()
            if len(data) > 0 and data.find('|') != -1:
                logFile = codecs.open(GameFile, 'a+', 'utf-8')
                for line in logFile.readlines():
                    line = line.rstrip("\r\n")
                    Info = line.split('|')
                    if Info[2] == "True":
                        self.lineEdit.setText(Info[0])
                        self.lineEdit_2.setText(Info[1])
                        self.checkBox.setChecked(True)
                    else:
                        self.checkBox.setChecked(False)
                    break

    def getHostAddress(self):
        address = ''
        try:
            config = ET.parse(file_operate.getCommonXmlPath())
            root = config.getroot()
            host = root.find("host")
            address = host.get("address")
        except Exception, e:
            print e
            print "Error: cannot parse file: commonconfig.xml."
            return -1
        return address
Пример #15
0
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(467, 536)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.frame = QtWidgets.QFrame(self.centralwidget)
        self.frame.setGeometry(QtCore.QRect(10, 90, 441, 401))
        self.frame.setStyleSheet("")
        self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame.setObjectName("frame")
        self.layoutWidget = QtWidgets.QWidget(self.frame)
        self.layoutWidget.setGeometry(QtCore.QRect(10, 10, 421, 381))
        self.layoutWidget.setObjectName("layoutWidget")
        self.gridLayout = QtWidgets.QGridLayout(self.layoutWidget)
        self.gridLayout.setContentsMargins(0, 0, 0, 0)
        self.gridLayout.setObjectName("gridLayout")
        self.account_lineEdit = QtWidgets.QLineEdit(self.layoutWidget)
        self.account_lineEdit.setMinimumSize(QtCore.QSize(293, 35))
        self.account_lineEdit.setMaximumSize(QtCore.QSize(293, 16777215))
        self.account_lineEdit.setStyleSheet("font: 14pt \"华文楷体\";")
        self.account_lineEdit.setClearButtonEnabled(True)
        self.account_lineEdit.setObjectName("account_lineEdit")
        self.gridLayout.addWidget(self.account_lineEdit, 0, 1, 1, 1)
        self.password_label = QtWidgets.QLabel(self.layoutWidget)
        self.password_label.setStyleSheet("font: 14pt \"华文楷体\";")
        self.password_label.setAlignment(QtCore.Qt.AlignCenter)
        self.password_label.setObjectName("password_label")
        self.gridLayout.addWidget(self.password_label, 1, 0, 1, 1)
        self.login_label = QtWidgets.QPushButton(self.layoutWidget)
        self.login_label.setMinimumSize(QtCore.QSize(0, 40))
        self.login_label.setMaximumSize(QtCore.QSize(16777215, 40))
        self.login_label.setStyleSheet("font: 14pt \"华文楷体\";")
        self.login_label.setObjectName("login_label")
        self.gridLayout.addWidget(self.login_label, 4, 0, 1, 2)
        self.password_lineEdit = QtWidgets.QLineEdit(self.layoutWidget)
        self.password_lineEdit.setMinimumSize(QtCore.QSize(293, 35))
        self.password_lineEdit.setMaximumSize(QtCore.QSize(293, 16777215))
        self.password_lineEdit.setStyleSheet("font: 14pt \"华文楷体\";")
        self.password_lineEdit.setEchoMode(QtWidgets.QLineEdit.Password)
        self.password_lineEdit.setClearButtonEnabled(True)
        self.password_lineEdit.setObjectName("password_lineEdit")
        self.gridLayout.addWidget(self.password_lineEdit, 1, 1, 1, 1)
        self.picture_label = MyLabel(self.layoutWidget)
        self.picture_label.setMinimumSize(QtCore.QSize(293, 190))
        self.picture_label.setMaximumSize(QtCore.QSize(293, 190))
        self.picture_label.setStyleSheet("font: 14pt \"华文楷体\";\n"
"background-color: rgb(0, 255, 255);")
        self.picture_label.setAlignment(QtCore.Qt.AlignCenter)
        self.picture_label.setObjectName("picture_label")
        self.gridLayout.addWidget(self.picture_label, 2, 1, 2, 1)
        self.account_label = QtWidgets.QLabel(self.layoutWidget)
        self.account_label.setStyleSheet("font: 14pt \"华文楷体\";")
        self.account_label.setAlignment(QtCore.Qt.AlignCenter)
        self.account_label.setObjectName("account_label")
        self.gridLayout.addWidget(self.account_label, 0, 0, 1, 1)
        self.refresh_button = QtWidgets.QPushButton(self.layoutWidget)
        self.refresh_button.setMinimumSize(QtCore.QSize(50, 60))
        self.refresh_button.setStyleSheet("font: 14pt \"华文楷体\";")
        self.refresh_button.setObjectName("refresh_button")
        self.gridLayout.addWidget(self.refresh_button, 2, 0, 1, 1)
        self.autoSelect_button = QtWidgets.QPushButton(self.layoutWidget)
        self.autoSelect_button.setMinimumSize(QtCore.QSize(50, 60))
        self.autoSelect_button.setStyleSheet("font: 14pt \"华文楷体\";")
        self.autoSelect_button.setObjectName("autoSelect_button")
        self.gridLayout.addWidget(self.autoSelect_button, 3, 0, 1, 1)
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(20, 10, 421, 81))
        self.label.setStyleSheet("font: 14pt \"华文楷体\";\n"
"border-image: url(:/image/qiangpiao.png);")
        self.label.setText("")
        self.label.setAlignment(QtCore.Qt.AlignCenter)
        self.label.setObjectName("label")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 467, 23))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        self.refresh_button.clicked.connect(MainWindow.reFresh)
        self.autoSelect_button.clicked.connect(MainWindow.autoSelect)
        self.login_label.clicked.connect(MainWindow.login)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
Пример #16
0
class gui_module:
    def __init__(self, heide):
        self.heide = heide
        self.active_window = None

        self.heide_version = "HEIDE v0.5"
        self.root = Tk()

        self.logo = None

        self.key_bindings()
        self.root.protocol("WM_DELETE_WINDOW", self.heide.heide_quit)

        self.param_custom_font = tkinter.font.Font()
        self.data_custom_font = tkinter.font.Font()
        self.alg_custom_font = tkinter.font.Font()

        self.param_label = Label
        self.data_label = Label
        self.alg_label = Label

        self.__command_label = Label
        self.__command_label_txt = StringVar()

        self.output_window = Toplevel
        self.output_text = ScrolledText
        self.__photo = PhotoImage
        self.load_bar_label = MyLabel

        self.settings_window = Toplevel
        self.__he_src_entry = Entry
        self.__max_num_subpr_entry = Entry
        self.__display_mem_usage = IntVar
        self.__display_mem_usage_checkbutton = Checkbutton

        self.__new_project_window = Toplevel
        self.he_src_entry_np = Entry
        self.project_name_entry = Entry
        self.project_loc_entry = Entry
        self.existing_params_entry = Entry
        self.existing_data_entry = Entry
        self.existing_alg_entry = Entry

    def key_bindings(self):
        keys = [
            "Control_L", "Control_R", "s", "p", "P", "d", "D", "a", "A", "o",
            "n", "C", "q", "F1"
        ]
        for key in keys:
            self.root.bind("<KeyPress-" + key + ">",
                           self.heide.edit_mod.key_press)
            self.root.bind("<KeyRelease-" + key + ">",
                           self.heide.edit_mod.key_release)

    def spawn_start_up_window(self):
        self.active_window = Window.START_UP

        # Root widget creation for startup window
        self.root.wm_title(self.heide_version + " Startup Window")
        self.root.wm_minsize(height=250, width=500)
        self.root.wm_maxsize(height=250, width=500)
        self.logo = Image("photo", file="./imgs/logo.gif")
        self.root.tk.call("wm", "iconphoto", self.root._w, "-default",
                          self.logo)

        logo_frame = Frame(self.root, height=250, width=250, padx=10, pady=50)
        logo_frame.grid(row=0, column=0)
        Label(logo_frame, image=self.logo).pack()

        text_frame = Frame(self.root, height=250, width=250, padx=10, pady=0)
        text_frame.grid(row=0, column=1)
        Label(text_frame, text=self.heide_version,
              font=("Helvetica", 30)).pack(anchor=W)

        self.__command_label = Label(text_frame,
                                     textvariable=self.__command_label_txt,
                                     wraplength=250,
                                     justify=LEFT)
        self.__command_label.pack()

        self.set_command_label("Initializing HEIDE ...")

        self.root.update()

    def set_command_label(self, text):
        self.__command_label_txt.set(text)

    def display_start_up_error(self, set_txt):
        self.__command_label.configure(fg="red")
        self.set_command_label(set_txt)

        self.root.update()

        # self.root.wait_window()
        self.root.quit()

        sys.exit()

    def display_error(self, error_type, error):
        tkinter.messagebox.showerror(error_type, error)
        return

    def spawn_heide_window(self):
        self.active_window = Window.HEIDE
        # Root widget creation for HEIDE GUI
        self.root.wm_title(self.heide_version)
        self.root.wm_minsize(height=927, width=1500)
        self.root.wm_maxsize(height=927, width=1500)

        # Create the root widgets menubar
        menubar = Menu(self.root)

        # add 'File' dropdown menu to menubar
        file_menu = Menu(menubar, tearoff=0)
        menubar.add_cascade(label="File", menu=file_menu)

        file_menu.add_command(label="New Project   CTRL+n",
                              command=self.heide.heide_new_project)

        # create submenu for opening files or projects
        open_menu = Menu(file_menu, tearoff=0)
        open_menu.add_command(
            label="Open Project       CTRL+o",
            command=lambda: self.heide.heide_open(File_Type.PROJ_FILE, None))
        open_menu.add_command(
            label="Open Param File",
            command=lambda: self.heide.heide_open(File_Type.PARAM_FILE, None))
        open_menu.add_command(
            label="Open Data File",
            command=lambda: self.heide.heide_open(File_Type.DATA_FILE, None))
        open_menu.add_command(
            label="Open Alg File",
            command=lambda: self.heide.heide_open(File_Type.ALG_FILE, None))
        file_menu.add_cascade(label="Open", menu=open_menu, underline=0)

        # create submenu for saving files
        save_menu = Menu(file_menu, tearoff=0)
        save_menu.add_command(
            label="Save Project".ljust(20) + "CTRL+s",
            command=lambda: self.heide.heide_save(File_Type.PROJ_FILE))
        save_menu.add_command(
            label="Save Params".ljust(18) + "CTRL+p",
            command=lambda: self.heide.heide_save(File_Type.PARAM_FILE))
        save_menu.add_command(
            label="Save Data".ljust(20) + "CTRL+d",
            command=lambda: self.heide.heide_save(File_Type.DATA_FILE))
        save_menu.add_command(
            label="Save Alg".ljust(21) + "CTRL+a",
            command=lambda: self.heide.heide_save(File_Type.ALG_FILE))
        file_menu.add_cascade(label="Save", menu=save_menu, underline=0)

        # create submenu for save as
        save_as_menu = Menu(file_menu, tearoff=0)
        save_as_menu.add_command(
            label="Save Params As...".ljust(20) + "CTRL+P",
            command=lambda: self.heide.heide_save_as(File_Type.PARAM_FILE))
        save_as_menu.add_command(
            label="Save Data As...".ljust(22) + "CTRL+D",
            command=lambda: self.heide.heide_save_as(File_Type.DATA_FILE))
        save_as_menu.add_command(
            label="Save Alg As...".ljust(23) + "CTRL+A",
            command=lambda: self.heide.heide_save_as(File_Type.ALG_FILE))
        file_menu.add_cascade(label="Save As...",
                              menu=save_as_menu,
                              underline=0)

        # create submenu for import
        import_menu = Menu(file_menu, tearoff=0)
        import_menu.add_command(
            label="Import Params",
            command=lambda: self.heide.heide_import(File_Type.PARAM_FILE))
        import_menu.add_command(
            label="Import Data",
            command=lambda: self.heide.heide_import(File_Type.DATA_FILE))
        import_menu.add_command(
            label="Import Alg",
            command=lambda: self.heide.heide_import(File_Type.ALG_FILE))
        file_menu.add_cascade(label="Import", menu=import_menu, underline=0)

        file_menu.add_command(label="Close Project   CTRL+C",
                              command=self.heide.heide_close_project)

        file_menu.add_command(label="Settings",
                              command=self.spawn_settings_window)

        file_menu.add_separator()

        file_menu.add_command(label="Quit               CTRL+q",
                              command=self.heide.heide_quit)

        # Add 'Run' dropdown menu to menubar
        run_menu = Menu(menubar, tearoff=0)
        menubar.add_cascade(label="Run", menu=run_menu)

        run_menu.add_command(label="Run    F1", command=self.heide.heide_run)

        # Tell root to display menubar
        self.root.config(menu=menubar)

        # The GUI is split into 3 frames: the parameter frame, data frame, the
        # algorithm frame.
        #
        #     - Parameter and Data Frame -
        #         Contains 'editors' where HElib setup parameters and data with
        #         which to perform computations on can be specified
        #
        #     - Algorithm Frame -
        #         Contains an 'editor' where the algorithm for computation is
        #         specified. The algorithm will be run on the data in the 'data
        #         editor' after it has been encrypted using the parameters
        #         specified in the 'parameter editor'

        param_and_data_frame = Frame(self.root,
                                     height=25,
                                     width=50,
                                     pady=15,
                                     padx=20)
        param_and_data_frame.grid(row=0, column=0)

        alg_frame = Frame(self.root, height=25, width=50, pady=15, padx=20)
        alg_frame.grid(row=0, column=1)

        keyboard_keys = [
            "Cancel", "BackSpace", "Tab", "Return", "Shift_L", "Control_L",
            "Alt_L", "Shift_R", "Control_R", "Alt_R", "Escape", "Insert",
            "Delete"
        ]

        self.param_label = Label(param_and_data_frame,
                                 text="Parameter Editor",
                                 font=self.param_custom_font).pack(anchor=W)
        param_editor = ScrolledText(param_and_data_frame,
                                    height=25,
                                    width=85,
                                    undo=True)
        param_editor.bind("<Key>", self.heide.edit_mod.param_edit_modified)
        for key in keyboard_keys:
            param_editor.bind(key, self.heide.edit_mod.param_edit_modified)
        param_editor.pack()

        Frame(param_and_data_frame, height=50).pack()

        self.data_label = Label(param_and_data_frame,
                                text="Data Editor",
                                font=self.data_custom_font).pack(anchor=W)
        data_editor = ScrolledText(param_and_data_frame,
                                   height=25,
                                   width=85,
                                   undo=True)
        data_editor.bind("<Key>", self.heide.edit_mod.data_edit_modified)
        for key in keyboard_keys:
            data_editor.bind(key, self.heide.edit_mod.data_edit_modified)
        data_editor.pack()

        self.alg_label = Label(alg_frame,
                               text="Algorithm Editor",
                               font=self.alg_custom_font).pack(anchor=W)
        alg_editor = ScrolledText(alg_frame, height=55, width=113, undo=True)
        alg_editor.bind("<Key>", self.heide.edit_mod.alg_edit_modified)
        for key in keyboard_keys:
            alg_editor.bind(key, self.heide.edit_mod.alg_edit_modified)
        alg_editor.pack()

        # set editor manager variables
        self.heide.edit_mod.set_editors(param_editor, data_editor, alg_editor)
        """
        Start mainloop, which will wait for user to do something
        """
        self.root.mainloop()

    def spawn_settings_window(self):
        self.active_window = Window.SETTINGS
        self.settings_window = Toplevel(padx=20, pady=20)
        self.settings_window.title("HEIDE Settings")
        self.settings_window.minsize(height=225, width=375)
        self.settings_window.maxsize(height=225, width=375)

        # setting window spawn location
        w = self.settings_window.winfo_screenwidth()
        h = self.settings_window.winfo_screenheight()
        settings_size = \
            tuple(int(_) for _ in
                  self.settings_window.geometry().split('+')[0].split('x'))
        x = w / 2 - settings_size[0] / 2
        y = h / 2 - settings_size[1] / 2
        self.settings_window.geometry("%dx%d+%d+%d" % (settings_size + (x, y)))

        self.settings_window.grab_set()

        Label(self.settings_window,
              text="Makefile Locations",
              font=("Helvetica", 15),
              anchor=W).grid(row=0, column=0)

        Label(self.settings_window, text="HE Source Code:").grid(row=1,
                                                                 column=0,
                                                                 sticky=W)
        self.__he_src_entry = Entry(self.settings_window)
        self.__he_src_entry.grid(row=1, column=1, sticky=W)
        self.__he_src_entry.insert(0, self.heide.set_mod.he_src)

        Label(self.settings_window,
              text="Run Settings",
              font=("Helvetica", 15),
              anchor=W).grid(row=2, column=0)

        Label(self.settings_window, text="Max # Subprocesses:").grid(row=3,
                                                                     column=0,
                                                                     sticky=W)
        self.__max_num_subpr_entry = Entry(self.settings_window)
        self.__max_num_subpr_entry.grid(row=3, column=1, sticky=W)
        self.__max_num_subpr_entry.insert(0, self.heide.set_mod.max_num_subpr)

        self.__display_mem_usage = IntVar()
        Label(self.settings_window,
              text="Display Memory Usage:").grid(row=4, column=0, sticky=W)
        self.__display_mem_usage_checkbutton = Checkbutton(
            self.settings_window, variable=self.__display_mem_usage)
        if self.heide.set_mod.display_mem_usage:
            self.__display_mem_usage_checkbutton.select()
        self.__display_mem_usage_checkbutton.grid(row=4, column=1, sticky=W)

        Button(self.settings_window, text="Close",
               command=self.close_settings).grid(row=5, column=0, pady=20)
        Button(self.settings_window,
               text="Apply",
               command=self.heide.set_mod.apply_settings).grid(row=5,
                                                               column=1,
                                                               pady=30)

        self.settings_window.update()

    def close_settings(self):
        self.active_window = Window.HEIDE
        self.settings_window.destroy()

    def get_settings(self):
        return json.dumps({
            "he_src":
            self.__he_src_entry.get(),
            "max_num_subpr":
            int(self.__max_num_subpr_entry.get()),
            "display_mem_usage":
            bool(self.__display_mem_usage.get())
        })

    def spawn_heide_console_window(self):
        self.active_window = Window.CONSOLE

        self.output_window = Toplevel()
        self.output_window.title("HEIDE Console")
        self.output_window.minsize(height=425, width=650)
        self.output_window.maxsize(height=425, width=650)

        self.output_window.protocol("WM_DELETE_WINDOW", self.close_console)

        # console window spawn location
        w = self.output_window.winfo_screenwidth()
        h = self.output_window.winfo_screenheight()
        output_wind_size = \
            tuple(int(_) for _ in
                  self.output_window.geometry().split('+')[0].split('x'))
        x = w / 2 - output_wind_size[0] / 2
        y = h / 2 - output_wind_size[1] / 2
        self.output_window.geometry("%dx%d+%d+%d" % (output_wind_size +
                                                     (x, y)))

        self.output_window.grab_set()

        text_frame = Frame(self.output_window, padx=20)
        text_frame.grid(row=0, column=0)

        Label(text_frame, text="Output").pack(anchor=W)

        self.output_text = ScrolledText(text_frame, height=23, width=85)
        self.output_text.pack()

        load_bar_frame = Frame(self.output_window, padx=20)
        load_bar_frame.grid(row=1, column=0)

        self.load_bar_label = MyLabel(load_bar_frame,
                                      "../imgs/loading_bar.gif")
        self.load_bar_label.pack()

        button_frame = Frame(self.output_window, padx=20)
        button_frame.grid(row=2, column=0)

        Button(button_frame, text="Close",
               command=self.close_console).grid(row=0, column=0)
        Button(button_frame,
               text="Save",
               command=self.heide.heide_save_console_output).grid(row=0,
                                                                  column=1)

        self.output_text.configure(state="disabled")

        self.output_window.update()

    def close_console(self):
        self.active_window = Window.HEIDE
        self.output_window.destroy()

        os.chdir(self.heide.og_dir)

        # terminate all currently running processes
        for proc in self.heide.running_processes:
            proc.terminate()

    def heide_console_display_result(self, config, ret_val, out, err):
        if ret_val == 0:
            self.output_text.configure(state="normal")
            self.output_text.insert("end", "/***** CONFIGURATION *****/\n\n")
            self.output_text.insert("end", config)

            self.output_text.insert("end", "\n/***** OUTPUT *****/\n\n")
            self.output_text.insert("end", out)
            self.output_text.insert("end", "\n" + "#" * 80 + "\n")
            self.output_text.configure(state="disabled")
        else:
            self.output_text.configure(state="normal")
            self.output_text.insert("end", "/***** CONFIGURATION *****/\n\n")
            self.output_text.insert("end", config)
            self.output_text.insert("end", out)
            self.output_text.insert("end", "\n" + "#" * 80 + "\n")
            self.output_text.insert("end",
                                    "/***** An ERROR has occurred *****/\n")
            self.output_text.insert("end", err)
            self.output_text.insert("end", "\n" + "#" * 80 + "\n")
            self.output_text.configure(state="disabled")

        self.output_window.update()

    def spawn_new_project_window(self):
        self.active_window = Window.NEW_PROJECT
        self.__new_project_window = Toplevel(padx=20, pady=20)
        self.__new_project_window.title("New Project")
        self.__new_project_window.minsize(height=350, width=405)
        self.__new_project_window.maxsize(height=350, width=405)

        # new project window spawn location
        w = self.__new_project_window.winfo_screenwidth()
        h = self.__new_project_window.winfo_screenheight()
        new_proj_wind_size = \
            tuple(int(_) for _ in
                  self.__new_project_window.geometry().split('+')[0].split('x'))
        x = w / 2 - new_proj_wind_size[0] / 2
        y = h / 2 - new_proj_wind_size[1] / 2
        self.__new_project_window.geometry("%dx%d+%d+%d" %
                                           (new_proj_wind_size + (x, y)))

        self.__new_project_window.grab_set()

        Label(self.__new_project_window,
              text="Makefile Locations",
              font=("Helvetica", 15)).grid(row=0, column=0, sticky=W)

        Label(self.__new_project_window, text="HE Source Code:").grid(row=1,
                                                                      column=0,
                                                                      sticky=W)
        self.he_src_entry_np = Entry(self.__new_project_window)
        self.he_src_entry_np.grid(row=1, column=1, sticky=W)
        self.he_src_entry_np.insert(0, self.heide.set_mod.he_src)

        Label(self.__new_project_window,
              text="Project Details",
              font=("Helvetica", 15)).grid(row=2, column=0, sticky=W)

        Label(self.__new_project_window, text="Project Name:").grid(row=3,
                                                                    column=0,
                                                                    sticky=W)
        self.project_name_entry = Entry(self.__new_project_window)
        self.project_name_entry.grid(row=3, column=1, sticky=W)

        Label(self.__new_project_window,
              text="Project Location:").grid(row=4, column=0, sticky=W)
        self.project_loc_entry = Entry(self.__new_project_window)
        self.project_loc_entry.grid(row=4, column=1, sticky=W)
        self.project_loc_entry.insert(0, self.heide.set_mod.heide_proj_dir)

        Label(self.__new_project_window,
              text="Existing Sources",
              font=("Helvetica", 15)).grid(row=5, column=0, sticky=W)

        Label(self.__new_project_window,
              text="Existing Parameter File:").grid(row=6, column=0, sticky=W)
        self.existing_params_entry = Entry(self.__new_project_window)
        self.existing_params_entry.grid(row=6, column=1, sticky=W)
        Button(self.__new_project_window,
               text="...",
               command=lambda: self.heide.file_mod.get_existing_loc(
                   self.existing_params_entry)).grid(row=6, column=3)

        Label(self.__new_project_window,
              text="Existing Data File:").grid(row=7, column=0, sticky=W)
        self.existing_data_entry = Entry(self.__new_project_window)
        self.existing_data_entry.grid(row=7, column=1, sticky=W)
        Button(self.__new_project_window,
               text="...",
               command=lambda: self.heide.file_mod.get_existing_loc(
                   self.existing_data_entry)).grid(row=7, column=3)

        Label(self.__new_project_window,
              text="Existing Algorithm File:").grid(row=8, column=0, sticky=W)
        self.existing_alg_entry = Entry(self.__new_project_window)
        self.existing_alg_entry.grid(row=8, column=1, sticky=W)
        Button(self.__new_project_window,
               text="...",
               command=lambda: self.heide.file_mod.get_existing_loc(
                   self.existing_alg_entry)).grid(row=8, column=3)

        Button(self.__new_project_window,
               text="Close",
               command=self.close_new_proj).grid(row=9, column=0, pady=20)
        Button(self.__new_project_window,
               text="Create",
               command=self.heide.create_new_proj).grid(row=9,
                                                        column=1,
                                                        pady=30)

        self.__new_project_window.update()

    def close_new_proj(self):
        self.active_window = Window.HEIDE
        self.__new_project_window.destroy()