isset($_MENU[$action])详细来说是什么意思?

isset函数用来判断一个变量是否存在。

$_GET['action'])是用get方式取客户端向服务器发送的数据段中action字段,

同理$_POST['action']就是用post方式取这个字段。

同理$_MENU['action']就是用menu方式取这个字段。

<?php /* Plugin Name: 多功能 WordPress 插件 Plugin URI: https://yourwebsite.com/plugins/multifunctional Description: 包含置顶、网页宠物、哀悼模式、禁止复制、弹幕等 20+ 功能的综合插件 Version: 1.0.0 Author: Your Name Author URI: https://yourwebsite.com License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html Text Domain: multifunctional-plugin Domain Path: /languages */ // 防止直接访问 if (!defined('ABSPATH')) { exit; } // 定义插件常量 define('MULTI_PLUGIN_DIR', plugin_dir_path(__FILE__)); define('MULTI_PLUGIN_URL', plugin_dir_url(__FILE__)); define('MULTI_PLUGIN_VERSION', '1.0.0'); // 全局设置存储键 $multi_plugin_options = array( 'mourning_date', 'background_image', 'announcement', 'marquee_content', 'watermark_text' ); // ------------------------------ // 1. 置顶功能 // ------------------------------ function multi_post_sticky_meta_box() { add_meta_box( 'post_sticky', '文章置顶', 'multi_post_sticky_callback', 'post', 'side', 'default' ); } add_action('add_meta_boxes', 'multi_post_sticky_meta_box'); function multi_post_sticky_callback($post) { $sticky = get_post_meta($post->ID, '_post_sticky', true); wp_nonce_field('post_sticky_nonce', 'post_sticky_nonce'); echo '<label><input type="checkbox" name="post_sticky" value="1" ' . checked(1, $sticky, false) . '> 置顶此文章</label>'; } function multi_post_sticky_save($post_id) { if (!isset($_POST['post_sticky_nonce']) || !wp_verify_nonce($_POST['post_sticky_nonce'], 'post_sticky_nonce')) { return; } if (isset($_POST['post_sticky'])) { update_post_meta($post_id, '_post_sticky', 1); } else { delete_post_meta($post_id, '_post_sticky'); } } add_action('save_post', 'multi_post_sticky_save'); // ------------------------------ // 2. 网页宠物 // ------------------------------ function multi_web_pet() { echo '<div id="web-pet" style="position:fixed;bottom:20px;right:20px;z-index:9999;">'; echo '<img src="' . MULTI_PLUGIN_URL . 'assets/pet.png" alt="网页宠物" width="80">'; echo '</div>'; } add_action('wp_footer', 'multi_web_pet'); // ------------------------------ // 3. 哀悼模式 // ------------------------------ function multi_mourning_mode() { $mourning_date = get_option('multi_mourning_date', '2025-04-29'); // 默认日期 if (date('Y-m-d') === $mourning_date) { echo '<style>html { filter: grayscale(100%); }</style>'; } } add_action('wp_head', 'multi_mourning_mode'); // ------------------------------ // 4. 禁止复制 & 查看源码 // ------------------------------ function multi_disable_copy_source() { // 禁止复制样式 echo '<style>body { user-select: none; -moz-user-select: none; -webkit-user-select: none; }</style>'; // 禁止查看源码脚本 echo '<script>document.addEventListener("keydown", function(e) { if ((e.ctrlKey && e.key === "u") || e.key === "F12" || e.keyCode === 123) { e.preventDefault(); } });</script>'; } add_action('wp_head', 'multi_disable_copy_source'); // ------------------------------ // 5. 弹幕功能 // ------------------------------ function multi_danmaku() { echo '<div id="danmaku-container"></div>'; echo '<script src="' . MULTI_PLUGIN_URL . 'assets/danmaku.js"></script>'; // 需自行添加弹幕逻辑脚本 } add_action('wp_footer', 'multi_danmaku'); // ------------------------------ // 6. WP 优化 // ------------------------------ function multi_wp_optimization() { // 移除冗余功能 remove_action('wp_head', 'rsd_link'); remove_action('wp_head', 'wlwmanifest_link'); remove_action('wp_head', 'wp_generator'); remove_action('wp_head', 'feed_links', 2); remove_action('wp_print_styles', 'print_emoji_styles'); } add_action('init', 'multi_wp_optimization'); // ------------------------------ // 7. 媒体分类 // ------------------------------ function multi_media_category() { register_taxonomy( 'media_category', 'attachment', array( 'label' => __('媒体分类', 'multifunctional-plugin'), 'hierarchical' => true, 'show_ui' => true, 'query_var' => true ) ); } add_action('init', 'multi_media_category'); // ------------------------------ // 8. 预加载首页 // ------------------------------ function multi_preload_homepage() { echo '<link rel="preload" href="' . home_url() . '" as="document">'; } add_action('wp_head', 'multi_preload_homepage'); // ------------------------------ // 9. 在线客服 & 手机客服 // ------------------------------ function multi_support_buttons() { // 通用客服按钮 echo '<div id="support-button" class="desktop-only">'; echo '<a href="https://your客服链接.com" target="_blank">在线客服</a>'; echo '</div>'; // 手机端专属客服按钮 echo '<div id="mobile-support" class="mobile-only">'; echo '<a href="tel:1234567890">手机客服</a>'; echo '</div>'; } add_action('wp_footer', 'multi_support_buttons'); // ------------------------------ // 10. 网站背景 & 公告 // ------------------------------ function multi_background_announcement() { // 背景图片 $bg_image = get_option('multi_background_image', MULTI_PLUGIN_URL . 'assets/bg.jpg'); echo '<style>body { background-image: url("' . esc_url($bg_image) . '"); }</style>'; // 公告栏 $announcement = get_option('multi_announcement', '欢迎访问我们的网站!'); echo '<div class="site-announcement">' . esc_html($announcement) . '</div>'; } add_action('wp_head', 'multi_background_announcement'); // ------------------------------ // 11. 水印功能 // ------------------------------ function multi_watermark() { $watermark = get_option('multi_watermark_text', '版权所有 © 你的网站'); echo '<style> body::after { content: "' . esc_attr($watermark) . '"; position: fixed; top: 50%; left: 50%; transform: rotate(-45deg) translate(-50%, -50%); opacity: 0.1; font-size: 80px; color: #000; pointer-events: none; } </style>'; } add_action('wp_head', 'multi_watermark'); // ------------------------------ // 12. 后台设置页面 // ------------------------------ function multi_plugin_settings_page() { add_options_page( '多功能插件设置', '多功能插件', 'manage_options', 'multi-plugin-settings', 'multi_settings_html' ); } add_action('admin_menu', 'multi_plugin_settings_page'); function multi_settings_html() { if (!current_user_can('manage_options')) { wp_die(__('你没有权限访问此页面。')); } if (isset($_POST['multi_plugin_save'])) { foreach ($multi_plugin_options as $option) { update_option('multi_' . $option, sanitize_text_field($_POST[$option])); } echo '<div class="updated"><p>设置已保存!</p></div>'; } $options = array(); foreach ($multi_plugin_options as $option) { $options[$option] = get_option('multi_' . $option, ''); } ?> <div class="wrap"> <h1>多功能插件设置</h1> <form method="post"> <table class="form-table"> <tr> <th>哀悼日期 (YYYY-MM-DD)</th> <td><input type="text" name="mourning_date" value="<?php echo esc_attr($options['mourning_date']); ?>"></td> </tr> <tr> <th>背景图片 URL</th> <td><input type="url" name="background_image" value="<?php echo esc_attr($options['background_image']); ?>"></td> </tr> <tr> <th>公告内容</th> <td><input type="text" name="announcement" value="<?php echo esc_attr($options['announcement']); ?>"></td> </tr> <tr> <th>跑马灯内容</th> <td><input type="text" name="marquee_content" value="<?php echo esc_attr($options['marquee_content']); ?>"></td> </tr> <tr> <th>水印文本</th> <td><input type="text" name="watermark_text" value="<?php echo esc_attr($options['watermark_text']); ?>"></td> </tr> </table> <p class="submit"> <input type="submit" name="multi_plugin_save" class="button button-primary" value="保存设置"> </p> </form> </div> <?php } // ------------------------------ // 插件激活时创建默认设置 // ------------------------------ function multi_plugin_activate() { foreach ($multi_plugin_options as $option) { $default = ($option === 'mourning_date') ? '2025-04-29' : ''; add_option('multi_' . $option, $default); } } register_activation_hook(__FILE__, 'multi_plugin_activate'); // ------------------------------ // 资源路径说明(需手动创建目录) // ------------------------------ /* 请在插件目录下创建以下文件夹和文件: - assets/ - pet.png (网页宠物图片) - bg.jpg (默认背景图片) - danmaku.js (弹幕逻辑脚本) - style.css (自定义样式) */
05-01
..\Src\menu.c(89): error: #167: argument of type "const char *" is incompatible with parameter of type "char *" OLED_ShowString((128 - strlen(menu->title)*6)/2, 0, menu->title); ..\Src\menu.c(108): error: #167: argument of type "const char *" is incompatible with parameter of type "char *" OLED_ShowString(6, displayLine, menu->items[i].text); ..\Src\menu.c(110): error: #167: argument of type "const char *" is incompatible with parameter of type "char *"#include "menu.h" #include "main.h" // ??GPIO?? #define KEY_UP_PIN GPIO_PIN_2 #define KEY_DOWN_PIN GPIO_PIN_3 #define KEY_ENTER_PIN GPIO_PIN_4 #define KEY_BACK_PIN GPIO_PIN_5 // ?????? #define KEY_PORT GPIOE // ???????? static void Power_On(void); static void Power_Off(void); static void Set_Voltage_Value(void); static void Set_Current_Value(void); static void Save_Settings(void); static void Factory_Reset(void); // ???????? static MenuItem voltageMenuItems[] = { {"Set Voltage", Set_Voltage_Value, NULL}, {"Back", Menu_BackToParent, NULL} }; // ???????? static MenuItem currentMenuItems[] = { {"Set Current", Set_Current_Value, NULL}, {"Back", Menu_BackToParent, NULL} }; // ???????? static MenuItem settingsMenuItems[] = { {"Save Settings", Save_Settings, NULL}, {"Factory Reset", Factory_Reset, NULL}, {"Back", Menu_BackToParent, NULL} }; // ???? static MenuItem mainMenuItems[] = { {"Power On", Power_On, NULL}, {"Power Off", Power_Off, NULL}, {"Set Voltage", NULL, &voltageMenu}, {"Set Current", NULL, &currentMenu}, {"System Settings", NULL, &settingsMenu} }; // ???? Menu voltageMenu = { .title = "VOLTAGE SETTING", .items = voltageMenuItems, .count = sizeof(voltageMenuItems)/sizeof(MenuItem), .selected = 0, .parent = &mainMenu }; Menu currentMenu = { .title = "CURRENT SETTING", .items = currentMenuItems, .count = sizeof(currentMenuItems)/sizeof(MenuItem), .selected = 0, .parent = &mainMenu }; Menu settingsMenu = { .title = "SYSTEM SETTINGS", .items = settingsMenuItems, .count = sizeof(settingsMenuItems)/sizeof(MenuItem), .selected = 0, .parent = &mainMenu }; Menu mainMenu = { .title = "MAIN MENU", .items = mainMenuItems, .count = sizeof(mainMenuItems)/sizeof(MenuItem), .selected = 0, .parent = NULL }; // ?????? static Menu *currentMenuPtr = &mainMenu; void Menu_Init(void) { // ??????????? } void Menu_Draw(Menu *menu) { OLED_Clear(); OLED_ShowString((128 - strlen(menu->title)*6)/2, 0, menu->title); for(int i = 0; i < 128; i++) { OLED_ShowChar(i, 1, '-'); } uint8_t startIdx = 0; if(menu->selected > 3) { startIdx = menu->selected - 3; } uint8_t endIdx = startIdx + 4; if(endIdx > menu->count) { endIdx = menu->count; } for(uint8_t i = startIdx; i < endIdx; i++) { uint8_t displayLine = i - startIdx + 2; if(i == menu->selected) { OLED_ShowString(0, displayLine, ">"); OLED_ShowString(6, displayLine, menu->items[i].text); } else { OLED_ShowString(6, displayLine, menu->items[i].text); } if(menu->items[i].submenu != NULL) { OLED_ShowString(120, displayLine, ">"); } } // ????? if(menu->count > 4) { uint8_t barHeight = 32 * 4 / menu->count; uint8_t barPos = 32 * menu->selected / menu->count; for(uint8_t i = 0; i < barHeight; i++) { OLED_ShowChar(124, 2 + barPos + i, '|'); } } // ?????? if(menu->parent != NULL) { OLED_ShowString(0, 6, "B:Back"); } } KeyPress Menu_GetKey(void) { static uint8_t last_state = 0; uint8_t current_state = HAL_GPIO_ReadPin(KEY_PORT, KEY_UP_PIN) << 0 | HAL_GPIO_ReadPin(KEY_PORT, KEY_DOWN_PIN) << 1 | HAL_GPIO_ReadPin(KEY_PORT, KEY_ENTER_PIN) << 2 | HAL_GPIO_ReadPin(KEY_PORT, KEY_BACK_PIN) << 3; // ???? if(current_state != last_state) { HAL_Delay(20); current_state = HAL_GPIO_ReadPin(KEY_PORT, KEY_UP_PIN) << 0 | HAL_GPIO_ReadPin(KEY_PORT, KEY_DOWN_PIN) << 1 | HAL_GPIO_ReadPin(KEY_PORT, KEY_ENTER_PIN) << 2 | HAL_GPIO_ReadPin(KEY_PORT, KEY_BACK_PIN) << 3; } last_state = current_state; if(!HAL_GPIO_ReadPin(KEY_PORT, KEY_UP_PIN)) return KEY_UP; if(!HAL_GPIO_ReadPin(KEY_PORT, KEY_DOWN_PIN)) return KEY_DOWN; if(!HAL_GPIO_ReadPin(KEY_PORT, KEY_ENTER_PIN)) return KEY_ENTER; if(!HAL_GPIO_ReadPin(KEY_PORT, KEY_BACK_PIN)) return KEY_BACK; return KEY_NONE; } void Menu_Process(Menu **currentMenu) { KeyPress key = Menu_GetKey(); switch(key) { case KEY_UP: if((*currentMenu)->selected > 0) { (*currentMenu)->selected--; } break; case KEY_DOWN: if((*currentMenu)->selected < (*currentMenu)->count - 1) { (*currentMenu)->selected++; } break; case KEY_ENTER: if((*currentMenu)->items[(*currentMenu)->selected].submenu != NULL) { // ????? *currentMenu = (*currentMenu)->items[(*currentMenu)->selected].submenu; } else if((*currentMenu)->items[(*currentMenu)->selected].action != NULL) { // ??????? (*currentMenu)->items[(*currentMenu)->selected].action(); } break; case KEY_BACK: if((*currentMenu)->parent != NULL) { // ????? *currentMenu = (*currentMenu)->parent; } break; default: break; } } void Menu_EnterSubmenu(Menu *submenu) { currentMenuPtr = submenu; } void Menu_BackToParent(void) { if(currentMenuPtr->parent != NULL) { currentMenuPtr = currentMenuPtr->parent; } } // ???????? static void Power_On(void) { OLED_Clear(); OLED_ShowString(20, 2, "Power ON"); OLED_ShowString(10, 4, "Selected"); // ???????? // HAL_GPIO_WritePin(POWER_GPIO_Port, POWER_Pin, GPIO_PIN_SET); HAL_Delay(1000); } static void Power_Off(void) { OLED_Clear(); OLED_ShowString(20, 2, "Power OFF"); OLED_ShowString(10, 4, "Selected"); // ???????? // HAL_GPIO_WritePin(POWER_GPIO_Port, POWER_Pin, GPIO_PIN_RESET); HAL_Delay(1000); } static void Set_Voltage_Value(void) { static uint16_t voltage = 0; uint8_t exitFlag = 0; OLED_Clear(); OLED_ShowString(20, 0, "SET VOLTAGE"); while(!exitFlag) { char buf[20]; sprintf(buf, "Voltage: %d.%dV", voltage/10, voltage%10); OLED_ShowString(10, 2, buf); OLED_ShowString(10, 4, "UP/DOWN: Adjust"); OLED_ShowString(10, 5, "ENTER: Confirm"); OLED_ShowString(10, 6, "BACK: Cancel"); KeyPress key = Menu_GetKey(); switch(key) { case KEY_UP: if(voltage < 300) voltage += 1; break; case KEY_DOWN: if(voltage > 0) voltage -= 1; break; case KEY_ENTER: // ?????? exitFlag = 1; OLED_ShowString(10, 3, "Setting saved!"); HAL_Delay(1000); break; case KEY_BACK: exitFlag = 1; break; default: break; } HAL_Delay(50); } } static void Set_Current_Value(void) { static uint16_t current = 0; uint8_t exitFlag = 0; OLED_Clear(); OLED_ShowString(20, 0, "SET CURRENT"); while(!exitFlag) { char buf[20]; sprintf(buf, "Current: %d.%dA", current/10, current%10); OLED_ShowString(10, 2, buf); OLED_ShowString(10, 4, "UP/DOWN: Adjust"); OLED_ShowString(10, 5, "ENTER: Confirm"); OLED_ShowString(10, 6, "BACK: Cancel"); KeyPress key = Menu_GetKey(); switch(key) { case KEY_UP: if(current < 50) current += 1; break; case KEY_DOWN: if(current > 0) current -= 1; break; case KEY_ENTER: // ?????? exitFlag = 1; OLED_ShowString(10, 3, "Setting saved!"); HAL_Delay(1000); break; case KEY_BACK: exitFlag = 1; break; default: break; } HAL_Delay(50); } } static void Save_Settings(void) { OLED_Clear(); OLED_ShowString(30, 2, "Saving..."); // ???????? HAL_Delay(500); OLED_ShowString(20, 4, "Settings saved!"); HAL_Delay(1000); } static void Factory_Reset(void) { OLED_Clear(); OLED_ShowString(10, 2, "Factory Reset?"); OLED_ShowString(10, 4, "ENTER: Confirm"); OLED_ShowString(10, 5, "BACK: Cancel"); uint8_t exitFlag = 0; while(!exitFlag) { KeyPress key = Menu_GetKey(); switch(key) { case KEY_ENTER: // ???????? OLED_Clear(); OLED_ShowString(20, 3, "Resetting..."); HAL_Delay(1000); // ???????? exitFlag = 1; break; case KEY_BACK: exitFlag = 1; break; default: break; } HAL_Delay(50); } }帮我修改 OLED_ShowString(6, displayLine, menu->items[i].text);
最新发布
07-11
下面这段是PHP5.6,如何改成PHP8.4? <?php require_once("include/global.php"); ?> <html> <head> <?php echo getMeta('gb') ?> <title><?php echo $_GLOBAL_CONF['SITE_NAME'] ?></title> </head> <link rel="stylesheet" href="/common.css" type="text/css"> <style> a {color:#616651} .img1 {border:solid 0 black} </style> <BODY link=#cc0000 leftMargin=0 topMargin=0 marginwidth="0" marginheight="0"> <?php require_once("include/header.php"); ?> <?php /* <div id=ad_dl01 style="z-index:1; visibility:visible; width:100px; position:absolute; top:115px; right:5px;"> <table border=0 cellspacing=0 cellpadding=0 width=300 style="table-layout:fixed; word-break:break-all" bgcolor=#d3e9FF> <tr> <td><iframe width="300" height="200" style="border: solid 1px black; width: 600px; height: 30px;" frameborder="0"></iframe></td> </tr> </table> </div> <script type=text/javascript> var step_ratio = 0.1; objs = new Array(); objs_x = new Array(); objs_y = new Array(); function addfollowmark(name, x, y) { i = objs.length; objs[i] = document.getElementById(name); objs_x[i] = x; objs_y[i] = y; } function followmark() { for(var i=0; i<objs.length; i++) { var fm = objs[i]; var fm_x = typeof(objs_x[i]) == 'string' ? eval(objs_x[i]) : objs_x[i]; var fm_y = typeof(objs_y[i]) == 'string' ? eval(objs_y[i]) : objs_y[i]; if (fm.offsetLeft != document.body.scrollLeft + fm_x) { var dx = (document.body.scrollLeft + fm_x - fm.offsetLeft) * step_ratio; dx = (dx > 0 ? 1 : -1) * Math.ceil(Math.abs(dx)); fm.style.left = fm.offsetLeft + dx; } if (fm.offsetTop != document.body.scrollTop + fm_y) { var dy = (document.body.scrollTop + fm_y - fm.offsetTop) * step_ratio; dy = (dy > 0 ? 1 : -1) * Math.ceil(Math.abs(dy)); fm.style.top = fm.offsetTop + dy; } fm.style.display = ''; } } addfollowmark("ad_dl01", "document.body.clientWidth-305", 115); setInterval('followmark()',20); </script> */ ?> <center> <table width=95% border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="2"><img src="images/tb_left.jpg" width="2" height="28" /></td> <td background="images/tb_bg.jpg"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <?php if($_SESSION['ss_admin']>0) echo " <form name=loginform method=post action=/login.php> <input type=hidden name=username value='$ss_name'> <input type=hidden name=password value='$ss_password'> "; ?> <tr> <td width="9"> </td> <td width=111><table border="0" cellspacing="0" cellpadding="0"> <tr> <td width="2"><img src="images/tb_sel_left.jpg" width="2" height="28" /></td> <td width="124" align="center" background="images/tb_sel_bg.jpg" class="selmenu">首页 Home</td> <td width="4"><img src="images/tb_sel_right.jpg" width="4" height="28" /></td> </tr> </table></td> <td align="center"><a href=/search.php class="menu">产品 Products</a></td> <td align="center"><span class="bai">|</span></td> <td align="center"><a href=/newest class="menu">新产品 New Products</a></td> <td align="center"><span class="bai">|</span></td> <?php /* <td align="center"><a href=/cart.php class="menu">Order</a></td> <td align="center"><span class="bai">|</span></td> <td align="center"><a href=/guestbook class="menu">Guestbook</a></td> <td align="center"><span class="bai">|</span></td>*/ ?> <td align="center"><a href=/help/about.php class="menu">联系我们 Contact us</a></td> <td align="center"><span class="bai">|</span></td> <td align="center"><a href=/register class="menu">注册 Register</a></td> <?php if($_SESSION['ss_admin']>0){ ?> <td align="center"><span class="bai">|</span></td> <td align="center"><a href=/admin class="menu" target=_blank>Admin</a> <input type=submit value=ReLogin style=cursor:hand></td> <?php } ?> <?php if($_SESSION['ss_userid']>0){ ?> <td align="center"><span class="bai">|</span></td> <td align="center"><a href=/bill class="menu">Bills</a></td> <td align="center"><span class="bai">|</span></td> <td align="center"><a href=/logout.php class="menu">退出 Logout</a></td> <?php }else{ ?> <td align="center"><span class="bai">|</span></td> <td align="center"><a href=/login.php class="menu">登录 Login</a></td> <?php } ?> </tr> <?php if($_SESSION['ss_admin']>0) echo " </form> "; ?> </table></td> <td width="2"><img src="images/tb_right.jpg" width="2" height="28" /></td> </tr> </table></td> </tr> <tr> <td><table width="100%" border="0" cellspacing="0" cellpadding="0"> <form name=searchform action=search.php method=post> <tr> <td width="6"><img src="images/tb_bt_left.jpg" width="6" height="62" /></td> <td background="images/tb_bt_bg.jpg"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="266" align="center" valign="top" class="vd" style="font-size:11px;color:#333333"></td> <td height="58" align="center"><select name=key> <option value=model_no <? if($key == "model_no") echo "selected"; ?>>型号 Model No.</option> <option value=name <? if($key == "name") echo "selected"; ?>>名称 Name</option> <option value=features <? if($key == "features") echo "selected"; ?>>规格 Features</option> <option value=description <? if($key == "description") echo "selected"; ?>>说明 Descriptions</option> <option value=fob_port <? if($key == "fob_port") echo "selected"; ?>>港口 Fob Port</option> <option value=color <? if($key == "color") echo "selected"; ?>>颜色 Color</option> <option value=matial <? if($key == "matial") echo "selected"; ?>>材料 Matial</option> </select> 关键词 Keyword:<input type=text size=5 name=value value="<?php echo $value?>"> 产品号 ProductID:<input type=text size=5 name=productid value="<?php echo $productid?>"> <input type=hidden name=typeid value="<?php echo $typeid?>"> <input type=submit name=sub6 value="查找 Search"></td> </tr> </table></td> <td width="7"><img src="images/tb_bt_right.jpg" width="7" height="62" /></td> </tr> </form> </table></td> </tr> </table> <table width=95% border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td valign="top" width=350><table width="100%" height="160" border="0" cellpadding="1" cellspacing="1" bgcolor="#F3F1E7"> <tr> <td valign="top" bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="0" cellpadding=5> <tr> <td height="22" align="left" bgcolor="#E7E4D2"></td> </tr> <tr> <td height="350" align="left" class="vd"><FONT style=font-size:14px;color:#000000;line-height:22px><?php include "include/html/notice1.html";?><FONT></td> </tr> <tr> <td height="1" bgcolor="#f5f5f5"></td></tr> <tr> <td height="20" align="right"><a href=/help/about.php class="blue" target=_blank>联系我们 Contact Us</a>   |   <a href=/help/about.php class="blue" target=_blank>更多 More</a>   </td> </tr> </table></td> </tr> </table></td> <td width="5"> </td> <td> <table cellspacing=0 cellpadding=0 align="center" bgcolor=#ffffff> <tr><td align=center> <?php /* <font style=font-size:5px><br></font><table border=0 cellspacing=0 cellpadding=0> <tr> <td align=center width=311><img src=images/100001.jpg class=img1><font style=font-size:5px><br><br></font></td> <td bgcolor=#c1c69d width=1></td> <td align=center width=311><table cellspacing=0 cellpadding=0 align="center"> <tr align=center> <td colspan=2 height=5></td> </tr> <tr align=center> <td><a href=search.php?typeid=1001000><img src=images/200001.jpg alt="Molding Case" class=img1></a></td> <td><a href=search.php?typeid=1002000><img src=images/200002.jpg alt="Assembled Case" class=img1></a></td> </tr> <tr align=center> <td><a href=search.php?typeid=1003000><img src=images/200003.jpg alt="Instrument Box" class=img1></a></td> <td><a href=search.php?typeid=1004000><img src=images/200004.jpg alt="Aluminum Box" class=img1></a></td> </tr> </table><font style=font-size:2px><br><br></font></td> </tr> <tr> <td bgcolor=#c1c69d colspan=3></td> </tr> <tr> <td align=center><font style=font-size:5px><br></font><table cellspacing=0 cellpadding=0 align="center"> <tr align=center> <td><a href=search.php?typeid=2001000><img src=images/300001.jpg alt="Premium Bag" class=img1></a></td> <td><a href=search.php?typeid=2002000><img src=images/300002.jpg alt="Casual Bags" class=img1></a></td> </tr> </table></td> <td bgcolor=#c1c69d width=1></td> <td align=center><font style=font-size:5px><br></font><table cellspacing=0 cellpadding=0 align="center"> <tr align=center> <td><a href=search.php?typeid=3001000><img src=images/400001.jpg alt="Solid Wood Item" class=img1></a></td> <td><a href=search.php?typeid=3002000><img src=images/400002.jpg alt="Gift Item" class=img1></a></td> </tr> </table></td> </tr> </table><font style=font-size:5px><br></font>*/?> <a href=search.php><img src=images/01.jpg alt="Enter Please" class=img1 width=600></a> </td></tr> </table> </td> </tr> </table> <table border=0 cellpadding=0 cellspacing=0><form method=POST action=n2e.php target=frame1> <tr><td valign=middle>数字 Num<input type=text SIZE=16 name=id><INPUT TYPE=submit VALUE="英语 EN" NAME=s></td> <td><IFRAME name=frame1 frameBorder=1 width=780 scrolling=no height=26></IFRAME></td></tr></form> </table> <table border=0 cellpadding=0 cellspacing=0><form method=POST action=n2c.php target=frame2> <tr><td valign=middle>数字 Num<input type=text SIZE=16 name=id><INPUT TYPE=submit VALUE="中文 CN" NAME=s></td> <td><IFRAME name=frame2 frameBorder=1 width=780 scrolling=no height=26></IFRAME></td></tr></form> </table> <?php require_once("include/foot.php"); ?> </center> </body> </html>
06-11
请修改以下代码实现在pyside6环境下,将SQlite3直接呈现在Qtableview,且单元格处于可编辑状态。上下文菜单的功能我还希望保留。from PySide6.QtWidgets import ( QApplication, QMainWindow, QTableView, QMenu, QAbstractItemView, QMessageBox ) from PySide6.QtGui import QStandardItemModel, QStandardItem, QAction from PySide6.QtCore import Qt, QPoint class MainWindow(QMainWindow): def __init__(self): super().__init__() self.setWindowTitle("QTableView右键菜单示例") self.resize(600, 400) # 创建表格视图和数据模型 self.tableView = QTableView(self) self.model = QStandardItemModel(4, 3) # 4行3列 # 设置表头 self.model.setHorizontalHeaderLabels(["姓名", "年龄", "职业"]) # 填充示例数据 data = [ ["张三", "25", "工程师"], ["李四", "30", "设计师"], ["王五", "28", "产品经理"], ["赵六", "35", "总监"] ] for row_idx, row_data in enumerate(data): for col_idx, item_data in enumerate(row_data): item = QStandardItem(item_data) self.model.setItem(row_idx, col_idx, item) # 将模型设置到视图 self.tableView.setModel(self.model) # 设置表格选择行为 self.tableView.setSelectionMode(QAbstractItemView.SingleSelection) self.tableView.setSelectionBehavior(QAbstractItemView.SelectRows) # 启用自定义上下文菜单 self.tableView.setContextMenuPolicy(Qt.CustomContextMenu) self.tableView.customContextMenuRequested.connect(self.show_context_menu) self.setCentralWidget(self.tableView) def show_context_menu(self, pos: QPoint): """显示自定义上下文菜单""" # 获取点击位置的索引 index = self.tableView.indexAt(pos) # 创建菜单 menu = QMenu(self) # 添加菜单项 - 行操作 add_below_action = QAction("在下方插入行", self) add_end_action = QAction("在末尾添加行", self) edit_action = QAction("编辑选中行", self) delete_action = QAction("删除选中行", self) # 添加菜单项 - 单元格操作 copy_action = QAction("复制内容", self) # 根据是否选中行设置菜单项可用状态 is_valid_row = index.isValid() add_below_action.setEnabled(is_valid_row) edit_action.setEnabled(is_valid_row) delete_action.setEnabled(is_valid_row) copy_action.setEnabled(is_valid_row) # 连接菜单项信号 add_below_action.triggered.connect(lambda: self.insert_row_below(index.row())) add_end_action.triggered.connect(self.append_row) edit_action.triggered.connect(lambda: self.edit_row(index.row())) delete_action.triggered.connect(lambda: self.delete_row(index.row())) copy_action.triggered.connect(lambda: self.copy_cell_content(index)) # 将动作添加到菜单 - 分组 menu.addAction(add_below_action) menu.addAction(add_end_action) menu.addSeparator() menu.addAction(edit_action) menu.addAction(delete_action) menu.addSeparator() menu.addAction(copy_action) # 显示菜单 menu.exec(self.tableView.viewport().mapToGlobal(pos)) def insert_row_below(self, row: int): """在选中行下方插入新行""" # 在指定行下方插入新行 self.model.insertRow(row + 1) # 填充默认数据 self.model.setItem(row + 1, 0, QStandardItem("新用户")) self.model.setItem(row + 1, 1, QStandardItem("0")) self.model.setItem(row + 1, 2, QStandardItem("未设置")) # 自动选中新添加的行 self.tableView.selectRow(row + 1) print(f"在行{row + 1}下方插入新行") def append_row(self): """在表格末尾添加新行""" # 获取当前行数 row_count = self.model.rowCount() # 在末尾添加新行 self.model.appendRow([ QStandardItem("新用户"), QStandardItem("0"), QStandardItem("未设置") ]) # 自动滚动到新行并选中 self.tableView.scrollToBottom() self.tableView.selectRow(row_count) print(f"在末尾添加新行,总行数: {row_count + 1}") def edit_row(self, row: int): """编辑行操作""" name = self.model.item(row, 0).text() print(f"编辑操作: 第{row + 1}行 [{name}]") # 这里可以添加实际编辑逻辑 def delete_row(self, row: int): """删除行操作""" name = self.model.item(row, 0).text() # 添加确认对话框 reply = QMessageBox.question( self, "确认删除", f"确定要删除用户 '{name}' 吗?", QMessageBox.Yes | QMessageBox.No ) if reply == QMessageBox.Yes: self.model.removeRow(row) print(f"已删除第{row + 1}行 [{name}]") def copy_cell_content(self, index): """复制单元格内容""" text = index.data() print(f"复制内容: {text}") # 实际应用中可放入剪贴板 # QApplication.clipboard().setText(text) if __name__ == "__main__": app = QApplication([]) window = MainWindow() window.show() app.exec()
07-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值