def __init__(self): gtk.VBox.__init__(self) self.all_app_default_value = {} style.draw_background_color(self) self.media_handle = MediaAutorun() self.app_manager = AppManager() self.init_table()
def setUp(self): self.app = create_app('testing') self.app_context = self.app.app_context() self.app_context.push() db.create_all() self.AM = AppManager() self.AM.init_app() self.AM.dataManager._store_permanent()
def __init__(self,database,parent=None): super(DatabaseEdit,self).__init__(parent) self.database=database self._initWindow() self.advanced=None self.units_manager=AppManager(self.database) self.units_manager.setWindowTitle(_('Databse Units Manager'))
def __init__(self): '''docstring for __''' gtk.VBox.__init__(self) style.draw_background_color(self) self.app = AppManager() self.content_type_list = [ self.app.http_content_type, self.app.mail_content_type, self.app.editor_content_type, self.app.audio_content_type, self.app.video_content_type, self.app.photo_content_type ] self.app_table() self.web.connect("item-selected", self.item_select, 0) self.mail.connect("item-selected", self.item_select, 1) self.editor.connect("item-selected", self.item_select, 2) self.music.connect("item-selected", self.item_select, 3) self.movie.connect("item-selected", self.item_select, 4) self.pic.connect("item-selected", self.item_select, 5)
def __init__(self): '''docstring for __''' gtk.VBox.__init__(self) style.draw_background_color(self) self.app = AppManager() self.content_type_list = [self.app.http_content_type, self.app.mail_content_type, self.app.editor_content_type, self.app.audio_content_type, self.app.video_content_type, self.app.photo_content_type] self.app_table() self.web.connect("item-selected", self.item_select, 0) self.mail.connect("item-selected", self.item_select, 1) self.editor.connect("item-selected", self.item_select, 2) self.music.connect("item-selected", self.item_select, 3) self.movie.connect("item-selected", self.item_select, 4) self.pic.connect("item-selected", self.item_select, 5)
class AppManagerTestCases(unittest.TestCase): def setUp(self): self.app = create_app('testing') self.app_context = self.app.app_context() self.app_context.push() db.create_all() self.AM = AppManager() self.AM.init_app() self.AM.dataManager._store_permanent() def tearDown(self): db.session.remove() db.drop_all() self.app_context.pop() def test_register_device(self): config = { 'device_id': 15, 'device_class': 'name', 'device_type': 'car', 'address': 'home' } device = mock.Mock() self.AM.deviceManager.new_device = mock.Mock(return_value=device) self.AM.dataManager.save_device = mock.Mock() self.AM.dataManager.event_device_start = mock.Mock() # correct behaviour result = Response(True, None, None) self.assertEqual(self.AM.register_device(config), result) # exception in progress e = AttributeError("Device missing attribute") result = Response(False, None, e) self.AM.deviceManager.new_device = mock.Mock(side_effect=e) self.assertEqual(self.AM.register_device(config), result) def test_end_device(self): device_id = 23 self.AM.deviceManager.remove_device = mock.Mock() self.AM.dataManager.update_experiment = mock.Mock() self.AM.dataManager.event_device_end = mock.Mock() # correct behaviour result = Response(True, None, None) self.assertEqual(self.AM.end_device(device_id), result) # exception in progress e = IdError('Connector with given ID: %s was not found' % device_id) self.AM.deviceManager.remove_device = mock.Mock(side_effect=KeyError) result = Response(False, None, e) self.assertEqual(self.AM.end_device(device_id), result) def test_command(self): config = {'device_id': 23, 'command_id': '3', 'arguments': '[30]'} result = Command(23, '3', [30], 'external') result.save_command_to_db = mock.Mock() device = mock.Mock() device.post_command = mock.Mock() self.AM.deviceManager.get_device = mock.Mock(return_value=device) # correct behaviour result = Response(True, None, None) command = mock.Mock() command.save_command_to_db = mock.Mock() self.AM._create_command = mock.Mock(return_value=device) self.assertEqual(self.AM.command(config), result) # exception in progress e = AttributeError("Command missing attribute") result = Response(False, None, e) self.AM.deviceManager.get_device = mock.Mock(side_effect=e) self.assertEqual(self.AM.command(config), result) def test_register_task(self): config = { 'task_id': 23, 'task_class': 'PSI', 'task_type': 'PBR_measure_all' } task = mock.Mock() task.start = mock.Mock() self.AM.taskManager.create_task = mock.Mock(return_value=task) self.AM.dataManager.event_task_start = mock.Mock() # correct behaviour result = Response(True, None, None) self.assertEqual(self.AM.register_task(config), result) # exception in progress e = AttributeError("Task missing attribute") result = Response(False, None, e) self.AM.taskManager.create_task = mock.Mock(side_effect=e) self.assertEqual(self.AM.register_task(config), result) def test_end_task(self): task_id = 23 self.AM.taskManager.remove_task = mock.Mock() self.AM.dataManager.event_task_end = mock.Mock() # correct behaviour result = Response(True, None, None) self.assertEqual(self.AM.end_task(task_id), result) # exception in progress e = IdError("Task with requested ID: 23 was not found") result = Response(False, None, e) self.AM.taskManager.remove_task = mock.Mock(side_effect=KeyError) self.assertEqual(self.AM.end_task(task_id), result) def test_ping(self): device_data = {'device_data': 'data01'} task_data = {'task_data': 'data02'} self.AM.deviceManager.ping = mock.Mock(return_value=device_data) self.AM.taskManager.ping = mock.Mock(return_value=task_data) # correct behaviour result = Response(True, { 'devices': device_data, 'tasks': task_data }, None) self.assertEqual(self.AM.ping(), result) def get_data(self): config = { 'time': '20211010101010333', 'device_id': 23, 'type': 'values' } data = {'some random data': 123} self.AM.dataManager.get_data = mock.Mock(return_value=data) # correct behaviour result = Response(True, data, None) self.assertEqual(self.AM.get_data(config), result) # exception in progress e = AttributeError("Missing a key attribute.") result = Response(False, None, e) self.AM.dataManager.get_data = mock.Mock(side_effect=e) self.assertEqual(self.AM.get_data(config), result) def test_get_latest_data(self): config = {'device_id': 23, 'type': 'values'} data = {'some random data': 123} self.AM.dataManager.get_latest_data = mock.Mock(return_value=data) # correct behaviour result = Response(True, data, None) self.assertEqual(self.AM.get_latest_data(config), result) # exception in progress e = AttributeError("Missing a key attribute.") result = Response(False, None, e) self.AM.dataManager.get_latest_data = mock.Mock(side_effect=e) self.assertEqual(self.AM.get_latest_data(config), result)
class AppView(gtk.VBox): ENTRY_WIDTH = 200 LEFT_WIDTH = STANDARD_LINE - TEXT_WINDOW_LEFT_PADDING def __init__(self): '''docstring for __''' gtk.VBox.__init__(self) style.draw_background_color(self) self.app = AppManager() self.content_type_list = [self.app.http_content_type, self.app.mail_content_type, self.app.editor_content_type, self.app.audio_content_type, self.app.video_content_type, self.app.photo_content_type] self.app_table() self.web.connect("item-selected", self.item_select, 0) self.mail.connect("item-selected", self.item_select, 1) self.editor.connect("item-selected", self.item_select, 2) self.music.connect("item-selected", self.item_select, 3) self.movie.connect("item-selected", self.item_select, 4) self.pic.connect("item-selected", self.item_select, 5) def app_table(self): # Labels #info_label = Label("您可以根据自己需要对深度系统在默认情况下使用的程序进行设置") web_label = Label(_("Web")) mail_label = Label(_("Mail")) editor_label = Label(_("Editor")) music_label = Label(_("Music")) movie_label = Label(_("Video")) pic_label = Label(_("Photo")) terminal_label = Label(_("Terminal")) self.web = ComboBox([("None",0)], fixed_width=self.ENTRY_WIDTH) self.mail = ComboBox([("None",0)], fixed_width=self.ENTRY_WIDTH) self.editor = ComboBox([("None",0)], fixed_width=self.ENTRY_WIDTH) self.music = ComboBox([("None",0)], fixed_width=self.ENTRY_WIDTH) self.movie = ComboBox([("None",0)], fixed_width=self.ENTRY_WIDTH) self.pic = ComboBox([("None",0)], fixed_width=self.ENTRY_WIDTH) self.terminal = self.get_terminal_combo() table = gtk.Table(8, 2, False) #table.attach(style.wrap_with_align(info_label), 0, 2, 0, 1) table.attach(style.wrap_with_align(web_label, width=self.LEFT_WIDTH), 0, 1, 1, 2) table.attach(style.wrap_with_align(mail_label, width=self.LEFT_WIDTH), 0, 1, 2, 3) table.attach(style.wrap_with_align(editor_label, width=self.LEFT_WIDTH), 0, 1, 3, 4) table.attach(style.wrap_with_align(music_label, width=self.LEFT_WIDTH), 0, 1, 4, 5) table.attach(style.wrap_with_align(movie_label, width=self.LEFT_WIDTH), 0, 1, 5, 6) table.attach(style.wrap_with_align(pic_label, width=self.LEFT_WIDTH), 0, 1, 6, 7) table.attach(style.wrap_with_align(terminal_label, width=self.LEFT_WIDTH), 0, 1, 7, 8) table.attach(style.wrap_with_align(self.web), 1, 2, 1, 2, 0) table.attach(style.wrap_with_align(self.mail),1, 2, 2, 3, 0) table.attach(style.wrap_with_align(self.editor), 1, 2, 3, 4) table.attach(style.wrap_with_align(self.music), 1, 2, 4, 5) table.attach(style.wrap_with_align(self.movie), 1, 2, 5, 6) table.attach(style.wrap_with_align(self.pic), 1, 2, 6, 7) table.attach(style.wrap_with_align(self.terminal), 1, 2, 7, 8) align = style.set_box_with_align(table, "text") style.set_table(table) self.pack_start(align, False, False) all_app_dict = self.get_all_app() #print all_app_dict apps = [self.web, self.mail, self.editor, self.music, self.movie, self.pic] for app in apps: app.set_size_request(self.ENTRY_WIDTH, 22) for key in all_app_dict.iterkeys(): if self.get_default_app: apps[key].add_items(all_app_dict[key]) else: apps[key].add_items(all_app_dict[key], clear_first = False) def attach_to(self, table, widget_list, row, width): for index, widget in enumerate(widget_list): align = style.wrap_with_align(widget, width=width[index]) table.attach(align, index, index + 1, row, row +1) def get_default_app(self): dic = {} for index, value in enumerate(self.content_type_list): default_app = self.app.get_default_for_type(value) if default_app: dic[index] = default_app return dic def get_terminal_combo(self): default_terminal = dmenu.get_default_terminal() terminal_apps = dmenu.get_terminal_apps() try: index = terminal_apps.index(default_terminal) except Exception, e: print e index = 0 combo_box = ComboBox([(exec_.capitalize(), exec_) for exec_ in terminal_apps], select_index=index, fixed_width=self.ENTRY_WIDTH) combo_box.connect("item-selected", self.on_terminal_item_selected) return combo_box
class AppView(gtk.VBox): ENTRY_WIDTH = 200 LEFT_WIDTH = STANDARD_LINE - TEXT_WINDOW_LEFT_PADDING def __init__(self): '''docstring for __''' gtk.VBox.__init__(self) style.draw_background_color(self) self.app = AppManager() self.content_type_list = [ self.app.http_content_type, self.app.mail_content_type, self.app.editor_content_type, self.app.audio_content_type, self.app.video_content_type, self.app.photo_content_type ] self.app_table() self.web.connect("item-selected", self.item_select, 0) self.mail.connect("item-selected", self.item_select, 1) self.editor.connect("item-selected", self.item_select, 2) self.music.connect("item-selected", self.item_select, 3) self.movie.connect("item-selected", self.item_select, 4) self.pic.connect("item-selected", self.item_select, 5) def app_table(self): # Labels #info_label = Label("您可以根据自己需要对深度系统在默认情况下使用的程序进行设置") web_label = Label(_("Web")) mail_label = Label(_("Mail")) editor_label = Label(_("Editor")) music_label = Label(_("Music")) movie_label = Label(_("Video")) pic_label = Label(_("Photo")) terminal_label = Label(_("Terminal")) self.web = ComboBox([("None", 0)], fixed_width=self.ENTRY_WIDTH) self.mail = ComboBox([("None", 0)], fixed_width=self.ENTRY_WIDTH) self.editor = ComboBox([("None", 0)], fixed_width=self.ENTRY_WIDTH) self.music = ComboBox([("None", 0)], fixed_width=self.ENTRY_WIDTH) self.movie = ComboBox([("None", 0)], fixed_width=self.ENTRY_WIDTH) self.pic = ComboBox([("None", 0)], fixed_width=self.ENTRY_WIDTH) self.terminal = self.get_terminal_combo() table = gtk.Table(8, 2, False) #table.attach(style.wrap_with_align(info_label), 0, 2, 0, 1) table.attach(style.wrap_with_align(web_label, width=self.LEFT_WIDTH), 0, 1, 1, 2) table.attach(style.wrap_with_align(mail_label, width=self.LEFT_WIDTH), 0, 1, 2, 3) table.attach( style.wrap_with_align(editor_label, width=self.LEFT_WIDTH), 0, 1, 3, 4) table.attach(style.wrap_with_align(music_label, width=self.LEFT_WIDTH), 0, 1, 4, 5) table.attach(style.wrap_with_align(movie_label, width=self.LEFT_WIDTH), 0, 1, 5, 6) table.attach(style.wrap_with_align(pic_label, width=self.LEFT_WIDTH), 0, 1, 6, 7) table.attach( style.wrap_with_align(terminal_label, width=self.LEFT_WIDTH), 0, 1, 7, 8) table.attach(style.wrap_with_align(self.web), 1, 2, 1, 2, 0) table.attach(style.wrap_with_align(self.mail), 1, 2, 2, 3, 0) table.attach(style.wrap_with_align(self.editor), 1, 2, 3, 4) table.attach(style.wrap_with_align(self.music), 1, 2, 4, 5) table.attach(style.wrap_with_align(self.movie), 1, 2, 5, 6) table.attach(style.wrap_with_align(self.pic), 1, 2, 6, 7) table.attach(style.wrap_with_align(self.terminal), 1, 2, 7, 8) align = style.set_box_with_align(table, "text") style.set_table(table) self.pack_start(align, False, False) all_app_dict = self.get_all_app() #print all_app_dict apps = [ self.web, self.mail, self.editor, self.music, self.movie, self.pic ] for app in apps: app.set_size_request(self.ENTRY_WIDTH, 22) for key in all_app_dict.iterkeys(): if self.get_default_app: apps[key].add_items(all_app_dict[key]) else: apps[key].add_items(all_app_dict[key], clear_first=False) def attach_to(self, table, widget_list, row, width): for index, widget in enumerate(widget_list): align = style.wrap_with_align(widget, width=width[index]) table.attach(align, index, index + 1, row, row + 1) def get_default_app(self): dic = {} for index, value in enumerate(self.content_type_list): default_app = self.app.get_default_for_type(value) if default_app: dic[index] = default_app return dic def get_terminal_combo(self): default_terminal = dmenu.get_default_terminal() terminal_apps = dmenu.get_terminal_apps() try: index = terminal_apps.index(default_terminal) except Exception, e: print e index = 0 combo_box = ComboBox([(exec_.capitalize(), exec_) for exec_ in terminal_apps], select_index=index, fixed_width=self.ENTRY_WIDTH) combo_box.connect("item-selected", self.on_terminal_item_selected) return combo_box
class MediaView(gtk.VBox): ENTRY_WIDTH = 200 LEFT_WIDTH = STANDARD_LINE - TEXT_WINDOW_LEFT_PADDING def __init__(self): gtk.VBox.__init__(self) self.all_app_default_value = {} style.draw_background_color(self) self.media_handle = MediaAutorun() self.app_manager = AppManager() self.init_table() def __get_index_from_value(self, value, _list): for tup in _list: if tup[1] == value: return _list.index(tup) def init_table(self): table = gtk.Table(8, 3, False) #info_label = Label(_("You can choose the operation after plugining media or device")) cd_label = Label(_("CD")) dvd_label = Label(_("DVD")) player_label = Label(_("Audio Player")) photo_label = Label(_("Camera")) software_label = Label(_("Applications")) auto_mount_label = Label(_("Automatically Mount")) self.all_label_list = [cd_label, dvd_label, player_label, photo_label, software_label] default_list = [(_("Other applications"), "other_app"), (_("Ask"), "ask"), (_("Do nothing"), "do_nothing"), (_("Open folder"),"open_folder")] auto_mount_list = [(_("Do nothing"), "do_nothing"), (_("Ask"), "ask"), (_("Mount"), "mount"), (_("Mount and open folder"), "mount_and_open")] #self.auto_mount_box = gtk.HBox(spacing = WIDGET_SPACING) #self.auto_mount_label = Label(_("apply auto open for all media and devices")) self.auto_mount_label = Label(_("AutoPlay")) self.auto_mount_toggle = ToggleButton(app_theme.get_pixbuf("toggle_button/inactive_normal.png"), app_theme.get_pixbuf("toggle_button/active_normal.png")) #self.auto_mount_box.pack_start(self.auto_mount_label, False, False) #self.auto_mount_box.pack_start(self.auto_mount_toggle, False, False) self.cd = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH) self.dvd = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH) self.player= ComboBox(default_list, fixed_width=self.ENTRY_WIDTH) self.photo = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH) self.software = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH) self.auto_mount = ComboBox(auto_mount_list, fixed_width=self.ENTRY_WIDTH) self.auto_mount.set_select_index(self.__get_index_from_value(get_auto_mount(), auto_mount_list)) #self.more_option = Button(_("more option")) ###below content type displayed as more option is clicked" self.audio_dvd = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH) self.blank_bd = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH) self.blank_cd = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH) self.blank_hddvd = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH) self.video_bluray = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH) self.ebook_reader = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH) self.video_hddvd = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH) self.image_picturecd = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH) self.video_svcd = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH) self.video_vcd = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH) #table.attach(style.wrap_with_align(info_label, width=self.LEFT_WIDTH), 0, 3, 0, 1) table.attach(style.wrap_with_align(cd_label, width=self.LEFT_WIDTH), 0, 1, 4, 5) table.attach(style.wrap_with_align(dvd_label, width=self.LEFT_WIDTH), 0, 1, 5, 6) table.attach(style.wrap_with_align(player_label, width=self.LEFT_WIDTH), 0, 1, 6, 7) table.attach(style.wrap_with_align(photo_label, width=self.LEFT_WIDTH), 0, 1, 7, 8) table.attach(style.wrap_with_align(software_label, width=self.LEFT_WIDTH), 0, 1, 8, 9) table.attach(style.wrap_with_align(auto_mount_label, width=self.LEFT_WIDTH), 0, 1, 9, 10) #table.attach(style.wrap_with_align(self.auto_mount_box, align = "left", left = 180), 0, 3, 1, 2) table.attach(style.wrap_with_align(self.auto_mount_label, width=self.LEFT_WIDTH), 0, 1, 1, 2) table.attach(style.wrap_with_align(self.auto_mount_toggle), 1, 3, 1, 2) table.attach(style.wrap_with_align(self.cd), 1, 3, 4, 5) table.attach(style.wrap_with_align(self.dvd), 1, 3, 5, 6) table.attach(style.wrap_with_align(self.player), 1, 3, 6, 7) table.attach(style.wrap_with_align(self.photo), 1, 3, 7, 8) table.attach(style.wrap_with_align(self.software), 1, 3, 8, 9) table.attach(style.wrap_with_align(self.auto_mount), 1, 3, 9, 10) # UI style table_align = style.set_box_with_align(table, "text") style.set_table(table) self.pack_start(table_align, False, False) combo_list = [self.cd, self.dvd, self.player, self.photo, self.software] for combo in combo_list: combo.set_size_request(self.ENTRY_WIDTH, 22) self.refresh_app_list(default_list) self.media_handle.auto_mount = True if self.media_handle.automount_open: for combo in self.all_app_dict: combo.set_sensitive(True) for l in self.all_label_list: l.set_sensitive(True) else: for combo in self.all_app_dict: combo.set_sensitive(False) for l in self.all_label_list: l.set_sensitive(False) self.auto_mount_toggle.set_active(self.media_handle.automount_open) self.connect_signal_to_combos() def refresh_app_list(self, default_list): self.default_list = default_list self.all_app_dict = {self.cd: self.media_handle.cd_content_type, self.dvd: self.media_handle.dvd_content_type, self.player: self.media_handle.player_content_type, self.photo: self.media_handle.photo_content_type, self.software: self.media_handle.software_content_type, } for key, value in self.all_app_dict.iteritems(): app_info_list = [] app_info_list.extend(self.app_manager.get_all_for_type(value)) state = self.get_state(value) if state == "set_default": default_value = 0 else: default_value = len(app_info_list) + ["ask", "do_nothing","open_folder"].index(state) + 1 key.add_items(map(lambda info:(info.get_name(), info), app_info_list) + default_list, select_index=default_value) self.all_app_default_value = {self.cd: self.cd.get_select_index(), self.dvd: self.dvd.get_select_index(), self.player: self.player.get_select_index(), self.photo: self.photo.get_select_index(), self.software: self.software.get_select_index(), } def connect_signal_to_combos(self): for combo in self.all_app_dict: combo.connect("item-selected", self.change_autorun_callback) self.auto_mount.connect("item-selected", self.auto_mount_combo_changed) self.auto_mount_toggle.connect("toggled", self.automount_open_toggle_cb) def auto_mount_combo_changed(self, widget, content, value, index): set_auto_mount(value) def change_autorun_callback(self, widget, content, value, index): if value != "other_app": self.all_app_default_value[widget] = index if type(value) is not str: self.set_media_handler_preference(self.all_app_dict[widget], widget, "set_default") self.app_manager.set_default_for_type(value, self.all_app_dict[widget]) else: self.set_media_handler_preference(self.all_app_dict[widget], widget, value) def automount_open_toggle_cb(self, widget): self.media_handle.automount_open = widget.get_active() if widget.get_active(): for combo in self.all_app_dict: combo.set_sensitive(True) for l in self.all_label_list: l.set_sensitive(True) else: for combo in self.all_app_dict: combo.set_sensitive(False) for l in self.all_label_list: l.set_sensitive(False) def set_media_handler_preference(self, x_content, widget, action_name=None): if action_name == "ask": self.media_handle.remove_x_content_start_app(x_content) self.media_handle.remove_x_content_ignore(x_content) self.media_handle.remove_x_content_open_folder(x_content) print action_name, ">>>",self.get_state(x_content) elif action_name == "do_nothing": self.media_handle.remove_x_content_start_app(x_content) self.media_handle.add_x_content_ignore(x_content) self.media_handle.remove_x_content_open_folder(x_content) print action_name, ">>>",self.get_state(x_content) elif action_name == "open_folder": self.media_handle.remove_x_content_start_app(x_content) self.media_handle.remove_x_content_ignore(x_content) self.media_handle.add_x_content_open_folder(x_content) print action_name, ">>>",self.get_state(x_content) elif action_name == "set_default": self.media_handle.add_x_content_start_app(x_content) self.media_handle.remove_x_content_ignore(x_content) self.media_handle.remove_x_content_open_folder(x_content) print action_name, ">>>",self.get_state(x_content) else: from dtk.ui.dialog import OpenFileDialog OpenFileDialog( _("Other applications"), self.get_toplevel(), lambda name: self.add_app_info(name, x_content), self.__cancel_other_application(widget)) def __cancel_other_application(self, widget): widget.set_select_index(self.all_app_default_value[widget]) def add_app_info(self, app_name, x_content): import os app_name = os.path.basename(app_name) app_info = self.app_manager.get_app_info(app_name + " %u", app_name) self.set_media_handler_preference(x_content, "set_default") self.app_manager.set_default_for_type(app_info, x_content) self.app_manager.get_all_for_type(x_content) self.refresh_app_list(self.default_list) def get_state(self, x_content): start_up = self.media_handle.autorun_x_content_start_app ignore = self.media_handle.autorun_x_content_ignore open_folder = self.media_handle.autorun_x_content_open_folder start_up_flag = x_content in start_up ignore_flag = x_content in ignore open_folder_flag = x_content in open_folder if start_up_flag: return "set_default" elif ignore_flag: return "do_nothing" elif open_folder_flag: return "open_folder" else: return "ask"
class DatabaseEdit(QDialog): def __init__(self,database,parent=None): super(DatabaseEdit,self).__init__(parent) self.database=database self._initWindow() self.advanced=None self.units_manager=AppManager(self.database) self.units_manager.setWindowTitle(_('Databse Units Manager')) def _initWindow(self): self.layout=QVBoxLayout(self) self.key_edit=QLineEdit() self.synonym_edit=QLineEdit() self.reply_edit=QLineEdit() self.add_button=QPushButton(_('add')) self.del_button=QPushButton(_('delete')) self.manage_units_button=QPushButton(_('manage units')) self.advanced_button=QPushButton(_('advanced setting')) self.save_button=QPushButton(_('save')) QObject.connect(self.add_button,SIGNAL("released()"),self._add) QObject.connect(self.del_button,SIGNAL("released()"),self._remove) QObject.connect(self.manage_units_button,SIGNAL("released()"),self._manage_units) QObject.connect(self.save_button,SIGNAL("released()"),self._save) QObject.connect(self.advanced_button,SIGNAL("released()"),self._showAdvancedSetting) key_layout=QHBoxLayout() key_layout.addWidget(QLabel(_('key'))) key_layout.addWidget(self.key_edit) self.layout.addLayout(key_layout) synonym_layout=QHBoxLayout() synonym_layout.addWidget(QLabel(_('synonym'))) synonym_layout.addWidget(self.synonym_edit) self.layout.addLayout(synonym_layout) reply_layout=QHBoxLayout() reply_layout.addWidget(QLabel(_('reply'))) reply_layout.addWidget(self.reply_edit) self.layout.addLayout(reply_layout) b_layout_e=QHBoxLayout() b_layout_e.addWidget(self.add_button) b_layout_e.addWidget(self.del_button) self.layout.addLayout(b_layout_e) b_layout_s=QHBoxLayout() b_layout_s.addWidget(self.manage_units_button) b_layout_s.addWidget(self.advanced_button) self.layout.addLayout(b_layout_s) self.layout.addWidget(self.save_button) def _add(self): ks=unicode(self.key_edit.text()) ss=unicode(self.synonym_edit.text()) rs=unicode(self.reply_edit.text()) if ks: self.key_edit.clear() if ss: self.database.addKey(ks,ss) self.synonym_edit.clear() if rs: self.database.addValue(ks,rs) self.reply_edit.clear() def _remove(self): ks=unicode(self.key_edit.text()) ss=unicode(self.synonym_edit.text()) rs=unicode(self.reply_edit.text()) if ks: self.database.removeKey(ks) self.key_edit.clear() if rs: self.database.removeValue(rs) self.reply_edit.clear() def _save(self): self.database.save() def _manage_units(self): self.units_manager.show() def _showAdvancedSetting(self): if self.advanced: self.advanced.close() self.advanced=DatabaseAdvancedSetting(self.database,parent=self) self.advanced.setWindowTitle(self.windowTitle()) self.advanced.show() def show(self,key=None): if key is not None: self.key_edit.setText(key) super(DatabaseEdit,self).show()